Skip to content

Commit f1f6f3d

Browse files
authored
test: ensure assertions are reached on more tests
PR-URL: #60641 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 57b4a31 commit f1f6f3d

File tree

78 files changed

+325
-298
lines changed

Some content is hidden

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

78 files changed

+325
-298
lines changed

test/addons/callback-scope/test-async-hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ async_hooks.createHook({
1717
}),
1818
}).enable();
1919

20-
runInCallbackScope({}, 1000, 1000, () => {
20+
runInCallbackScope({}, 1000, 1000, common.mustCallAtLeast(() => {
2121
assert(insideHook);
22-
});
22+
}));

test/addons/callback-scope/test-resolve-async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ const { testResolveAsync } = require(`./build/${common.buildType}/binding`);
99
let called = false;
1010
testResolveAsync().then(() => { called = true; });
1111

12-
process.on('beforeExit', () => { assert(called); });
12+
process.on('beforeExit', common.mustCall(() => { assert(called); }));

test/async-hooks/test-async-local-storage-http.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const server = http.createServer((req, res) => {
99
res.end('ok');
1010
});
1111

12-
server.listen(0, () => {
13-
asyncLocalStorage.run(new Map(), () => {
12+
server.listen(0, mustCall(() => {
13+
asyncLocalStorage.run(new Map(), mustCall(() => {
1414
const store = asyncLocalStorage.getStore();
1515
store.set('hello', 'world');
1616
http.get({ host: 'localhost', port: server.address().port }, mustCall(() => {
1717
assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
1818
server.close();
1919
}));
20-
});
21-
});
20+
}));
21+
}));

test/eslint.config_partial.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export default [
194194
].join(',')}}/**/*.{js,mjs,cjs}`,
195195
`test/parallel/test-{${
196196
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
197-
Array.from({ length: 3 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
197+
Array.from({ length: 4 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
198198
},${
199199
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
200200
Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')

test/module-hooks/test-module-hooks-custom-conditions-cjs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
1515
// allow a CJS to be resolved with that condition.
1616
{
1717
const hooks = registerHooks({
18-
resolve(specifier, context, nextResolve) {
18+
resolve: common.mustCall((specifier, context, nextResolve) => {
1919
assert(Array.isArray(context.conditions));
2020
context.conditions = ['foo', ...context.conditions];
2121
return nextResolve(specifier, context);
22-
},
22+
}, 2),
2323
});
2424
assert.strictEqual(cjs('foo/second').result, 'foo');
2525
assert.strictEqual((await esm('foo/second')).result, 'foo');
@@ -30,11 +30,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
3030
// allow a ESM to be resolved with that condition.
3131
{
3232
const hooks = registerHooks({
33-
resolve(specifier, context, nextResolve) {
33+
resolve: common.mustCall((specifier, context, nextResolve) => {
3434
assert(Array.isArray(context.conditions));
3535
context.conditions = ['foo-esm', ...context.conditions];
3636
return nextResolve(specifier, context);
37-
},
37+
}, 2),
3838
});
3939
assert.strictEqual(cjs('foo/third').result, 'foo-esm');
4040
assert.strictEqual((await esm('foo/third')).result, 'foo-esm');
@@ -44,11 +44,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
4444
// Duplicating the 'foo' condition in the resolve hook should not change the result.
4545
{
4646
const hooks = registerHooks({
47-
resolve(specifier, context, nextResolve) {
47+
resolve: common.mustCall((specifier, context, nextResolve) => {
4848
assert(Array.isArray(context.conditions));
4949
context.conditions = ['foo', ...context.conditions, 'foo'];
5050
return nextResolve(specifier, context);
51-
},
51+
}, 2),
5252
});
5353
assert.strictEqual(cjs('foo/fourth').result, 'foo');
5454
assert.strictEqual((await esm('foo/fourth')).result, 'foo');

test/module-hooks/test-module-hooks-custom-conditions.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This tests that custom conditions can be used in module resolution hooks.
2-
import '../common/index.mjs';
2+
import * as common from '../common/index.mjs';
33
import { registerHooks } from 'node:module';
44
import assert from 'node:assert';
55
import { cjs, esm } from '../fixtures/es-modules/custom-condition/load.cjs';
@@ -12,11 +12,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
1212
// allow a CJS to be resolved with that condition.
1313
{
1414
const hooks = registerHooks({
15-
resolve(specifier, context, nextResolve) {
15+
resolve: common.mustCall((specifier, context, nextResolve) => {
1616
assert(Array.isArray(context.conditions));
1717
context.conditions = ['foo', ...context.conditions];
1818
return nextResolve(specifier, context);
19-
},
19+
}, 2),
2020
});
2121
assert.strictEqual(cjs('foo/second').result, 'foo');
2222
assert.strictEqual((await esm('foo/second')).result, 'foo');
@@ -27,11 +27,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
2727
// allow a ESM to be resolved with that condition.
2828
{
2929
const hooks = registerHooks({
30-
resolve(specifier, context, nextResolve) {
30+
resolve: common.mustCall((specifier, context, nextResolve) => {
3131
assert(Array.isArray(context.conditions));
3232
context.conditions = ['foo-esm', ...context.conditions];
3333
return nextResolve(specifier, context);
34-
},
34+
}, 2),
3535
});
3636
assert.strictEqual(cjs('foo/third').result, 'foo-esm');
3737
assert.strictEqual((await esm('foo/third')).result, 'foo-esm');
@@ -41,11 +41,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
4141
// Duplicating the 'foo' condition in the resolve hook should not change the result.
4242
{
4343
const hooks = registerHooks({
44-
resolve(specifier, context, nextResolve) {
44+
resolve: common.mustCall((specifier, context, nextResolve) => {
4545
assert(Array.isArray(context.conditions));
4646
context.conditions = ['foo', ...context.conditions, 'foo'];
4747
return nextResolve(specifier, context);
48-
},
48+
}, 2),
4949
});
5050
assert.strictEqual(cjs('foo/fourth').result, 'foo');
5151
assert.strictEqual((await esm('foo/fourth')).result, 'foo');

test/node-api/test_callback_scope/test-async-hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ async_hooks.createHook({
3434
}),
3535
}).enable();
3636

37-
runInCallbackScope(expectedResource, expectedResourceType, () => {
37+
runInCallbackScope(expectedResource, expectedResourceType, common.mustCall(() => {
3838
assert(insideHook);
39-
});
39+
}));

test/parallel/test-assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323

24-
const { invalidArgTypeHelper } = require('../common');
24+
const { invalidArgTypeHelper, mustCall } = require('../common');
2525
const assert = require('assert');
2626
const { inspect } = require('util');
2727
const { test } = require('node:test');
@@ -605,7 +605,7 @@ test('Test strict assert', () => {
605605
}
606606
);
607607
strict.throws(
608-
() => assert(),
608+
mustCall(() => assert()),
609609
{
610610
message: 'No value argument passed to `assert.ok()`',
611611
name: 'AssertionError'

test/parallel/test-child-process-fork-net.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ if (process.argv[2] === 'child') {
172172
function closeServer() {
173173
server.close();
174174

175-
setTimeout(() => {
175+
setTimeout(mustCall(() => {
176176
assert(!closeEmitted);
177177
child1.send('close');
178178
child2.send('close');
179179
child3.disconnect();
180-
}, platformTimeout(200));
180+
}), platformTimeout(200));
181181
}
182182

183183
process.on('exit', function() {

test/parallel/test-cluster-basic.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,36 +160,36 @@ if (cluster.isWorker) {
160160
}));
161161

162162
// Check all values
163-
process.once('exit', () => {
163+
process.on('exit', () => {
164164
// Check cluster events
165-
forEach(checks.cluster.events, (check, name) => {
165+
for (const [ name, check ] of Object.entries(checks.cluster.events)) {
166166
assert(check,
167167
`The cluster event "${name}" on the cluster object did not fire`);
168-
});
168+
}
169169

170170
// Check cluster event arguments
171-
forEach(checks.cluster.equal, (check, name) => {
171+
for (const [ name, check ] of Object.entries(checks.cluster.equal)) {
172172
assert(check,
173173
`The cluster event "${name}" did not emit with correct argument`);
174-
});
174+
}
175175

176176
// Check worker states
177-
forEach(checks.worker.states, (check, name) => {
177+
for (const [ name, check ] of Object.entries(checks.worker.states)) {
178178
assert(check,
179179
`The worker state "${name}" was not set to true`);
180-
});
180+
}
181181

182182
// Check worker events
183-
forEach(checks.worker.events, (check, name) => {
183+
for (const [ name, check ] of Object.entries(checks.worker.events)) {
184184
assert(check,
185185
`The worker event "${name}" on the worker object did not fire`);
186-
});
186+
}
187187

188188
// Check worker event arguments
189-
forEach(checks.worker.equal, (check, name) => {
189+
for (const [ name, check ] of Object.entries(checks.worker.equal)) {
190190
assert(check,
191191
`The worker event "${name}" did not emit with correct argument`);
192-
});
192+
}
193193
});
194194

195195
}

0 commit comments

Comments
 (0)