Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 335cb0b

Browse filesBrowse files
committed
test: ensure assertions are reached on all tests
PR-URL: #60845 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 5ee02c7 commit 335cb0b
Copy full SHA for 335cb0b

46 files changed

+469-538Lines changed: 469 additions & 538 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/eslint.config_partial.mjs‎

Copy file name to clipboardExpand all lines: test/eslint.config_partial.mjs
+2-50Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export default [
141141
],
142142
'node-core/require-common-first': 'error',
143143
'node-core/no-duplicate-requires': 'off',
144+
'node-core/must-call-assert': 'error',
144145
},
145146
},
146147
{
@@ -162,56 +163,6 @@ export default [
162163
],
163164
},
164165
},
165-
{
166-
files: [
167-
`test/{${[
168-
'abort',
169-
'addons',
170-
'async-hooks',
171-
'benchmark',
172-
'cctest',
173-
'client-proxy',
174-
'doctool',
175-
'embedding',
176-
'es-module',
177-
'fixtures',
178-
'fuzzers',
179-
'internet',
180-
'js-native-api',
181-
'known_issues',
182-
'message',
183-
'module-hooks',
184-
'node-api',
185-
'nop',
186-
'overlapped-checker',
187-
'pseudo-tty',
188-
'pummel',
189-
'report',
190-
'sea',
191-
'sequential',
192-
'sqlite',
193-
'system-ca',
194-
'test426',
195-
'testpy',
196-
'tick-processor',
197-
'tools',
198-
'v8-updates',
199-
'wasi',
200-
'wasm-allocation',
201-
'wpt',
202-
].join(',')}}/**/*.{js,mjs,cjs}`,
203-
`test/parallel/test-{${
204-
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
205-
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
206-
},n*,r*,${
207-
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
208-
Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
209-
}}.{js,mjs,cjs}`,
210-
],
211-
rules: {
212-
'node-core/must-call-assert': 'error',
213-
},
214-
},
215166
{
216167
files: [
217168
'test/{common,fixtures,wpt}/**/*.{js,mjs,cjs}',
@@ -220,6 +171,7 @@ export default [
220171
rules: {
221172
'node-core/required-modules': 'off',
222173
'node-core/require-common-first': 'off',
174+
'node-core/must-call-assert': 'off',
223175
},
224176
},
225177
{
Collapse file

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

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/hooks-with-no-global-test.js
-1Lines 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',
Collapse file

‎test/parallel/test-os.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-os.js
+13-15Lines 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) {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-perf-hooks-histogram.js
+53-58Lines 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
});
Collapse file

‎test/parallel/test-performance-gc.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-performance-gc.js
+2-2Lines 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
}
Collapse file

‎test/parallel/test-performance-global.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-performance-global.js
+4-6Lines 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;
Collapse file

‎test/parallel/test-performance-measure.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-performance-measure.js
+2-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.