Skip to content

Commit

Permalink
test: use strictEqual in tests (#255)
Browse files Browse the repository at this point in the history
* test: use strictEqual in tests

* run gts fix
  • Loading branch information
JustinBeckwith authored and nolanmar511 committed Jul 30, 2018
1 parent c265a6f commit 901294b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ts/test/test-heap-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('HeapProfiler', () => {
try {
heapProfiler.start(intervalBytes2, stackDepth2);
} catch (e) {
assert.equal(
assert.strictEqual(
e.message,
'Heap profiler is already started with intervalBytes 524288 and' +
' stackDepth 64');
Expand Down
26 changes: 13 additions & 13 deletions ts/test/test-init-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,40 @@ const v8HeapProfiler = require('bindings')('sampling_heap_profiler');

describe('nodeVersionOkay', () => {
it('should accept alpha versions', () => {
assert.equal(true, nodeVersionOkay('v11.0.0-alpha.1'));
assert.strictEqual(true, nodeVersionOkay('v11.0.0-alpha.1'));
});
it('should accept beta versions', () => {
assert.equal(true, nodeVersionOkay('v8.9.10-beta.2'));
assert.strictEqual(true, nodeVersionOkay('v8.9.10-beta.2'));
});
it('should accept nightly versions', () => {
assert.equal(true, nodeVersionOkay('v11.0.0-nightly2018000000'));
assert.strictEqual(true, nodeVersionOkay('v11.0.0-nightly2018000000'));
});
it('should accept pre-release versions', () => {
assert.equal(true, nodeVersionOkay('v11.0.0-pre'));
assert.strictEqual(true, nodeVersionOkay('v11.0.0-pre'));
});
it('should accept v6.12.3', () => {
assert.equal(true, nodeVersionOkay('v6.12.3'));
assert.strictEqual(true, nodeVersionOkay('v6.12.3'));
});
it('should not accept v6.12.2', () => {
assert.equal(false, nodeVersionOkay('v6.12.2'));
assert.strictEqual(false, nodeVersionOkay('v6.12.2'));
});
it('should accept v8.9.4', () => {
assert.equal(true, nodeVersionOkay('v8.9.4'));
assert.strictEqual(true, nodeVersionOkay('v8.9.4'));
});
it('should not accept v8.9.3', () => {
assert.equal(false, nodeVersionOkay('v8.9.3'));
assert.strictEqual(false, nodeVersionOkay('v8.9.3'));
});
it('should accept v10.4.1', () => {
assert.equal(true, nodeVersionOkay('v10.4.1'));
assert.strictEqual(true, nodeVersionOkay('v10.4.1'));
});
it('should not accept v10.4.0', () => {
assert.equal(false, nodeVersionOkay('v10.4.0'));
assert.strictEqual(false, nodeVersionOkay('v10.4.0'));
});
it('should accept node 7', () => {
assert.equal(true, nodeVersionOkay('v7.7.7'));
assert.strictEqual(true, nodeVersionOkay('v7.7.7'));
});
it('should accept node 9', () => {
assert.equal(true, nodeVersionOkay('v9.9.9'));
assert.strictEqual(true, nodeVersionOkay('v9.9.9'));
});
});

Expand Down Expand Up @@ -211,7 +211,7 @@ describe('createProfiler', () => {
assert.fail('expected error because no service in config');
})
.catch((e: Error) => {
assert.equal(
assert.strictEqual(
e.message,
'Could not start profiler: Error: Service must be specified in the configuration');
});
Expand Down
70 changes: 36 additions & 34 deletions ts/test/test-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ function nockOauth2(): nock.Scope {
describe('Retryer', () => {
it('should backoff until max-backoff reached', () => {
const retryer = new Retryer(1000, 1000000, 5, () => 0.5);
assert.equal(retryer.getBackoff(), 0.5 * 1000);
assert.equal(retryer.getBackoff(), 0.5 * 5000);
assert.equal(retryer.getBackoff(), 0.5 * 25000);
assert.equal(retryer.getBackoff(), 0.5 * 125000);
assert.equal(retryer.getBackoff(), 0.5 * 625000);
assert.equal(retryer.getBackoff(), 0.5 * 1000000);
assert.equal(retryer.getBackoff(), 0.5 * 1000000);
assert.equal(retryer.getBackoff(), 0.5 * 1000000);
assert.equal(retryer.getBackoff(), 0.5 * 1000000);
assert.equal(retryer.getBackoff(), 0.5 * 1000000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 1000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 5000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 25000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 125000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 625000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 1000000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 1000000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 1000000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 1000000);
assert.strictEqual(retryer.getBackoff(), 0.5 * 1000000);
});
});

Expand Down Expand Up @@ -159,7 +159,7 @@ describe('Profiler', () => {
await profiler.profile(requestProf);
assert.fail('Expected an error to be thrown,');
} catch (err) {
assert.equal(err.message, 'Unexpected profile type UNKNOWN.');
assert.strictEqual(err.message, 'Unexpected profile type UNKNOWN.');
}
});
});
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('Profiler', () => {
await profiler.writeTimeProfile(requestProf);
assert.fail('expected error, no error thrown');
} catch (err) {
assert.equal(
assert.strictEqual(
err.message,
'Cannot collect time profile, time profiler not enabled.');
}
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('Profiler', () => {
await profiler.writeHeapProfile(requestProf);
assert.fail('expected error, no error thrown');
} catch (err) {
assert.equal(
assert.strictEqual(
err.message,
'Cannot collect heap profile, heap profiler not enabled.');
}
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('Profiler', () => {
}));
const profiler = new Profiler(testConfig);
await profiler.profileAndUpload(requestProf);
assert.equal(0, requestStub.callCount);
assert.strictEqual(0, requestStub.callCount);
});
it('should ignore error thrown by http request.', async () => {
const requestProf = {
Expand Down Expand Up @@ -378,7 +378,8 @@ describe('Profiler', () => {
nock(API).patch('/' + requestProf.name).once().reply(200);
const profiler = new Profiler(testConfig);
await profiler.profileAndUpload(requestProf);
assert.equal(apiMock.isDone(), true, 'completed call to real API');
assert.strictEqual(
apiMock.isDone(), true, 'completed call to real API');
});
it('should send request to upload profile to non-default API without error.',
async () => {
Expand All @@ -395,7 +396,8 @@ describe('Profiler', () => {
config.baseApiUrl = TEST_API;
const profiler = new Profiler(config);
await profiler.profileAndUpload(requestProf);
assert.equal(apiMock.isDone(), true, 'completed call to test API');
assert.strictEqual(
apiMock.isDone(), true, 'completed call to test API');
});
});
describe('createProfile', () => {
Expand Down Expand Up @@ -495,7 +497,7 @@ describe('Profiler', () => {
await profiler.createProfile();
assert.fail('expected error, no error thrown');
} catch (err) {
assert.equal(
assert.strictEqual(
err.message,
'Profile not valid: ' +
'{"name":"projects/12345678901/test-projectId"}.');
Expand Down Expand Up @@ -596,7 +598,7 @@ describe('Profiler', () => {
await profiler.createProfile();
assert.fail('expected error, no error thrown');
} catch (err) {
assert.equal(err.message, 'Network error');
assert.strictEqual(err.message, 'Network error');
}
});
it('should throw status message when response has non-200 status.',
Expand All @@ -620,7 +622,7 @@ describe('Profiler', () => {
await profiler.createProfile();
assert.fail('expected error, no error thrown');
} catch (err) {
assert.equal(err.message, '500 status code');
assert.strictEqual(err.message, '500 status code');
}
});
it('should throw error with server-specified backoff when non-200 error' +
Expand All @@ -647,7 +649,7 @@ describe('Profiler', () => {
await profiler.createProfile();
assert.fail('expected error, no error thrown');
} catch (err) {
assert.equal(err.backoffMillis, 50000);
assert.strictEqual(err.backoffMillis, 50000);
}
});
it('should throw error when response undefined', async () => {
Expand All @@ -667,7 +669,7 @@ describe('Profiler', () => {
await profiler.createProfile();
assert.fail('expected error, no error thrown');
} catch (err) {
assert.equal(err.message, 'Profile not valid: undefined.');
assert.strictEqual(err.message, 'Profile not valid: undefined.');
}
});
});
Expand Down Expand Up @@ -709,7 +711,7 @@ describe('Profiler', () => {
const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
const delayMillis = await profiler.collectProfile();
assert.equal(
assert.strictEqual(
0, delayMillis, 'No delay before asking to collect next profile');
});
it('should return expect backoff when non-200 response and no backoff' +
Expand Down Expand Up @@ -804,7 +806,7 @@ describe('Profiler', () => {
const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
const delayMillis = await profiler.collectProfile();
assert.equal(50000, delayMillis);
assert.strictEqual(50000, delayMillis);
});
it('should return expected backoff when non-200 error and invalid server backoff' +
' specified',
Expand All @@ -825,7 +827,7 @@ describe('Profiler', () => {
const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
const delayMillis = await profiler.collectProfile();
assert.equal(500, delayMillis);
assert.strictEqual(500, delayMillis);
});
it('should return backoff limit, when server specified backoff is greater' +
' then backoff limit',
Expand All @@ -847,7 +849,7 @@ describe('Profiler', () => {
const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
const delayMillis = await profiler.collectProfile();
assert.equal(parseDuration('7d'), delayMillis);
assert.strictEqual(parseDuration('7d'), delayMillis);
});
it('should indicate collectProfile should be called immediately if there' +
' is an error when collecting and uploading profile.',
Expand All @@ -871,45 +873,45 @@ describe('Profiler', () => {
const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
const delayMillis = await profiler.collectProfile();
assert.equal(0, delayMillis);
assert.strictEqual(0, delayMillis);
});
});
describe('parseBackoffDuration', () => {
it('should return undefined when no duration specified', () => {
assert.equal(undefined, parseBackoffDuration(''));
assert.strictEqual(undefined, parseBackoffDuration(''));
});
it('should parse backoff with minutes and seconds specified', () => {
assert.equal(
assert.strictEqual(
62000, parseBackoffDuration('action throttled, backoff for 1m2s'));
});
it('should parse backoff with fraction of second', () => {
assert.equal(
assert.strictEqual(
2500, parseBackoffDuration('action throttled, backoff for 2.5s'));
});
it('should parse backoff with minutes and seconds, including fraction of second',
() => {
assert.equal(
assert.strictEqual(
62500,
parseBackoffDuration('action throttled, backoff for 1m2.5s'));
});
it('should parse backoff with hours and seconds', () => {
assert.equal(
assert.strictEqual(
3602500,
parseBackoffDuration('action throttled, backoff for 1h2.5s'));
});
it('should parse backoff with hours, minutes, and seconds', () => {
assert.equal(
assert.strictEqual(
3662500,
parseBackoffDuration('action throttled, backoff for 1h1m2.5s'));
});
it('should parse return undefined for unexpected backoff time string format',
() => {
assert.equal(
assert.strictEqual(
undefined,
parseBackoffDuration('action throttled, backoff for 1m2+s'));
});
it('should parse return undefined for unexpected string format', () => {
assert.equal(undefined, parseBackoffDuration('time 1m2s'));
assert.strictEqual(undefined, parseBackoffDuration('time 1m2s'));
});
});
});
2 changes: 1 addition & 1 deletion ts/test/test-time-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('TimeProfiler', () => {
isProfiling = false;
});
await delay(2 * durationMillis);
assert.equal(false, isProfiling, 'profiler is still running');
assert.strictEqual(false, isProfiling, 'profiler is still running');
});

it('should return a profile equal to the expected profile', async () => {
Expand Down

0 comments on commit 901294b

Please sign in to comment.