Skip to content

Commit 1e3e91f

Browse files
committed
test: ensure assertions are reached on all tests
1 parent fc203b3 commit 1e3e91f

File tree

46 files changed

+469
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+469
-538
lines changed

test/eslint.config_partial.mjs

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export default [
133133
],
134134
'node-core/require-common-first': 'error',
135135
'node-core/no-duplicate-requires': 'off',
136+
'node-core/must-call-assert': 'error',
136137
},
137138
},
138139
{
@@ -154,56 +155,6 @@ export default [
154155
],
155156
},
156157
},
157-
{
158-
files: [
159-
`test/{${[
160-
'abort',
161-
'addons',
162-
'async-hooks',
163-
'benchmark',
164-
'cctest',
165-
'client-proxy',
166-
'doctool',
167-
'embedding',
168-
'es-module',
169-
'fixtures',
170-
'fuzzers',
171-
'internet',
172-
'js-native-api',
173-
'known_issues',
174-
'message',
175-
'module-hooks',
176-
'node-api',
177-
'nop',
178-
'overlapped-checker',
179-
'pseudo-tty',
180-
'pummel',
181-
'report',
182-
'sea',
183-
'sequential',
184-
'sqlite',
185-
'system-ca',
186-
'test426',
187-
'testpy',
188-
'tick-processor',
189-
'tools',
190-
'v8-updates',
191-
'wasi',
192-
'wasm-allocation',
193-
'wpt',
194-
].join(',')}}/**/*.{js,mjs,cjs}`,
195-
`test/parallel/test-{${
196-
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
197-
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
198-
},n*,r*,${
199-
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
200-
Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
201-
}}.{js,mjs,cjs}`,
202-
],
203-
rules: {
204-
'node-core/must-call-assert': 'error',
205-
},
206-
},
207158
{
208159
files: [
209160
'test/{common,fixtures,wpt}/**/*.{js,mjs,cjs}',
@@ -212,6 +163,7 @@ export default [
212163
rules: {
213164
'node-core/required-modules': 'off',
214165
'node-core/require-common-first': 'off',
166+
'node-core/must-call-assert': 'off',
215167
},
216168
},
217169
{

test/fixtures/test-runner/output/hooks-with-no-global-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ before(() => testArr.push('global before'));
99
after(() => {
1010
testArr.push('global after');
1111

12-
// eslint-disable-next-line node-core/must-call-assert
1312
assert.deepStrictEqual(testArr, [
1413
'global before',
1514
'describe before',

test/parallel/test-os.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ const path = require('path');
2727
const { inspect } = require('util');
2828

2929
const is = {
30-
number: (value, key) => {
30+
number: common.mustCallAtLeast((value, key) => {
3131
assert(!Number.isNaN(value), `${key} should not be NaN`);
3232
assert.strictEqual(typeof value, 'number');
33-
},
34-
string: (value) => { assert.strictEqual(typeof value, 'string'); },
35-
array: (value) => { assert.ok(Array.isArray(value)); },
36-
object: (value) => {
33+
}),
34+
string: common.mustCallAtLeast((value) => { assert.strictEqual(typeof value, 'string'); }),
35+
array: common.mustCallAtLeast((value) => { assert.ok(Array.isArray(value)); }),
36+
object: common.mustCallAtLeast((value) => {
3737
assert.strictEqual(typeof value, 'object');
3838
assert.notStrictEqual(value, null);
39-
}
39+
}),
4040
};
4141

4242
process.env.TMPDIR = '/tmpdir';
@@ -181,15 +181,13 @@ const netmaskToCIDRSuffixMap = new Map(Object.entries({
181181
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff': 128
182182
}));
183183

184-
Object.values(interfaces)
185-
.flat(Infinity)
186-
.map((v) => ({ v, mask: netmaskToCIDRSuffixMap.get(v.netmask) }))
187-
.forEach(({ v, mask }) => {
188-
assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`);
189-
if (mask) {
190-
assert.strictEqual(v.cidr, `${v.address}/${mask}`);
191-
}
192-
});
184+
for (const v of Object.values(interfaces).flat(Infinity)) {
185+
assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`);
186+
const mask = netmaskToCIDRSuffixMap.get(v.netmask);
187+
if (mask) {
188+
assert.strictEqual(v.cidr, `${v.address}/${mask}`);
189+
}
190+
}
193191

194192
const EOL = os.EOL;
195193
if (common.isWindows) {

test/parallel/test-perf-hooks-histogram.js

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
const common = require('../common');
44

5-
const {
6-
deepStrictEqual,
7-
ok,
8-
strictEqual,
9-
throws,
10-
} = require('assert');
5+
const assert = require('assert');
116

127
const {
138
createHistogram,
@@ -19,64 +14,64 @@ const { inspect } = require('util');
1914
{
2015
const h = createHistogram();
2116

22-
strictEqual(h.min, 9223372036854776000);
23-
strictEqual(h.minBigInt, 9223372036854775807n);
24-
strictEqual(h.max, 0);
25-
strictEqual(h.maxBigInt, 0n);
26-
strictEqual(h.exceeds, 0);
27-
strictEqual(h.exceedsBigInt, 0n);
28-
ok(Number.isNaN(h.mean));
29-
ok(Number.isNaN(h.stddev));
17+
assert.strictEqual(h.min, 9223372036854776000);
18+
assert.strictEqual(h.minBigInt, 9223372036854775807n);
19+
assert.strictEqual(h.max, 0);
20+
assert.strictEqual(h.maxBigInt, 0n);
21+
assert.strictEqual(h.exceeds, 0);
22+
assert.strictEqual(h.exceedsBigInt, 0n);
23+
assert.ok(Number.isNaN(h.mean));
24+
assert.ok(Number.isNaN(h.stddev));
3025

31-
strictEqual(h.count, 0);
32-
strictEqual(h.countBigInt, 0n);
26+
assert.strictEqual(h.count, 0);
27+
assert.strictEqual(h.countBigInt, 0n);
3328

3429
h.record(1);
3530

36-
strictEqual(h.count, 1);
37-
strictEqual(h.countBigInt, 1n);
31+
assert.strictEqual(h.count, 1);
32+
assert.strictEqual(h.countBigInt, 1n);
3833

3934
[false, '', {}, undefined, null].forEach((i) => {
40-
throws(() => h.record(i), {
35+
assert.throws(() => h.record(i), {
4136
code: 'ERR_INVALID_ARG_TYPE'
4237
});
4338
});
4439
[0, Number.MAX_SAFE_INTEGER + 1].forEach((i) => {
45-
throws(() => h.record(i), {
40+
assert.throws(() => h.record(i), {
4641
code: 'ERR_OUT_OF_RANGE'
4742
});
4843
});
4944

50-
strictEqual(h.min, 1);
51-
strictEqual(h.minBigInt, 1n);
52-
strictEqual(h.max, 1);
53-
strictEqual(h.maxBigInt, 1n);
54-
strictEqual(h.exceeds, 0);
55-
strictEqual(h.mean, 1);
56-
strictEqual(h.stddev, 0);
45+
assert.strictEqual(h.min, 1);
46+
assert.strictEqual(h.minBigInt, 1n);
47+
assert.strictEqual(h.max, 1);
48+
assert.strictEqual(h.maxBigInt, 1n);
49+
assert.strictEqual(h.exceeds, 0);
50+
assert.strictEqual(h.mean, 1);
51+
assert.strictEqual(h.stddev, 0);
5752

58-
strictEqual(h.percentile(1), 1);
59-
strictEqual(h.percentile(100), 1);
53+
assert.strictEqual(h.percentile(1), 1);
54+
assert.strictEqual(h.percentile(100), 1);
6055

61-
strictEqual(h.percentileBigInt(1), 1n);
62-
strictEqual(h.percentileBigInt(100), 1n);
56+
assert.strictEqual(h.percentileBigInt(1), 1n);
57+
assert.strictEqual(h.percentileBigInt(100), 1n);
6358

64-
deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]]));
59+
assert.deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]]));
6560

66-
deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]]));
61+
assert.deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]]));
6762

6863
const mc = new MessageChannel();
6964
mc.port1.onmessage = common.mustCall(({ data }) => {
70-
strictEqual(h.min, 1);
71-
strictEqual(h.max, 1);
72-
strictEqual(h.exceeds, 0);
73-
strictEqual(h.mean, 1);
74-
strictEqual(h.stddev, 0);
65+
assert.strictEqual(h.min, 1);
66+
assert.strictEqual(h.max, 1);
67+
assert.strictEqual(h.exceeds, 0);
68+
assert.strictEqual(h.mean, 1);
69+
assert.strictEqual(h.stddev, 0);
7570

7671
data.record(2n);
7772
data.recordDelta();
7873

79-
strictEqual(h.max, 2);
74+
assert.strictEqual(h.max, 2);
8075

8176
mc.port1.close();
8277
});
@@ -85,15 +80,15 @@ const { inspect } = require('util');
8580

8681
{
8782
const e = monitorEventLoopDelay();
88-
strictEqual(e.count, 0);
83+
assert.strictEqual(e.count, 0);
8984
e.enable();
9085
const mc = new MessageChannel();
9186
mc.port1.onmessage = common.mustCall(({ data }) => {
92-
strictEqual(typeof data.min, 'number');
93-
ok(data.min > 0);
94-
ok(data.count > 0);
95-
strictEqual(data.disable, undefined);
96-
strictEqual(data.enable, undefined);
87+
assert.strictEqual(typeof data.min, 'number');
88+
assert.ok(data.min > 0);
89+
assert.ok(data.count > 0);
90+
assert.strictEqual(data.disable, undefined);
91+
assert.strictEqual(data.enable, undefined);
9792
mc.port1.close();
9893
});
9994
const interval = setInterval(() => {
@@ -112,19 +107,19 @@ const { inspect } = require('util');
112107
histogram = hi;
113108
}
114109
// The histogram should already be disabled.
115-
strictEqual(histogram.disable(), false);
110+
assert.strictEqual(histogram.disable(), false);
116111
}
117112

118113
{
119114
const h = createHistogram();
120-
ok(inspect(h, { depth: null }).startsWith('Histogram'));
121-
strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]');
115+
assert.ok(inspect(h, { depth: null }).startsWith('Histogram'));
116+
assert.strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]');
122117
}
123118

124119
{
125120
// Tests that RecordableHistogram is impossible to construct manually
126121
const h = createHistogram();
127-
throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
122+
assert.throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
128123
}
129124

130125
{
@@ -133,7 +128,7 @@ const { inspect } = require('util');
133128
1,
134129
null,
135130
].forEach((i) => {
136-
throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' });
131+
assert.throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' });
137132
});
138133

139134
[
@@ -142,20 +137,20 @@ const { inspect } = require('util');
142137
null,
143138
{},
144139
].forEach((i) => {
145-
throws(() => createHistogram({ lowest: i }), {
140+
assert.throws(() => createHistogram({ lowest: i }), {
146141
code: 'ERR_INVALID_ARG_TYPE',
147142
});
148-
throws(() => createHistogram({ highest: i }), {
143+
assert.throws(() => createHistogram({ highest: i }), {
149144
code: 'ERR_INVALID_ARG_TYPE',
150145
});
151-
throws(() => createHistogram({ figures: i }), {
146+
assert.throws(() => createHistogram({ figures: i }), {
152147
code: 'ERR_INVALID_ARG_TYPE',
153148
});
154149
});
155150

156151
// Number greater than 5 is not allowed
157152
for (const i of [6, 10]) {
158-
throws(() => createHistogram({ figures: i }), {
153+
assert.throws(() => createHistogram({ figures: i }), {
159154
code: 'ERR_OUT_OF_RANGE',
160155
});
161156
}
@@ -169,20 +164,20 @@ const { inspect } = require('util');
169164

170165
h1.record(1);
171166

172-
strictEqual(h2.count, 0);
173-
strictEqual(h1.count, 1);
167+
assert.strictEqual(h2.count, 0);
168+
assert.strictEqual(h1.count, 1);
174169

175170
h2.add(h1);
176171

177-
strictEqual(h2.count, 1);
172+
assert.strictEqual(h2.count, 1);
178173

179174
[
180175
'hello',
181176
1,
182177
false,
183178
{},
184179
].forEach((i) => {
185-
throws(() => h1.add(i), {
180+
assert.throws(() => h1.add(i), {
186181
code: 'ERR_INVALID_ARG_TYPE',
187182
});
188183
});

test/parallel/test-performance-gc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ const kinds = [
4646
// GC should not keep the event loop alive
4747
{
4848
let didCall = false;
49-
process.on('beforeExit', () => {
49+
process.on('beforeExit', common.mustCall(() => {
5050
assert(!didCall);
5151
didCall = true;
5252
globalThis.gc();
53-
});
53+
}));
5454
}

test/parallel/test-performance-global.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
require('../common');
55

66
const perf_hooks = require('perf_hooks');
7-
const {
8-
strictEqual
9-
} = require('assert');
7+
const assert = require('assert');
108

119
const perf = performance;
12-
strictEqual(globalThis.performance, perf_hooks.performance);
10+
assert.strictEqual(globalThis.performance, perf_hooks.performance);
1311
performance = undefined;
14-
strictEqual(globalThis.performance, undefined);
15-
strictEqual(typeof perf_hooks.performance.now, 'function');
12+
assert.strictEqual(globalThis.performance, undefined);
13+
assert.strictEqual(typeof perf_hooks.performance.now, 'function');
1614

1715
// Restore the value of performance for the known globals check
1816
performance = perf;

test/parallel/test-performance-measure.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const ALLOWED_MARGIN = 10;
99

1010
const expected = ['Start to Now', 'A to Now', 'A to B'];
1111
const obs = new PerformanceObserver(common.mustCall((items) => {
12-
items.getEntries().forEach(({ name, duration }) => {
12+
for (const { name, duration } of items.getEntries()) {
1313
assert.ok(duration > (DELAY - ALLOWED_MARGIN));
1414
assert.strictEqual(expected.shift(), name);
15-
});
15+
}
1616
}));
1717
obs.observe({ entryTypes: ['measure'] });
1818

0 commit comments

Comments
 (0)