From 4bad62eda27c8ef9dbb0c9b12c756025dbdc2dd1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 30 Oct 2025 13:07:21 +0100 Subject: [PATCH 1/3] test: ensure assertions are reached on more tests --- test/eslint.config_partial.mjs | 6 +- .../test-child-process-fork-abort-signal.js | 40 +-- ...-child-process-fork-timeout-kill-signal.js | 14 +- ...test-child-process-prototype-tampering.mjs | 36 +-- .../test-child-process-reject-null-bytes.js | 104 +++---- ...child-process-spawn-timeout-kill-signal.js | 14 +- test/parallel/test-cli-options-as-flags.js | 42 +-- test/parallel/test-cluster-worker-events.js | 10 +- test/parallel/test-cluster-worker-isdead.js | 6 +- test/parallel/test-common-must-not-call.js | 4 +- test/parallel/test-config-file.js | 254 +++++++++--------- .../test-console-diagnostics-channels.js | 10 +- .../test-console-tty-colors-per-stream.js | 2 +- test/parallel/test-constants.js | 8 +- test/parallel/test-crypto-dh-generate-keys.js | 4 +- test/parallel/test-crypto-domain.js | 6 +- test/parallel/test-crypto-key-objects.js | 4 +- .../test-crypto-op-during-process-exit.js | 5 +- .../test-crypto-randomfillsync-regression.js | 4 +- .../test-crypto-subtle-zero-length.js | 4 +- 20 files changed, 286 insertions(+), 291 deletions(-) diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index c53c0d4d24405e..5c91f4319b200f 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -192,11 +192,11 @@ export default [ 'wpt', ].join(',')}}/**/*.{js,mjs,cjs}`, `test/parallel/test-{${ + // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' + Array.from({ length: 3 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') + },${ // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…' Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') - },${ - // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' - Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') }}.{js,mjs,cjs}`, ], rules: { diff --git a/test/parallel/test-child-process-fork-abort-signal.js b/test/parallel/test-child-process-fork-abort-signal.js index b963306fb1bed3..1d170134f715dd 100644 --- a/test/parallel/test-child-process-fork-abort-signal.js +++ b/test/parallel/test-child-process-fork-abort-signal.js @@ -1,7 +1,7 @@ 'use strict'; const { mustCall, mustNotCall } = require('../common'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const fixtures = require('../common/fixtures'); const { fork } = require('child_process'); @@ -13,11 +13,11 @@ const { fork } = require('child_process'); signal }); cp.on('exit', mustCall((code, killSignal) => { - strictEqual(code, null); - strictEqual(killSignal, 'SIGTERM'); + assert.strictEqual(code, null); + assert.strictEqual(killSignal, 'SIGTERM'); })); cp.on('error', mustCall((err) => { - strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.name, 'AbortError'); })); process.nextTick(() => ac.abort()); } @@ -30,13 +30,13 @@ const { fork } = require('child_process'); signal }); cp.on('exit', mustCall((code, killSignal) => { - strictEqual(code, null); - strictEqual(killSignal, 'SIGTERM'); + assert.strictEqual(code, null); + assert.strictEqual(killSignal, 'SIGTERM'); })); cp.on('error', mustCall((err) => { - strictEqual(err.name, 'AbortError'); - strictEqual(err.cause.name, 'Error'); - strictEqual(err.cause.message, 'boom'); + assert.strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.cause.name, 'Error'); + assert.strictEqual(err.cause.message, 'boom'); })); process.nextTick(() => ac.abort(new Error('boom'))); } @@ -48,11 +48,11 @@ const { fork } = require('child_process'); signal }); cp.on('exit', mustCall((code, killSignal) => { - strictEqual(code, null); - strictEqual(killSignal, 'SIGTERM'); + assert.strictEqual(code, null); + assert.strictEqual(killSignal, 'SIGTERM'); })); cp.on('error', mustCall((err) => { - strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.name, 'AbortError'); })); } @@ -63,13 +63,13 @@ const { fork } = require('child_process'); signal }); cp.on('exit', mustCall((code, killSignal) => { - strictEqual(code, null); - strictEqual(killSignal, 'SIGTERM'); + assert.strictEqual(code, null); + assert.strictEqual(killSignal, 'SIGTERM'); })); cp.on('error', mustCall((err) => { - strictEqual(err.name, 'AbortError'); - strictEqual(err.cause.name, 'Error'); - strictEqual(err.cause.message, 'boom'); + assert.strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.cause.name, 'Error'); + assert.strictEqual(err.cause.message, 'boom'); })); } @@ -81,11 +81,11 @@ const { fork } = require('child_process'); killSignal: 'SIGKILL', }); cp.on('exit', mustCall((code, killSignal) => { - strictEqual(code, null); - strictEqual(killSignal, 'SIGKILL'); + assert.strictEqual(code, null); + assert.strictEqual(killSignal, 'SIGKILL'); })); cp.on('error', mustCall((err) => { - strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.name, 'AbortError'); })); } diff --git a/test/parallel/test-child-process-fork-timeout-kill-signal.js b/test/parallel/test-child-process-fork-timeout-kill-signal.js index f3f605d7f5e24b..3d9dada1415d5e 100644 --- a/test/parallel/test-child-process-fork-timeout-kill-signal.js +++ b/test/parallel/test-child-process-fork-timeout-kill-signal.js @@ -1,7 +1,7 @@ 'use strict'; const { mustCall } = require('../common'); -const { strictEqual, throws } = require('assert'); +const assert = require('assert'); const fixtures = require('../common/fixtures'); const { fork } = require('child_process'); const { getEventListeners } = require('events'); @@ -11,7 +11,7 @@ const { getEventListeners } = require('events'); const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { timeout: 5, }); - cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM'))); + cp.on('exit', mustCall((code, ks) => assert.strictEqual(ks, 'SIGTERM'))); } { @@ -20,16 +20,16 @@ const { getEventListeners } = require('events'); timeout: 5, killSignal: 'SIGKILL', }); - cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL'))); + cp.on('exit', mustCall((code, ks) => assert.strictEqual(ks, 'SIGKILL'))); } { // Verify timeout verification - throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), { + assert.throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), { timeout: 'badValue', }), /ERR_INVALID_ARG_TYPE/); - throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), { + assert.throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), { timeout: {}, }), /ERR_INVALID_ARG_TYPE/); } @@ -43,8 +43,8 @@ const { getEventListeners } = require('events'); timeout: 6, signal, }); - strictEqual(getEventListeners(signal, 'abort').length, 1); + assert.strictEqual(getEventListeners(signal, 'abort').length, 1); cp.on('exit', mustCall(() => { - strictEqual(getEventListeners(signal, 'abort').length, 0); + assert.strictEqual(getEventListeners(signal, 'abort').length, 0); })); } diff --git a/test/parallel/test-child-process-prototype-tampering.mjs b/test/parallel/test-child-process-prototype-tampering.mjs index d94c4bdbc61621..cc30c1b6c89d6e 100644 --- a/test/parallel/test-child-process-prototype-tampering.mjs +++ b/test/parallel/test-child-process-prototype-tampering.mjs @@ -1,7 +1,7 @@ import * as common from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import { EOL } from 'node:os'; -import { strictEqual, notStrictEqual, throws } from 'node:assert'; +import assert from 'node:assert'; import cp from 'node:child_process'; // TODO(LiviaMedeiros): test on different platforms @@ -15,17 +15,17 @@ for (const tamperedCwd of ['', '/tmp', '/not/existing/malicious/path', 42n]) { Object.prototype.cwd = tamperedCwd; cp.exec('pwd', common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedCWD}${EOL}`); + assert.strictEqual(`${out}`, `${expectedCWD}${EOL}`); })); - strictEqual(`${cp.execSync('pwd')}`, `${expectedCWD}${EOL}`); + assert.strictEqual(`${cp.execSync('pwd')}`, `${expectedCWD}${EOL}`); cp.execFile('pwd', common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedCWD}${EOL}`); + assert.strictEqual(`${out}`, `${expectedCWD}${EOL}`); })); - strictEqual(`${cp.execFileSync('pwd')}`, `${expectedCWD}${EOL}`); + assert.strictEqual(`${cp.execFileSync('pwd')}`, `${expectedCWD}${EOL}`); cp.spawn('pwd').stdout.on('data', common.mustCall((out) => { - strictEqual(`${out}`, `${expectedCWD}${EOL}`); + assert.strictEqual(`${out}`, `${expectedCWD}${EOL}`); })); - strictEqual(`${cp.spawnSync('pwd').stdout}`, `${expectedCWD}${EOL}`); + assert.strictEqual(`${cp.spawnSync('pwd').stdout}`, `${expectedCWD}${EOL}`); delete Object.prototype.cwd; } @@ -34,17 +34,17 @@ for (const tamperedUID of [0, 1, 999, 1000, 0n, 'gwak']) { Object.prototype.uid = tamperedUID; cp.exec('id -u', common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedUID}${EOL}`); + assert.strictEqual(`${out}`, `${expectedUID}${EOL}`); })); - strictEqual(`${cp.execSync('id -u')}`, `${expectedUID}${EOL}`); + assert.strictEqual(`${cp.execSync('id -u')}`, `${expectedUID}${EOL}`); cp.execFile('id', ['-u'], common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedUID}${EOL}`); + assert.strictEqual(`${out}`, `${expectedUID}${EOL}`); })); - strictEqual(`${cp.execFileSync('id', ['-u'])}`, `${expectedUID}${EOL}`); + assert.strictEqual(`${cp.execFileSync('id', ['-u'])}`, `${expectedUID}${EOL}`); cp.spawn('id', ['-u']).stdout.on('data', common.mustCall((out) => { - strictEqual(`${out}`, `${expectedUID}${EOL}`); + assert.strictEqual(`${out}`, `${expectedUID}${EOL}`); })); - strictEqual(`${cp.spawnSync('id', ['-u']).stdout}`, `${expectedUID}${EOL}`); + assert.strictEqual(`${cp.spawnSync('id', ['-u']).stdout}`, `${expectedUID}${EOL}`); delete Object.prototype.uid; } @@ -68,24 +68,24 @@ for (const shellCommandArgument of ['-L && echo "tampered"']) { program.stdout.on('data', common.mustNotCall()); program.on('exit', common.mustCall((code) => { - notStrictEqual(code, 0); + assert.notStrictEqual(code, 0); })); cp.execFile(cmd, [shellCommandArgument], { cwd: expectedCWD }, common.mustCall((err) => { - notStrictEqual(err.code, 0); + assert.notStrictEqual(err.code, 0); }) ); - throws(() => { + assert.throws(() => { cp.execFileSync(cmd, [shellCommandArgument], { cwd: expectedCWD }); }, (e) => { - notStrictEqual(e.status, 0); + assert.notStrictEqual(e.status, 0); return true; }); cmdExitCode = cp.spawnSync(cmd, [shellCommandArgument], { cwd: expectedCWD }).status; - notStrictEqual(cmdExitCode, 0); + assert.notStrictEqual(cmdExitCode, 0); delete Object.prototype.shell; } diff --git a/test/parallel/test-child-process-reject-null-bytes.js b/test/parallel/test-child-process-reject-null-bytes.js index b5239cdddcdd07..3b3a25d961a95f 100644 --- a/test/parallel/test-child-process-reject-null-bytes.js +++ b/test/parallel/test-child-process-reject-null-bytes.js @@ -3,7 +3,7 @@ const { mustNotCall } = require('../common'); // Regression test for https://github.com/nodejs/node/issues/44768 -const { throws } = require('assert'); +const assert = require('assert'); const { exec, execFile, @@ -16,56 +16,56 @@ const { // Tests for the 'command' argument -throws(() => exec(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`, mustNotCall()), { +assert.throws(() => exec(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => exec('BBB\0XXX AAA CCC', mustNotCall()), { +assert.throws(() => exec('BBB\0XXX AAA CCC', mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execSync(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`), { +assert.throws(() => execSync(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execSync('BBB\0XXX AAA CCC'), { +assert.throws(() => execSync('BBB\0XXX AAA CCC'), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'file' argument -throws(() => spawn('BBB\0XXX'), { +assert.throws(() => spawn('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFile('BBB\0XXX', mustNotCall()), { +assert.throws(() => execFile('BBB\0XXX', mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFileSync('BBB\0XXX'), { +assert.throws(() => execFileSync('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawn('BBB\0XXX'), { +assert.throws(() => spawn('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawnSync('BBB\0XXX'), { +assert.throws(() => spawnSync('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'modulePath' argument -throws(() => fork('BBB\0XXX'), { +assert.throws(() => fork('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); @@ -75,123 +75,123 @@ throws(() => fork('BBB\0XXX'), { // Not testing exec() and execSync() because these accept 'args' as a part of // 'command' as space-separated arguments. -throws(() => execFile(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC'], mustNotCall()), { +assert.throws(() => execFile(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC'], mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFileSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { +assert.throws(() => execFileSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => fork(__filename, ['AAA', 'BBB\0XXX', 'CCC']), { +assert.throws(() => fork(__filename, ['AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawn(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { +assert.throws(() => spawn(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawnSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { +assert.throws(() => spawnSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'options.cwd' argument -throws(() => exec(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), { +assert.throws(() => exec(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFile(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), { +assert.throws(() => execFile(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFileSync(process.execPath, { cwd: 'BBB\0XXX' }), { +assert.throws(() => execFileSync(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execSync(process.execPath, { cwd: 'BBB\0XXX' }), { +assert.throws(() => execSync(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => fork(__filename, { cwd: 'BBB\0XXX' }), { +assert.throws(() => fork(__filename, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawn(process.execPath, { cwd: 'BBB\0XXX' }), { +assert.throws(() => spawn(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawnSync(process.execPath, { cwd: 'BBB\0XXX' }), { +assert.throws(() => spawnSync(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'options.argv0' argument -throws(() => exec(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), { +assert.throws(() => exec(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFile(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), { +assert.throws(() => execFile(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFileSync(process.execPath, { argv0: 'BBB\0XXX' }), { +assert.throws(() => execFileSync(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execSync(process.execPath, { argv0: 'BBB\0XXX' }), { +assert.throws(() => execSync(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => fork(__filename, { argv0: 'BBB\0XXX' }), { +assert.throws(() => fork(__filename, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawn(process.execPath, { argv0: 'BBB\0XXX' }), { +assert.throws(() => spawn(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawnSync(process.execPath, { argv0: 'BBB\0XXX' }), { +assert.throws(() => spawnSync(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'options.shell' argument -throws(() => exec(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), { +assert.throws(() => exec(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFile(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), { +assert.throws(() => execFile(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFileSync(process.execPath, { shell: 'BBB\0XXX' }), { +assert.throws(() => execFileSync(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execSync(process.execPath, { shell: 'BBB\0XXX' }), { +assert.throws(() => execSync(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); @@ -199,96 +199,96 @@ throws(() => execSync(process.execPath, { shell: 'BBB\0XXX' }), { // Not testing fork() because it doesn't accept the shell option (internally it // explicitly sets shell to false). -throws(() => spawn(process.execPath, { shell: 'BBB\0XXX' }), { +assert.throws(() => spawn(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawnSync(process.execPath, { shell: 'BBB\0XXX' }), { +assert.throws(() => spawnSync(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'options.env' argument -throws(() => exec(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), { +assert.throws(() => exec(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => exec(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), { +assert.throws(() => exec(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFile(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), { +assert.throws(() => execFile(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFile(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), { +assert.throws(() => execFile(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFileSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { +assert.throws(() => execFileSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execFileSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { +assert.throws(() => execFileSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { +assert.throws(() => execSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => execSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { +assert.throws(() => execSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => fork(__filename, { env: { 'AAA': 'BBB\0XXX' } }), { +assert.throws(() => fork(__filename, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => fork(__filename, { env: { 'BBB\0XXX': 'AAA' } }), { +assert.throws(() => fork(__filename, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawn(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { +assert.throws(() => spawn(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawn(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { +assert.throws(() => spawn(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawnSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { +assert.throws(() => spawnSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); -throws(() => spawnSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { +assert.throws(() => spawnSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'options.execPath' argument -throws(() => fork(__filename, { execPath: 'BBB\0XXX' }), { +assert.throws(() => fork(__filename, { execPath: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); // Tests for the 'options.execArgv' argument -throws(() => fork(__filename, { execArgv: ['AAA', 'BBB\0XXX', 'CCC'] }), { +assert.throws(() => fork(__filename, { execArgv: ['AAA', 'BBB\0XXX', 'CCC'] }), { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', }); diff --git a/test/parallel/test-child-process-spawn-timeout-kill-signal.js b/test/parallel/test-child-process-spawn-timeout-kill-signal.js index a03a984b50ebbd..9ac76285a7df5f 100644 --- a/test/parallel/test-child-process-spawn-timeout-kill-signal.js +++ b/test/parallel/test-child-process-spawn-timeout-kill-signal.js @@ -1,7 +1,7 @@ 'use strict'; const { mustCall } = require('../common'); -const { strictEqual, throws } = require('assert'); +const assert = require('assert'); const fixtures = require('../common/fixtures'); const { spawn } = require('child_process'); const { getEventListeners } = require('events'); @@ -12,7 +12,7 @@ const aliveForeverFile = 'child-process-stay-alive-forever.js'; const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], { timeout: 5, }); - cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM'))); + cp.on('exit', mustCall((code, ks) => assert.strictEqual(ks, 'SIGTERM'))); } { @@ -21,16 +21,16 @@ const aliveForeverFile = 'child-process-stay-alive-forever.js'; timeout: 6, killSignal: 'SIGKILL', }); - cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL'))); + cp.on('exit', mustCall((code, ks) => assert.strictEqual(ks, 'SIGKILL'))); } { // Verify timeout verification - throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], { + assert.throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], { timeout: 'badValue', }), /ERR_INVALID_ARG_TYPE/); - throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], { + assert.throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], { timeout: {}, }), /ERR_INVALID_ARG_TYPE/); } @@ -43,8 +43,8 @@ const aliveForeverFile = 'child-process-stay-alive-forever.js'; timeout: 6, signal, }); - strictEqual(getEventListeners(signal, 'abort').length, 1); + assert.strictEqual(getEventListeners(signal, 'abort').length, 1); cp.on('exit', mustCall(() => { - strictEqual(getEventListeners(signal, 'abort').length, 0); + assert.strictEqual(getEventListeners(signal, 'abort').length, 0); })); } diff --git a/test/parallel/test-cli-options-as-flags.js b/test/parallel/test-cli-options-as-flags.js index c9d92b69f72a45..04e9e801b8ec81 100644 --- a/test/parallel/test-cli-options-as-flags.js +++ b/test/parallel/test-cli-options-as-flags.js @@ -4,7 +4,7 @@ const { spawnPromisified, } = require('../common'); const fixtures = require('../common/fixtures'); -const { strictEqual } = require('node:assert'); +const assert = require('node:assert'); const { describe, it } = require('node:test'); const path = require('node:path'); @@ -21,11 +21,11 @@ describe('getOptionsAsFlagsFromBinding', () => { fixtureFile, ]); - strictEqual(result.code, 0); + assert.strictEqual(result.code, 0); const flags = JSON.parse(result.stdout.trim()); - strictEqual(flags.includes('--no-warnings'), true); - strictEqual(flags.includes('--stack-trace-limit=512'), true); + assert.strictEqual(flags.includes('--no-warnings'), true); + assert.strictEqual(flags.includes('--stack-trace-limit=512'), true); }); it('should extract flags from NODE_OPTIONS environment variable', async () => { @@ -40,13 +40,13 @@ describe('getOptionsAsFlagsFromBinding', () => { } }); - strictEqual(result.code, 0); + assert.strictEqual(result.code, 0); const flags = JSON.parse(result.stdout.trim()); // Should contain the flag from NODE_OPTIONS - strictEqual(flags.includes('--stack-trace-limit=4096'), true); + assert.strictEqual(flags.includes('--stack-trace-limit=4096'), true); // Should also contain command line flags - strictEqual(flags.includes('--no-warnings'), true); + assert.strictEqual(flags.includes('--no-warnings'), true); }); it('should extract flags from config file', async () => { @@ -58,15 +58,15 @@ describe('getOptionsAsFlagsFromBinding', () => { fixtureFile, ]); - strictEqual(result.code, 0); + assert.strictEqual(result.code, 0); const flags = JSON.parse(result.stdout.trim()); // Should contain flags from config file - strictEqual(flags.includes('--experimental-transform-types'), true); - strictEqual(flags.includes('--max-http-header-size=8192'), true); - strictEqual(flags.includes('--test-isolation=none'), true); + assert.strictEqual(flags.includes('--experimental-transform-types'), true); + assert.strictEqual(flags.includes('--max-http-header-size=8192'), true); + assert.strictEqual(flags.includes('--test-isolation=none'), true); // Should also contain command line flags - strictEqual(flags.includes('--no-warnings'), true); + assert.strictEqual(flags.includes('--no-warnings'), true); }); it('should extract flags from config file and command line', async () => { @@ -79,17 +79,17 @@ describe('getOptionsAsFlagsFromBinding', () => { fixtureFile, ]); - strictEqual(result.code, 0); + assert.strictEqual(result.code, 0); const flags = JSON.parse(result.stdout.trim()); // Should contain flags from command line arguments - strictEqual(flags.includes('--no-warnings'), true); - strictEqual(flags.includes('--stack-trace-limit=512'), true); + assert.strictEqual(flags.includes('--no-warnings'), true); + assert.strictEqual(flags.includes('--stack-trace-limit=512'), true); // Should contain flags from config file - strictEqual(flags.includes('--experimental-transform-types'), true); - strictEqual(flags.includes('--max-http-header-size=8192'), true); - strictEqual(flags.includes('--test-isolation=none'), true); + assert.strictEqual(flags.includes('--experimental-transform-types'), true); + assert.strictEqual(flags.includes('--max-http-header-size=8192'), true); + assert.strictEqual(flags.includes('--test-isolation=none'), true); }); it('should extract flags from .env file', async () => { @@ -100,12 +100,12 @@ describe('getOptionsAsFlagsFromBinding', () => { fixtureFile, ]); - strictEqual(result.code, 0); + assert.strictEqual(result.code, 0); const flags = JSON.parse(result.stdout.trim()); // Should contain flags from .env file (NODE_OPTIONS) - strictEqual(flags.includes('--v8-pool-size=8'), true); + assert.strictEqual(flags.includes('--v8-pool-size=8'), true); // Should also contain command line flags - strictEqual(flags.includes('--no-warnings'), true); + assert.strictEqual(flags.includes('--no-warnings'), true); }); }); diff --git a/test/parallel/test-cluster-worker-events.js b/test/parallel/test-cluster-worker-events.js index 6c044ace8df04c..cbb14405c1f363 100644 --- a/test/parallel/test-cluster-worker-events.js +++ b/test/parallel/test-cluster-worker-events.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const cluster = require('cluster'); @@ -30,10 +30,10 @@ if (cluster.isPrimary) { const worker = cluster.fork(); - worker.on('exit', (code) => { + worker.on('exit', common.mustCall((code) => { assert.strictEqual(code, OK); process.exit(0); - }); + })); const result = worker.send('SOME MESSAGE'); assert.strictEqual(result, true); @@ -58,10 +58,10 @@ const check = (m) => { assert.deepStrictEqual(messages[0], messages[1]); - cluster.worker.once('error', (e) => { + cluster.worker.once('error', common.mustCall((e) => { assert.strictEqual(e, 'HI'); process.exit(OK); - }); + })); process.emit('error', 'HI'); }; diff --git a/test/parallel/test-cluster-worker-isdead.js b/test/parallel/test-cluster-worker-isdead.js index 6f2aa3c52ecd5c..24395da42045b6 100644 --- a/test/parallel/test-cluster-worker-isdead.js +++ b/test/parallel/test-cluster-worker-isdead.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const cluster = require('cluster'); const assert = require('assert'); @@ -10,12 +10,12 @@ if (cluster.isPrimary) { `isDead() returned ${workerDead}. isDead() should return ` + 'false right after the worker has been created.'); - worker.on('exit', function() { + worker.on('exit', common.mustCall(() => { workerDead = worker.isDead(); assert.ok(workerDead, `isDead() returned ${workerDead}. After an event has been ` + 'emitted, isDead should return true'); - }); + })); worker.on('message', function(msg) { if (msg === 'readyToDie') { diff --git a/test/parallel/test-common-must-not-call.js b/test/parallel/test-common-must-not-call.js index b3c94a2390ffb6..43da3a208f6d8e 100644 --- a/test/parallel/test-common-must-not-call.js +++ b/test/parallel/test-common-must-not-call.js @@ -10,7 +10,7 @@ const testFunction1 = common.mustNotCall(message); const testFunction2 = common.mustNotCall(message); -const createValidate = (line, args = []) => common.mustCall((e) => { +const createValidate = common.mustCallAtLeast((line, args = []) => common.mustCall((e) => { const prefix = `${message} at `; assert.ok(e.message.startsWith(prefix)); if (process.platform === 'win32') { @@ -24,7 +24,7 @@ const createValidate = (line, args = []) => common.mustCall((e) => { const argsInfo = args.length > 0 ? `\ncalled with arguments: ${args.map(util.inspect).join(', ')}` : ''; assert.strictEqual(rest, line + argsInfo); -}); +})); const validate1 = createValidate('9'); try { diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index cc235bfadae146..4f4e6703f88702 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -8,7 +8,7 @@ const { skipIfSQLiteMissing(); const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { match, strictEqual, deepStrictEqual } = require('node:assert'); +const assert = require('node:assert'); const { test, it, describe } = require('node:test'); const { chmodSync, writeFileSync, constants } = require('node:fs'); const { join } = require('node:path'); @@ -19,10 +19,10 @@ test('should handle non existing json', async () => { 'i-do-not-exist.json', '-p', '"Hello, World!"', ]); - match(result.stderr, /Cannot read configuration from i-do-not-exist\.json: no such file or directory/); - match(result.stderr, /i-do-not-exist\.json: not found/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Cannot read configuration from i-do-not-exist\.json: no such file or directory/); + assert.match(result.stderr, /i-do-not-exist\.json: not found/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('should handle empty json', async () => { @@ -31,10 +31,10 @@ test('should handle empty json', async () => { fixtures.path('rc/empty.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /Can't parse/); - match(result.stderr, /empty\.json: invalid content/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Can't parse/); + assert.match(result.stderr, /empty\.json: invalid content/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('should handle empty object json', async () => { @@ -44,9 +44,9 @@ test('should handle empty object json', async () => { fixtures.path('rc/empty-object.json'), '-p', '"Hello, World!"', ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, World!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, World!/); + assert.strictEqual(result.code, 0); }); test('should parse boolean flag', async () => { @@ -55,9 +55,9 @@ test('should parse boolean flag', async () => { fixtures.path('rc/transform-types.json'), fixtures.path('typescript/ts/transformation/test-enum.ts'), ]); - match(result.stderr, /--experimental-config-file is an experimental feature and might change at any time/); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.match(result.stderr, /--experimental-config-file is an experimental feature and might change at any time/); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('should parse boolean flag defaulted to true', async () => { @@ -66,9 +66,9 @@ test('should parse boolean flag defaulted to true', async () => { fixtures.path('rc/warnings-false.json'), '-p', 'process.emitWarning("A warning")', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'undefined\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'undefined\n'); + assert.strictEqual(result.code, 0); }); test('should throw an error when a flag is declared twice', async () => { @@ -78,9 +78,9 @@ test('should throw an error when a flag is declared twice', async () => { fixtures.path('rc/override-property.json'), fixtures.path('typescript/ts/transformation/test-enum.ts'), ]); - match(result.stderr, /Option --experimental-transform-types is already defined/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Option --experimental-transform-types is already defined/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); @@ -92,9 +92,9 @@ test('should override env-file', async () => { '--env-file', fixtures.path('dotenv/node-options-no-tranform.env'), fixtures.path('typescript/ts/transformation/test-enum.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('should not override NODE_OPTIONS', async () => { @@ -109,9 +109,9 @@ test('should not override NODE_OPTIONS', async () => { NODE_OPTIONS: '--no-experimental-transform-types', }, }); - match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('should not override CLI flags', async () => { @@ -122,9 +122,9 @@ test('should not override CLI flags', async () => { fixtures.path('rc/transform-types.json'), fixtures.path('typescript/ts/transformation/test-enum.ts'), ]); - match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('should parse array flag correctly', async () => { @@ -134,9 +134,9 @@ test('should parse array flag correctly', async () => { fixtures.path('rc/import.json'), '--eval', 'setTimeout(() => console.log("D"),99)', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'A\nB\nC\nD\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'A\nB\nC\nD\n'); + assert.strictEqual(result.code, 0); }); test('should validate invalid array flag', async () => { @@ -146,9 +146,9 @@ test('should validate invalid array flag', async () => { fixtures.path('rc/invalid-import.json'), '--eval', 'setTimeout(() => console.log("D"),99)', ]); - match(result.stderr, /invalid-import\.json: invalid content/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /invalid-import\.json: invalid content/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('should validate array flag as string', async () => { @@ -158,9 +158,9 @@ test('should validate array flag as string', async () => { fixtures.path('rc/import-as-string.json'), '--eval', 'setTimeout(() => console.log("B"),99)', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'A\nB\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'A\nB\n'); + assert.strictEqual(result.code, 0); }); test('should throw at unknown flag', async () => { @@ -170,9 +170,9 @@ test('should throw at unknown flag', async () => { fixtures.path('rc/unknown-flag.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /Unknown or not allowed option some-unknown-flag for namespace nodeOptions/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Unknown or not allowed option some-unknown-flag for namespace nodeOptions/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('should throw at flag not available in NODE_OPTIONS', async () => { @@ -182,9 +182,9 @@ test('should throw at flag not available in NODE_OPTIONS', async () => { fixtures.path('rc/not-node-options-flag.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /Unknown or not allowed option test for namespace nodeOptions/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Unknown or not allowed option test for namespace nodeOptions/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('unsigned flag should be parsed correctly', async () => { @@ -194,9 +194,9 @@ test('unsigned flag should be parsed correctly', async () => { fixtures.path('rc/numeric.json'), '-p', 'http.maxHeaderSize', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, '4294967295\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, '4294967295\n'); + assert.strictEqual(result.code, 0); }); test('numeric flag should not allow negative values', async () => { @@ -206,10 +206,10 @@ test('numeric flag should not allow negative values', async () => { fixtures.path('rc/negative-numeric.json'), '-p', 'http.maxHeaderSize', ]); - match(result.stderr, /Invalid value for --max-http-header-size/); - match(result.stderr, /negative-numeric\.json: invalid content/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Invalid value for --max-http-header-size/); + assert.match(result.stderr, /negative-numeric\.json: invalid content/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('v8 flag should not be allowed in config file', async () => { @@ -219,9 +219,9 @@ test('v8 flag should not be allowed in config file', async () => { fixtures.path('rc/v8-flag.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /V8 flag --abort-on-uncaught-exception is currently not supported/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /V8 flag --abort-on-uncaught-exception is currently not supported/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('string flag should be parsed correctly', async () => { @@ -232,9 +232,9 @@ test('string flag should be parsed correctly', async () => { fixtures.path('rc/string.json'), fixtures.path('rc/test.js'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, '.\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, '.\n'); + assert.strictEqual(result.code, 0); }); test('host port flag should be parsed correctly', { skip: !process.features.inspector }, async () => { @@ -245,9 +245,9 @@ test('host port flag should be parsed correctly', { skip: !process.features.insp fixtures.path('rc/host-port.json'), '-p', 'require("internal/options").getOptionValue("--inspect-port").port', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, '65535\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, '65535\n'); + assert.strictEqual(result.code, 0); }); test('--inspect=true should be parsed correctly', { skip: !process.features.inspector }, async () => { @@ -258,9 +258,9 @@ test('--inspect=true should be parsed correctly', { skip: !process.features.insp '--inspect-port', '0', '-p', 'require("node:inspector").url()', ]); - match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/); - match(result.stdout, /ws:\/\/[^\s]+/); - strictEqual(result.code, 0); + assert.match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/); + assert.match(result.stdout, /ws:\/\/[^\s]+/); + assert.strictEqual(result.code, 0); }); test('--inspect=false should be parsed correctly', { skip: !process.features.inspector }, async () => { @@ -270,9 +270,9 @@ test('--inspect=false should be parsed correctly', { skip: !process.features.ins fixtures.path('rc/inspect-false.json'), '-p', 'require("node:inspector").url()', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'undefined\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'undefined\n'); + assert.strictEqual(result.code, 0); }); test('no op flag should throw', async () => { @@ -282,10 +282,10 @@ test('no op flag should throw', async () => { fixtures.path('rc/no-op.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /No-op flag --http-parser is currently not supported/); - match(result.stderr, /no-op\.json: invalid content/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /No-op flag --http-parser is currently not supported/); + assert.match(result.stderr, /no-op\.json: invalid content/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('should not allow users to sneak in a flag', async () => { @@ -295,9 +295,9 @@ test('should not allow users to sneak in a flag', async () => { fixtures.path('rc/sneaky-flag.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /The number of NODE_OPTIONS doesn't match the number of flags in the config file/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /The number of NODE_OPTIONS doesn't match the number of flags in the config file/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('non object root', async () => { @@ -307,9 +307,9 @@ test('non object root', async () => { fixtures.path('rc/non-object-root.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /Root value unexpected not an object for/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Root value unexpected not an object for/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('non object node options', async () => { @@ -319,9 +319,9 @@ test('non object node options', async () => { fixtures.path('rc/non-object-node-options.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /"nodeOptions" value unexpected for/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /"nodeOptions" value unexpected for/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('should throw correct error when a json is broken', async () => { @@ -331,10 +331,10 @@ test('should throw correct error when a json is broken', async () => { fixtures.path('rc/broken.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /Can't parse/); - match(result.stderr, /broken\.json: invalid content/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Can't parse/); + assert.match(result.stderr, /broken\.json: invalid content/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('broken value in node_options', async () => { @@ -344,10 +344,10 @@ test('broken value in node_options', async () => { fixtures.path('rc/broken-node-options.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /Can't parse/); - match(result.stderr, /broken-node-options\.json: invalid content/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Can't parse/); + assert.match(result.stderr, /broken-node-options\.json: invalid content/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); test('should use node.config.json as default', async () => { @@ -358,9 +358,9 @@ test('should use node.config.json as default', async () => { ], { cwd: fixtures.path('rc/default'), }); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, '10\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, '10\n'); + assert.strictEqual(result.code, 0); }); test('should override node.config.json when specificied', async () => { @@ -373,9 +373,9 @@ test('should override node.config.json when specificied', async () => { ], { cwd: fixtures.path('rc/default'), }); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, '20\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, '20\n'); + assert.strictEqual(result.code, 0); }); // Skip on windows because it doesn't support chmod changing read permissions // Also skip if user is root because it would have read permissions anyway @@ -395,9 +395,9 @@ test('should throw an error when the file is non readable', { ], { cwd: tmpdir.path, }); - match(result.stderr, /Cannot read configuration from node\.config\.json: permission denied/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Cannot read configuration from node\.config\.json: permission denied/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); describe('namespace-scoped options', () => { @@ -409,9 +409,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/namespaced/node.config.json'), '-p', 'require("internal/options").getOptionValue("--test-isolation")', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'none\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'none\n'); + assert.strictEqual(result.code, 0); }); it('should throw an error when a namespace-scoped option is not recognised', async () => { @@ -421,9 +421,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/unknown-flag-namespace.json'), '-p', '"Hello, World!"', ]); - match(result.stderr, /Unknown or not allowed option unknown-flag for namespace testRunner/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Unknown or not allowed option unknown-flag for namespace testRunner/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); it('should not throw an error when a namespace is not recognised', async () => { @@ -433,9 +433,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/unknown-namespace.json'), '-p', '"Hello, World!"', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'Hello, World!\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'Hello, World!\n'); + assert.strictEqual(result.code, 0); }); it('should handle an empty namespace valid namespace', async () => { @@ -445,9 +445,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/empty-valid-namespace.json'), '-p', '"Hello, World!"', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'Hello, World!\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'Hello, World!\n'); + assert.strictEqual(result.code, 0); }); it('should throw an error if a namespace-scoped option has already been set in node options', async () => { @@ -458,9 +458,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/override-node-option-with-namespace.json'), '-p', 'require("internal/options").getOptionValue("--test-isolation")', ]); - match(result.stderr, /Option --test-isolation is already defined/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Option --test-isolation is already defined/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); it('should throw an error if a node option has already been set in a namespace-scoped option', async () => { @@ -471,9 +471,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/override-namespace.json'), '-p', 'require("internal/options").getOptionValue("--test-isolation")', ]); - match(result.stderr, /Option --test-isolation is already defined/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 9); + assert.match(result.stderr, /Option --test-isolation is already defined/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 9); }); it('should prioritise CLI namespace-scoped options over config file options', async () => { @@ -485,9 +485,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/namespaced/node.config.json'), '-p', 'require("internal/options").getOptionValue("--test-isolation")', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'process\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'process\n'); + assert.strictEqual(result.code, 0); }); it('should append namespace-scoped config file options with CLI options in case of array', async () => { @@ -500,7 +500,7 @@ describe('namespace-scoped options', () => { fixtures.path('rc/namespace-with-array.json'), '-p', 'JSON.stringify(require("internal/options").getOptionValue("--test-coverage-exclude"))', ]); - strictEqual(result.stderr, ''); + assert.strictEqual(result.stderr, ''); const excludePatterns = JSON.parse(result.stdout); const expected = [ 'config-pattern1', @@ -508,8 +508,8 @@ describe('namespace-scoped options', () => { 'cli-pattern1', 'cli-pattern2', ]; - deepStrictEqual(excludePatterns, expected); - strictEqual(result.code, 0); + assert.deepStrictEqual(excludePatterns, expected); + assert.strictEqual(result.code, 0); }); it('should allow setting kDisallowedInEnvvar in the config file if part of a namespace', async () => { @@ -522,9 +522,9 @@ describe('namespace-scoped options', () => { fixtures.path('rc/namespace-with-disallowed-envvar.json'), '-p', 'require("internal/options").getOptionValue("--test-concurrency")', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, '1\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, '1\n'); + assert.strictEqual(result.code, 0); }); it('should override namespace-scoped config file options with CLI options', async () => { @@ -538,8 +538,8 @@ describe('namespace-scoped options', () => { fixtures.path('rc/namespace-with-disallowed-envvar.json'), '-p', 'require("internal/options").getOptionValue("--test-concurrency")', ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, '2\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, '2\n'); + assert.strictEqual(result.code, 0); }); }); diff --git a/test/parallel/test-console-diagnostics-channels.js b/test/parallel/test-console-diagnostics-channels.js index 1a12d7a78f0b71..70de442697e1bb 100644 --- a/test/parallel/test-console-diagnostics-channels.js +++ b/test/parallel/test-console-diagnostics-channels.js @@ -1,7 +1,7 @@ 'use strict'; const { mustCall } = require('../common'); -const { deepStrictEqual, ok, strictEqual } = require('assert'); +const assert = require('assert'); const { channel } = require('diagnostics_channel'); @@ -54,10 +54,10 @@ for (const method of methods) { channels[method].subscribe(mustCall((args) => { // Should not have been formatted yet. intercepted = true; - ok(!formatted); + assert.ok(!formatted); // Should receive expected log message args. - deepStrictEqual(args, [foo, bar, baz]); + assert.deepStrictEqual(args, [foo, bar, baz]); // Should be able to mutate message args and have it reflected in output. bar.added = true; @@ -66,10 +66,10 @@ for (const method of methods) { hijack(mustCall((output) => { // Should have already been intercepted. formatted = true; - ok(intercepted); + assert.ok(intercepted); // Should produce expected formatted output with mutated message args. - strictEqual(output, 'string { key: /value/, added: true } [ 1, 2, 3 ]\n'); + assert.strictEqual(output, 'string { key: /value/, added: true } [ 1, 2, 3 ]\n'); })); console[method](foo, bar, baz); diff --git a/test/parallel/test-console-tty-colors-per-stream.js b/test/parallel/test-console-tty-colors-per-stream.js index a7502766a1e354..4831c1d2ef7626 100644 --- a/test/parallel/test-console-tty-colors-per-stream.js +++ b/test/parallel/test-console-tty-colors-per-stream.js @@ -2,7 +2,7 @@ require('../common'); const { Console } = require('console'); const { PassThrough } = require('stream'); -const { strict: assert } = require('assert'); +const assert = require('assert'); const stdout = new PassThrough().setEncoding('utf8'); const stderr = new PassThrough().setEncoding('utf8'); diff --git a/test/parallel/test-constants.js b/test/parallel/test-constants.js index 08d1f1dbcdd0ab..51023b56d4dca1 100644 --- a/test/parallel/test-constants.js +++ b/test/parallel/test-constants.js @@ -15,16 +15,16 @@ assert.ok(binding.fs); assert.ok(binding.crypto); ['os', 'fs', 'crypto'].forEach((l) => { - Object.keys(binding[l]).forEach((k) => { + for (const k of Object.keys(binding[l])) { if (typeof binding[l][k] === 'object') { // errno and signals - Object.keys(binding[l][k]).forEach((j) => { + for (const j of Object.keys(binding[l][k])) { assert.strictEqual(binding[l][k][j], constants[j]); - }); + } } if (l !== 'os') { // Top level os constant isn't currently copied assert.strictEqual(binding[l][k], constants[k]); } - }); + } }); assert.ok(Object.isFrozen(constants)); diff --git a/test/parallel/test-crypto-dh-generate-keys.js b/test/parallel/test-crypto-dh-generate-keys.js index e4598274328bd8..acf7e2d09b2b83 100644 --- a/test/parallel/test-crypto-dh-generate-keys.js +++ b/test/parallel/test-crypto-dh-generate-keys.js @@ -56,9 +56,9 @@ const { hasOpenSSL3 } = require('../common/crypto'); }, ['public']); // The public key is outdated: generateKeys() generates only the public key. - testGenerateKeysChangesKeys((dh) => { + testGenerateKeysChangesKeys(common.mustCall((dh) => { const oldPublicKey = dh.generateKeys(); dh.setPrivateKey(Buffer.from('01020304', 'hex')); assert.deepStrictEqual(dh.getPublicKey(), oldPublicKey); - }, ['public']); + }), ['public']); } diff --git a/test/parallel/test-crypto-domain.js b/test/parallel/test-crypto-domain.js index 62e2be4c0f39c2..3e8ead73dc28d2 100644 --- a/test/parallel/test-crypto-domain.js +++ b/test/parallel/test-crypto-domain.js @@ -28,7 +28,7 @@ const assert = require('assert'); const crypto = require('crypto'); const domain = require('domain'); -const test = (fn) => { +function test(fn) { const ex = new Error('BAM'); const d = domain.create(); d.on('error', common.mustCall(function(err) { @@ -37,11 +37,11 @@ const test = (fn) => { const cb = common.mustCall(function() { throw ex; }); - d.run(cb); + d.run(fn, cb); }; test(function(cb) { - crypto.pbkdf2('password', 'salt', 1, 8, cb); + crypto.pbkdf2('password', 'salt', 1, 8, 'sha1', cb); }); test(function(cb) { diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index 0c516d80950694..e8359ed6d0362c 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -243,14 +243,14 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', assert(Buffer.isBuffer(privateDER)); const plaintext = Buffer.from('Hello world', 'utf8'); - const testDecryption = (fn, ciphertexts, decryptionKeys) => { + const testDecryption = common.mustCall((fn, ciphertexts, decryptionKeys) => { for (const ciphertext of ciphertexts) { for (const key of decryptionKeys) { const deciphered = fn(key, ciphertext); assert.deepStrictEqual(deciphered, plaintext); } } - }; + }, 2); testDecryption(privateDecrypt, [ // Encrypt using the public key. diff --git a/test/parallel/test-crypto-op-during-process-exit.js b/test/parallel/test-crypto-op-during-process-exit.js index a9a70c39e095a3..28858dd1b57e49 100644 --- a/test/parallel/test-crypto-op-during-process-exit.js +++ b/test/parallel/test-crypto-op-during-process-exit.js @@ -1,7 +1,6 @@ 'use strict'; const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); } -const assert = require('assert'); const { generateKeyPair } = require('crypto'); if (common.isWindows) { @@ -21,8 +20,6 @@ generateKeyPair('rsa', { type: 'pkcs1', format: 'pem' } -}, (err/* , publicKey, privateKey */) => { - assert.ifError(err); -}); +}, common.mustNotCall()); setTimeout(() => process.exit(), common.platformTimeout(10)); diff --git a/test/parallel/test-crypto-randomfillsync-regression.js b/test/parallel/test-crypto-randomfillsync-regression.js index 7a378642588d9e..0b7cd6931569e4 100644 --- a/test/parallel/test-crypto-randomfillsync-regression.js +++ b/test/parallel/test-crypto-randomfillsync-regression.js @@ -4,7 +4,7 @@ if (!common.hasCrypto) common.skip('missing crypto'); const { randomFillSync } = require('crypto'); -const { notStrictEqual } = require('assert'); +const assert = require('assert'); const ab = new ArrayBuffer(20); const buf = Buffer.from(ab, 10); @@ -15,4 +15,4 @@ randomFillSync(buf); const after = buf.toString('hex'); -notStrictEqual(before, after); +assert.notStrictEqual(before, after); diff --git a/test/parallel/test-crypto-subtle-zero-length.js b/test/parallel/test-crypto-subtle-zero-length.js index f5a84727b02a01..fa0ffa0160d701 100644 --- a/test/parallel/test-crypto-subtle-zero-length.js +++ b/test/parallel/test-crypto-subtle-zero-length.js @@ -34,6 +34,4 @@ const { subtle } = globalThis.crypto; }, k, e); assert(v instanceof ArrayBuffer); assert.strictEqual(v.byteLength, 0); -})().then(common.mustCall()).catch((e) => { - assert.ifError(e); -}); +})().then(common.mustCall()); From 3995a076ec807bf006f79f9810e4aab608eec6d5 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 6 Nov 2025 12:51:02 +0100 Subject: [PATCH 2/3] fixup! test: ensure assertions are reached on more tests --- test/parallel/test-child-process-bad-stdio.js | 12 +++---- .../test-child-process-can-write-to-stdout.js | 6 ++-- test/parallel/test-child-process-cwd.js | 8 ++--- .../parallel/test-child-process-disconnect.js | 12 +++---- .../test-child-process-exec-encoding.js | 12 +++---- test/parallel/test-child-process-execfile.js | 4 +-- .../test-child-process-flush-stdio.js | 4 +-- ...ld-process-fork-closed-channel-segfault.js | 13 ++++---- .../parallel/test-child-process-fork-dgram.js | 4 +-- .../test-child-process-fork-net-server.js | 12 +++---- test/parallel/test-child-process-fork-ref.js | 6 ++-- test/parallel/test-child-process-fork.js | 4 +-- .../test-child-process-http-socket-leak.js | 4 +-- test/parallel/test-child-process-kill.js | 4 +-- .../test-child-process-send-keep-open.js | 4 +-- ...test-child-process-send-returns-boolean.js | 9 +++--- .../test-child-process-server-close.js | 6 ++-- .../test-child-process-spawnsync-args.js | 4 +-- ...est-child-process-spawnsync-kill-signal.js | 12 +++---- .../test-child-process-stdio-inherit.js | 6 ++-- test/parallel/test-cli-node-options.js | 4 +-- test/parallel/test-cli-node-print-help.js | 12 +++---- test/parallel/test-cluster-accept-fail.js | 8 ++--- test/parallel/test-cluster-basic.js | 8 ++--- .../test-cluster-concurrent-disconnect.js | 4 +-- ...r-disconnect-exitedAfterDisconnect-race.js | 4 +-- test/parallel/test-cluster-disconnect.js | 24 +++++++------- test/parallel/test-cluster-eaddrinuse.js | 4 +-- test/parallel/test-cluster-fork-stdio.js | 4 +-- .../parallel/test-cluster-fork-windowsHide.js | 4 +-- test/parallel/test-cluster-message.js | 12 +++---- test/parallel/test-cluster-net-send.js | 8 ++--- .../test-cluster-rr-handle-keep-loop-alive.js | 4 +-- test/parallel/test-cluster-send-deadlock.js | 6 ++-- .../test-cluster-send-handle-twice.js | 4 +-- .../test-cluster-server-restart-none.js | 8 ++--- .../test-cluster-server-restart-rr.js | 8 ++--- test/parallel/test-cluster-shared-leak.js | 8 ++--- test/parallel/test-cluster-worker-events.js | 4 +-- test/parallel/test-console.js | 4 +-- test/parallel/test-cppheap-stats.js | 32 +++++++++---------- .../test-crypto-op-during-process-exit.js | 6 +++- .../parallel/test-crypto-pqc-keygen-ml-dsa.js | 4 +++ .../parallel/test-crypto-pqc-keygen-ml-kem.js | 4 +++ .../test-crypto-pqc-keygen-slh-dsa.js | 2 ++ 45 files changed, 173 insertions(+), 163 deletions(-) diff --git a/test/parallel/test-child-process-bad-stdio.js b/test/parallel/test-child-process-bad-stdio.js index 3b17e2ce0d5a72..1e5bd4afc44e44 100644 --- a/test/parallel/test-child-process-bad-stdio.js +++ b/test/parallel/test-child-process-bad-stdio.js @@ -36,31 +36,31 @@ function createChild(options, callback) { } test('normal execution of a child process is handled', (_, done) => { - createChild({}, (err, stdout, stderr) => { + createChild({}, common.mustCall((err, stdout, stderr) => { assert.strictEqual(err, null); assert.strictEqual(stdout, ''); assert.strictEqual(stderr, ''); done(); - }); + })); }); test('execution with an error event is handled', (_, done) => { const error = new Error('foo'); - const child = createChild({}, (err, stdout, stderr) => { + const child = createChild({}, common.mustCall((err, stdout, stderr) => { assert.strictEqual(err, error); assert.strictEqual(stdout, ''); assert.strictEqual(stderr, ''); done(); - }); + })); child.emit('error', error); }); test('execution with a killed process is handled', (_, done) => { - createChild({ timeout: 1 }, (err, stdout, stderr) => { + createChild({ timeout: 1 }, common.mustCall((err, stdout, stderr) => { assert.strictEqual(err.killed, true); assert.strictEqual(stdout, ''); assert.strictEqual(stderr, ''); done(); - }); + })); }); diff --git a/test/parallel/test-child-process-can-write-to-stdout.js b/test/parallel/test-child-process-can-write-to-stdout.js index 069e07fb160282..68e1bff877fff4 100644 --- a/test/parallel/test-child-process-can-write-to-stdout.js +++ b/test/parallel/test-child-process-can-write-to-stdout.js @@ -2,7 +2,7 @@ // Tests that a spawned child process can write to stdout without throwing. // See https://github.com/nodejs/node-v0.x-archive/issues/1899. -require('../common'); +const common = require('../common'); const fixtures = require('../common/fixtures'); const assert = require('assert'); const spawn = require('child_process').spawn; @@ -16,7 +16,7 @@ child.stdout.on('data', function(data) { output += data; }); -child.on('exit', function(code, signal) { +child.on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); assert.strictEqual(output, 'hello, world!\n'); -}); +})); diff --git a/test/parallel/test-child-process-cwd.js b/test/parallel/test-child-process-cwd.js index e876361b167ffb..847c666a9077d3 100644 --- a/test/parallel/test-child-process-cwd.js +++ b/test/parallel/test-child-process-cwd.js @@ -32,7 +32,7 @@ const { spawn } = require('child_process'); // - whether the child pid is undefined or number, // - whether the exit code equals expectCode, // - optionally whether the trimmed stdout result matches expectData -function testCwd(options, expectPidType, expectCode = 0, expectData) { +function testCwd(options, expectPidType, expectCode = 0, expectData, shouldCallExit = true) { const child = spawn(...common.pwdCommand, options); assert.strictEqual(typeof child.pid, expectPidType); @@ -47,9 +47,9 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) { // Can't assert callback, as stayed in to API: // _The 'exit' event may or may not fire after an error has occurred._ - child.on('exit', function(code, signal) { + child.on('exit', shouldCallExit ? common.mustCall((code) => { assert.strictEqual(code, expectCode); - }); + }) : common.mustNotCall()); child.on('close', common.mustCall(function() { if (expectData) { @@ -68,7 +68,7 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) { // Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT { - testCwd({ cwd: 'does-not-exist' }, 'undefined', -1) + testCwd({ cwd: 'does-not-exist' }, 'undefined', -1, undefined, false) .on('error', common.mustCall(function(e) { assert.strictEqual(e.code, 'ENOENT'); })); diff --git a/test/parallel/test-child-process-disconnect.js b/test/parallel/test-child-process-disconnect.js index fb8a2dd0ea2213..0e4f37ae61d537 100644 --- a/test/parallel/test-child-process-disconnect.js +++ b/test/parallel/test-child-process-disconnect.js @@ -30,13 +30,13 @@ if (process.argv[2] === 'child') { // Check that the 'disconnect' event is deferred to the next event loop tick. const disconnect = process.disconnect; - process.disconnect = function() { + process.disconnect = common.mustCall(function() { disconnect.apply(this, arguments); // If the event is emitted synchronously, we're too late by now. process.once('disconnect', common.mustCall(disconnectIsNotAsync)); // The funky function name makes it show up legible in mustCall errors. function disconnectIsNotAsync() {} - }; + }); const server = net.createServer(); @@ -81,13 +81,13 @@ if (process.argv[2] === 'child') { child.on('exit', common.mustCall()); // When child is listening - child.on('message', function(obj) { + child.on('message', common.mustCallAtLeast((obj) => { if (obj && obj.msg === 'ready') { // Connect to child using TCP to know if disconnect was emitted const socket = net.connect(obj.port); - socket.on('data', function(data) { + socket.on('data', common.mustCallAtLeast((data) => { data = data.toString(); // Ready to be disconnected @@ -103,10 +103,10 @@ if (process.argv[2] === 'child') { // 'disconnect' is emitted childFlag = (data === 'true'); - }); + })); } - }); + })); process.on('exit', function() { assert.strictEqual(childFlag, false); diff --git a/test/parallel/test-child-process-exec-encoding.js b/test/parallel/test-child-process-exec-encoding.js index 059e300e4e760e..21ab207fca8ce2 100644 --- a/test/parallel/test-child-process-exec-encoding.js +++ b/test/parallel/test-child-process-exec-encoding.js @@ -22,28 +22,28 @@ if (process.argv[2] === 'child') { } // Test default encoding, which should be utf8. - run({}, (stdout, stderr) => { + run({}, common.mustCall((stdout, stderr) => { assert.strictEqual(typeof stdout, 'string'); assert.strictEqual(typeof stderr, 'string'); assert.strictEqual(stdout, expectedStdout); assert.strictEqual(stderr, expectedStderr); - }); + })); // Test explicit utf8 encoding. - run({ encoding: 'utf8' }, (stdout, stderr) => { + run({ encoding: 'utf8' }, common.mustCall((stdout, stderr) => { assert.strictEqual(typeof stdout, 'string'); assert.strictEqual(typeof stderr, 'string'); assert.strictEqual(stdout, expectedStdout); assert.strictEqual(stderr, expectedStderr); - }); + })); // Test cases that result in buffer encodings. [undefined, null, 'buffer', 'invalid'].forEach((encoding) => { - run({ encoding }, (stdout, stderr) => { + run({ encoding }, common.mustCall((stdout, stderr) => { assert(stdout instanceof Buffer); assert(stdout instanceof Buffer); assert.strictEqual(stdout.toString(), expectedStdout); assert.strictEqual(stderr.toString(), expectedStderr); - }); + })); }); } diff --git a/test/parallel/test-child-process-execfile.js b/test/parallel/test-child-process-execfile.js index 80d94cc5626f2f..d44bae59d17484 100644 --- a/test/parallel/test-child-process-execfile.js +++ b/test/parallel/test-child-process-execfile.js @@ -65,14 +65,14 @@ common.expectWarning( const ac = new AbortController(); const { signal } = ac; - const test = () => { + const test = common.mustCall(() => { const check = common.mustCall((err) => { assert.strictEqual(err.code, 'ABORT_ERR'); assert.strictEqual(err.name, 'AbortError'); assert.strictEqual(err.signal, undefined); }); execFile(process.execPath, [echoFixture, 0], { signal }, check); - }; + }); // Verify that it still works the same way now that the signal is aborted. test(); diff --git a/test/parallel/test-child-process-flush-stdio.js b/test/parallel/test-child-process-flush-stdio.js index 7b9a2a049cb20b..37e63e64990e95 100644 --- a/test/parallel/test-child-process-flush-stdio.js +++ b/test/parallel/test-child-process-flush-stdio.js @@ -17,7 +17,7 @@ p.on('close', common.mustCall((code, signal) => { p.stdout.read(); -const spawnWithReadable = () => { +const spawnWithReadable = common.mustCall(() => { const buffer = []; const p = cp.spawn('echo', ['123'], opts); p.on('close', common.mustCall((code, signal) => { @@ -30,4 +30,4 @@ const spawnWithReadable = () => { while ((buf = p.stdout.read()) !== null) buffer.push(buf); }); -}; +}); diff --git a/test/parallel/test-child-process-fork-closed-channel-segfault.js b/test/parallel/test-child-process-fork-closed-channel-segfault.js index 47eb87c45fd045..73bd118ddce363 100644 --- a/test/parallel/test-child-process-fork-closed-channel-segfault.js +++ b/test/parallel/test-child-process-fork-closed-channel-segfault.js @@ -28,7 +28,7 @@ const server = net s.destroy(); }, 100); }) - .listen(0, function() { + .listen(0, common.mustCall(() => { const worker = cluster.fork(); worker.on('error', function(err) { @@ -70,9 +70,8 @@ const server = net }) ); - worker.on('online', function() { - send(function(err) { - assert.ifError(err); + worker.on('online', common.mustCall(() => { + send(common.mustSucceed(() => { send(function(err) { // Ignore errors when sending the second handle because the worker // may already have exited. @@ -83,6 +82,6 @@ const server = net throw err; } }); - }); - }); - }); + })); + })); + })); diff --git a/test/parallel/test-child-process-fork-dgram.js b/test/parallel/test-child-process-fork-dgram.js index 4ea2edc60c29c1..6a7be71f9d87ea 100644 --- a/test/parallel/test-child-process-fork-dgram.js +++ b/test/parallel/test-child-process-fork-dgram.js @@ -92,9 +92,7 @@ if (process.argv[2] === 'child') { msg.length, serverPort, '127.0.0.1', - (err) => { - assert.ifError(err); - } + common.mustSucceed(), ); } }, 1); diff --git a/test/parallel/test-child-process-fork-net-server.js b/test/parallel/test-child-process-fork-net-server.js index 3a3f01c6d664cb..e52b4dbe53e67a 100644 --- a/test/parallel/test-child-process-fork-net-server.js +++ b/test/parallel/test-child-process-fork-net-server.js @@ -60,7 +60,7 @@ if (process.argv[2] === 'child') { // TODO(@jasnell): The close event is not called consistently // across platforms. Need to investigate if it can be made // more consistent. - const onClose = (msg) => { + const onClose = common.mustCallAtLeast((msg) => { if (msg.what !== 'close') return; process.removeListener('message', onClose); @@ -68,7 +68,7 @@ if (process.argv[2] === 'child') { process.send({ what: 'close' }); })); serverScope.close(); - }; + }); process.on('message', onClose); @@ -86,13 +86,13 @@ if (process.argv[2] === 'child') { function testServer(callback) { // Destroy server execute callback when done. - const countdown = new Countdown(2, () => { + const countdown = new Countdown(2, common.mustCall(() => { server.on('close', common.mustCall(() => { debug('PARENT: server closed'); child.send({ what: 'close' }); })); server.close(); - }); + })); // We expect 4 connections and close events. const connections = new Countdown(4, () => countdown.dec()); @@ -122,7 +122,7 @@ if (process.argv[2] === 'child') { // event is emitted appears to be variable across platforms. // Need to investigate why and whether it can be made // more consistent. - const messageHandlers = (msg) => { + const messageHandlers = common.mustCallAtLeast((msg) => { if (msg.what === 'listening') { // Make connections. let socket; @@ -143,7 +143,7 @@ if (process.argv[2] === 'child') { child.removeListener('message', messageHandlers); callback(); } - }; + }); child.on('message', messageHandlers); } diff --git a/test/parallel/test-child-process-fork-ref.js b/test/parallel/test-child-process-fork-ref.js index bbf4432af80866..ae025a72fa2748 100644 --- a/test/parallel/test-child-process-fork-ref.js +++ b/test/parallel/test-child-process-fork-ref.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const fork = require('child_process').fork; @@ -52,8 +52,8 @@ if (process.argv[2] === 'child') { stdout += chunk; }); - child.once('exit', function() { + child.once('exit', common.mustCall(() => { assert.deepStrictEqual(ipc, ['1', '2']); assert.strictEqual(stdout, '3'); - }); + })); } diff --git a/test/parallel/test-child-process-fork.js b/test/parallel/test-child-process-fork.js index ee9dd3fc9f4746..3146c4fea18237 100644 --- a/test/parallel/test-child-process-fork.js +++ b/test/parallel/test-child-process-fork.js @@ -30,10 +30,10 @@ const n = fork(fixtures.path('child-process-spawn-node.js'), args); assert.deepStrictEqual(args, ['foo', 'bar']); -n.on('message', (m) => { +n.on('message', common.mustCall((m) => { debug('PARENT got message:', m); assert.ok(m.foo); -}); +})); // https://github.com/joyent/node/issues/2355 - JSON.stringify(undefined) // returns "undefined" but JSON.parse() cannot parse that... diff --git a/test/parallel/test-child-process-http-socket-leak.js b/test/parallel/test-child-process-http-socket-leak.js index cae4b051bc2b35..285411ddb137b1 100644 --- a/test/parallel/test-child-process-http-socket-leak.js +++ b/test/parallel/test-child-process-http-socket-leak.js @@ -39,7 +39,7 @@ const server = http.createServer(common.mustCall((req, res) => { server.listen(0, common.mustCall(() => { child = fork(__filename, [ 'child' ]); - child.once('message', (msg) => { + child.once('message', common.mustCall((msg) => { assert.strictEqual(msg, 'ready'); const req = http.request({ port: server.address().port, @@ -53,5 +53,5 @@ server.listen(0, common.mustCall(() => { })); req.end(); - }); + })); })); diff --git a/test/parallel/test-child-process-kill.js b/test/parallel/test-child-process-kill.js index 4d045feba434fb..d143b21a8681d1 100644 --- a/test/parallel/test-child-process-kill.js +++ b/test/parallel/test-child-process-kill.js @@ -67,10 +67,10 @@ process.stdout.write('x');`; const checkProcess = spawn(process.execPath, ['-e', code]); -checkProcess.on('exit', (code, signal) => { +checkProcess.on('exit', common.mustCall((code, signal) => { assert.strictEqual(code, 0); assert.strictEqual(signal, null); -}); +})); checkProcess.stdout.on('data', common.mustCall((chunk) => { assert.strictEqual(chunk.toString(), 'x'); diff --git a/test/parallel/test-child-process-send-keep-open.js b/test/parallel/test-child-process-send-keep-open.js index 54169dc1885f66..62c862e1b43820 100644 --- a/test/parallel/test-child-process-send-keep-open.js +++ b/test/parallel/test-child-process-send-keep-open.js @@ -23,7 +23,7 @@ if (process.argv[2] !== 'child') { assert.strictEqual(signalCode, null); })); - const server = net.createServer((socket) => { + const server = net.createServer(common.mustCall((socket) => { child.on('message', common.mustCall((msg) => { assert.strictEqual(msg, 'child_done'); socket.end('parent', () => { @@ -33,7 +33,7 @@ if (process.argv[2] !== 'child') { })); child.send('socket', socket, { keepOpen: true }, common.mustSucceed()); - }); + })); server.listen(0, () => { const socket = net.connect(server.address().port, common.localhostIPv4); diff --git a/test/parallel/test-child-process-send-returns-boolean.js b/test/parallel/test-child-process-send-returns-boolean.js index 3d2e913dc265a6..d50a3d84594be0 100644 --- a/test/parallel/test-child-process-send-returns-boolean.js +++ b/test/parallel/test-child-process-send-returns-boolean.js @@ -28,7 +28,7 @@ const subScript = fixtures.path('child-process-persistent.js'); const spawnOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }; const s = spawn(process.execPath, [subScript], spawnOptions); - const server = net.createServer(common.mustNotCall()).listen(0, () => { + const server = net.createServer(common.mustNotCall()).listen(0, common.mustCall(() => { const handle = server._handle; // Sending a handle and not giving the tickQueue time to acknowledge should @@ -42,8 +42,7 @@ const subScript = fixtures.path('child-process-persistent.js'); // The backlog should now be indicate to backoff. const rv3 = s.send('three', assert.ifError); assert.strictEqual(rv3, false); - const rv4 = s.send('four', (err) => { - assert.ifError(err); + const rv4 = s.send('four', common.mustSucceed(() => { // `send` queue should have been drained. const rv5 = s.send('5', handle, assert.ifError); assert.strictEqual(rv5, true); @@ -52,7 +51,7 @@ const subScript = fixtures.path('child-process-persistent.js'); s.kill(); handle.close(); server.close(); - }); + })); assert.strictEqual(rv4, false); - }); + })); } diff --git a/test/parallel/test-child-process-server-close.js b/test/parallel/test-child-process-server-close.js index 832cf970178afa..65a4ebb87c1cad 100644 --- a/test/parallel/test-child-process-server-close.js +++ b/test/parallel/test-child-process-server-close.js @@ -24,17 +24,17 @@ if (process.argv[2] !== 'child') { } // Child -const server = net.createServer((conn) => { +const server = net.createServer(common.mustCall((conn) => { spawn(process.execPath, ['-v'], { stdio: ['ignore', conn, 'ignore'] }).on('close', common.mustCall(() => { conn.end(); })); -}).listen(common.PIPE, () => { +})).listen(common.PIPE, common.mustCall(() => { const client = net.connect(common.PIPE, common.mustCall()); client.once('data', () => { client.end(() => { server.close(); }); }); -}); +})); diff --git a/test/parallel/test-child-process-spawnsync-args.js b/test/parallel/test-child-process-spawnsync-args.js index 4e65b22f6e4587..997852cae11870 100644 --- a/test/parallel/test-child-process-spawnsync-args.js +++ b/test/parallel/test-child-process-spawnsync-args.js @@ -32,7 +32,7 @@ const testCases = [ const expectedResult = tmpdir.path.trim().toLowerCase(); -const results = testCases.map((testCase) => { +const results = testCases.map(common.mustCallAtLeast((testCase) => { const { stdout, stderr, error } = spawnSync( command, testCase, @@ -43,6 +43,6 @@ const results = testCases.map((testCase) => { assert.deepStrictEqual(stderr, Buffer.alloc(0)); return stdout.toString().trim().toLowerCase(); -}); +})); assert.deepStrictEqual([...new Set(results)], [expectedResult]); diff --git a/test/parallel/test-child-process-spawnsync-kill-signal.js b/test/parallel/test-child-process-spawnsync-kill-signal.js index 6d14f24724bb2b..c3073a09c476f4 100644 --- a/test/parallel/test-child-process-spawnsync-kill-signal.js +++ b/test/parallel/test-child-process-spawnsync-kill-signal.js @@ -35,18 +35,18 @@ if (process.argv[2] === 'child') { // Verify that the default kill signal is SIGTERM. { - const child = spawn(undefined, (opts) => { + const child = spawn(undefined, common.mustCall((opts) => { assert.strictEqual(opts.killSignal, undefined); - }); + })); assert.strictEqual(child.signal, 'SIGTERM'); } // Verify that a string signal name is handled properly. { - const child = spawn('SIGKILL', (opts) => { + const child = spawn('SIGKILL', common.mustCall((opts) => { assert.strictEqual(opts.killSignal, SIGKILL); - }); + })); assert.strictEqual(child.signal, 'SIGKILL'); } @@ -55,9 +55,9 @@ if (process.argv[2] === 'child') { { assert.strictEqual(typeof SIGKILL, 'number'); - const child = spawn(SIGKILL, (opts) => { + const child = spawn(SIGKILL, common.mustCall((opts) => { assert.strictEqual(opts.killSignal, SIGKILL); - }); + })); assert.strictEqual(child.signal, 'SIGKILL'); } diff --git a/test/parallel/test-child-process-stdio-inherit.js b/test/parallel/test-child-process-stdio-inherit.js index 034a0770168bc9..73a5bc802c7660 100644 --- a/test/parallel/test-child-process-stdio-inherit.js +++ b/test/parallel/test-child-process-stdio-inherit.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const spawn = require('child_process').spawn; @@ -42,12 +42,12 @@ function grandparent() { child.stdin.end(input); - child.on('close', function(code, signal) { + child.on('close', common.mustCall((code, signal) => { assert.strictEqual(code, 0); assert.strictEqual(signal, null); // 'cat' on windows adds a \r\n at the end. assert.strictEqual(output.trim(), input.trim()); - }); + })); } function parent() { diff --git a/test/parallel/test-cli-node-options.js b/test/parallel/test-cli-node-options.js index 53bca572c3405c..3eee6023025f85 100644 --- a/test/parallel/test-cli-node-options.js +++ b/test/parallel/test-cli-node-options.js @@ -112,7 +112,7 @@ function expect( if (typeof want === 'string') want = new RegExp(want); - const test = (type) => common.mustCall((err, stdout) => { + const test = common.mustCallAtLeast((type) => common.mustCall((err, stdout) => { const o = JSON.stringify(opt); if (wantsError) { assert.ok(err, `${type}: expected error for ${o}`); @@ -125,7 +125,7 @@ function expect( assert.fail( `${type}: for ${o}, failed to find ${want} in: <\n${stdout}\n>` ); - }); + })); exec(process.execPath, argv, opts, test('child process')); if (testWorker) diff --git a/test/parallel/test-cli-node-print-help.js b/test/parallel/test-cli-node-print-help.js index 4075a6c9b609b2..f42129eb133026 100644 --- a/test/parallel/test-cli-node-print-help.js +++ b/test/parallel/test-cli-node-print-help.js @@ -40,15 +40,15 @@ function validateNodePrintHelp() { function testForSubstring(options) { if (options.compileConstant) { - options.flags.forEach((flag) => { - assert.strictEqual(stdOut.indexOf(flag) !== -1, true, - `Missing flag ${flag} in ${stdOut}`); - }); + for (const flag of options.flags) { + assert.notStrictEqual(stdOut.indexOf(flag), -1, + `Missing flag ${flag} in ${stdOut}`); + } } else { - options.flags.forEach((flag) => { + for (const flag of options.flags) { assert.strictEqual(stdOut.indexOf(flag), -1, `Unexpected flag ${flag} in ${stdOut}`); - }); + } } } diff --git a/test/parallel/test-cluster-accept-fail.js b/test/parallel/test-cluster-accept-fail.js index 29d57783a9d11f..f35379afab4d1a 100644 --- a/test/parallel/test-cluster-accept-fail.js +++ b/test/parallel/test-cluster-accept-fail.js @@ -7,12 +7,12 @@ const cluster = require('cluster'); const rr = require('internal/cluster/round_robin_handle'); if (cluster.isPrimary) { - const distribute = rr.prototype.distribute; - rr.prototype.distribute = function(err, handle) { + const originalDistribute = rr.prototype.distribute; + rr.prototype.distribute = common.mustCall(function distribute(err, handle) { assert.strictEqual(err, 0); handle.close(); - distribute.call(this, -1, undefined); - }; + originalDistribute.call(this, -1, undefined); + }); cluster.schedulingPolicy = cluster.SCHED_RR; cluster.fork(); } else { diff --git a/test/parallel/test-cluster-basic.js b/test/parallel/test-cluster-basic.js index 306b4d7f58788d..12b531a1110fd1 100644 --- a/test/parallel/test-cluster-basic.js +++ b/test/parallel/test-cluster-basic.js @@ -92,7 +92,7 @@ if (cluster.isWorker) { const stateNames = Object.keys(checks.worker.states); // Check events, states, and emit arguments - forEach(checks.cluster.events, (bool, name, index) => { + forEach(checks.cluster.events, common.mustCallAtLeast((bool, name, index) => { // Listen on event cluster.on(name, common.mustCall(function(/* worker */) { @@ -107,7 +107,7 @@ if (cluster.isWorker) { const state = stateNames[index]; checks.worker.states[state] = (state === worker.state); })); - }); + })); // Kill worker when listening cluster.on('listening', common.mustCall(() => { @@ -124,7 +124,7 @@ if (cluster.isWorker) { 'the worker is not a instance of the Worker constructor'); // Check event - forEach(checks.worker.events, function(bool, name, index) { + forEach(checks.worker.events, common.mustCallAtLeast((bool, name, index) => { worker.on(name, common.mustCall(function() { // Set event checks.worker.events[name] = true; @@ -157,7 +157,7 @@ if (cluster.isWorker) { break; } })); - }); + })); // Check all values process.once('exit', () => { diff --git a/test/parallel/test-cluster-concurrent-disconnect.js b/test/parallel/test-cluster-concurrent-disconnect.js index b754fa221a0dcd..56707d3cf2fa74 100644 --- a/test/parallel/test-cluster-concurrent-disconnect.js +++ b/test/parallel/test-cluster-concurrent-disconnect.js @@ -24,14 +24,14 @@ if (cluster.isPrimary) { // These errors can occur due to the nature of the test, we might be trying // to send messages when the worker is disconnecting. - worker.on('error', (err) => { + worker.on('error', common.mustCallAtLeast((err) => { assert.strictEqual(err.syscall, 'write'); if (common.isMacOS) { assert(['EPIPE', 'ENOTCONN'].includes(err.code), err); } else { assert(['EPIPE', 'ECONNRESET'].includes(err.code), err); } - }); + }, 0)); worker.once('disconnect', common.mustCall(() => { for (const worker of workers) diff --git a/test/parallel/test-cluster-disconnect-exitedAfterDisconnect-race.js b/test/parallel/test-cluster-disconnect-exitedAfterDisconnect-race.js index f1a8dea0a9a6df..81bdc0459d0b12 100644 --- a/test/parallel/test-cluster-disconnect-exitedAfterDisconnect-race.js +++ b/test/parallel/test-cluster-disconnect-exitedAfterDisconnect-race.js @@ -8,9 +8,9 @@ const assert = require('assert'); const cluster = require('cluster'); if (cluster.isPrimary) { - cluster.on('exit', (worker, code) => { + cluster.on('exit', common.mustCall((worker, code) => { assert.strictEqual(code, 0, `worker exited with code: ${code}, expected 0`); - }); + })); return cluster.fork(); } diff --git a/test/parallel/test-cluster-disconnect.js b/test/parallel/test-cluster-disconnect.js index 240bb972fa359e..01a2167dbc2ee1 100644 --- a/test/parallel/test-cluster-disconnect.js +++ b/test/parallel/test-cluster-disconnect.js @@ -38,8 +38,8 @@ if (cluster.isWorker) { const serverPorts = new Set(); // Test a single TCP server - const testConnection = (port, cb) => { - const socket = net.connect(port, '127.0.0.1', () => { + const testConnection = common.mustCallAtLeast((port, cb) => { + const socket = net.connect(port, '127.0.0.1', common.mustCall(() => { // buffer result let result = ''; socket.on('data', (chunk) => { result += chunk; }); @@ -49,27 +49,27 @@ if (cluster.isWorker) { cb(result === 'echo'); serverPorts.delete(port); })); - }); - }; + })); + }); // Test both servers created in the cluster - const testCluster = (cb) => { + const testCluster = common.mustCallAtLeast((cb) => { let done = 0; const portsArray = Array.from(serverPorts); for (let i = 0; i < servers; i++) { - testConnection(portsArray[i], (success) => { + testConnection(portsArray[i], common.mustCall((success) => { assert.ok(success); done += 1; if (done === servers) { cb(); } - }); + })); } - }; + }); // Start two workers and execute callback when both is listening - const startCluster = (cb) => { + const startCluster = common.mustCallAtLeast((cb) => { const workers = 8; let online = 0; @@ -83,9 +83,9 @@ if (cluster.isWorker) { } }, servers)); } - }; + }); - const test = (again) => { + const test = common.mustCall((again) => { // 1. start cluster startCluster(common.mustCall(() => { // 2. test cluster @@ -99,7 +99,7 @@ if (cluster.isWorker) { })); })); })); - }; + }, 2); test(true); } diff --git a/test/parallel/test-cluster-eaddrinuse.js b/test/parallel/test-cluster-eaddrinuse.js index f74d4ab7ec2eb9..cbab4aa5262c70 100644 --- a/test/parallel/test-cluster-eaddrinuse.js +++ b/test/parallel/test-cluster-eaddrinuse.js @@ -49,13 +49,13 @@ if (id === 'undefined') { server.on('error', common.mustCall(function(e) { assert(e.code, 'EADDRINUSE'); process.send('stop-listening'); - process.once('message', function(msg) { + process.once('message', common.mustCall((msg) => { if (msg !== 'stopped-listening') return; server = net.createServer(common.mustNotCall()); server.listen(port, common.mustCall(function() { server.close(); })); - }); + })); })); } else { assert(0); // Bad argument. diff --git a/test/parallel/test-cluster-fork-stdio.js b/test/parallel/test-cluster-fork-stdio.js index 263c2ba8024f25..37708c2faaf9b5 100644 --- a/test/parallel/test-cluster-fork-stdio.js +++ b/test/parallel/test-cluster-fork-stdio.js @@ -33,8 +33,8 @@ if (cluster.isPrimary) { const pipe = new net.Socket({ fd: 4 }); pipe.unref(); - pipe.on('data', (data) => { + pipe.on('data', common.mustCallAtLeast((data) => { assert.ok(data instanceof Buffer); pipe.write(data); - }); + })); } diff --git a/test/parallel/test-cluster-fork-windowsHide.js b/test/parallel/test-cluster-fork-windowsHide.js index 2b90713ceb0a74..b74a7606e9700a 100644 --- a/test/parallel/test-cluster-fork-windowsHide.js +++ b/test/parallel/test-cluster-fork-windowsHide.js @@ -30,11 +30,11 @@ if (!process.argv[2]) { }) }; - primary.on('message', (msg) => { + primary.on('message', common.mustCallAtLeast((msg) => { const handler = messageHandlers[msg.type]; assert.ok(handler); handler(msg); - }); + })); primary.on('exit', common.mustCall((code, signal) => { assert.strictEqual(code, 0); diff --git a/test/parallel/test-cluster-message.js b/test/parallel/test-cluster-message.js index 35d6c975b28b5f..49b5793187b53f 100644 --- a/test/parallel/test-cluster-message.js +++ b/test/parallel/test-cluster-message.js @@ -103,13 +103,13 @@ if (cluster.isWorker) { worker.on('message', function(message) { check('primary', message === 'message from worker'); }); - cluster.on('message', function(worker_, message) { + cluster.on('message', common.mustCall((worker_, message) => { assert.strictEqual(worker_, worker); check('global', message === 'message from worker'); - }); + })); // When a TCP server is listening in the worker connect to it - worker.on('listening', function(address) { + worker.on('listening', common.mustCall((address) => { client = net.connect(address.port, function() { // Send message to worker. @@ -135,12 +135,12 @@ if (cluster.isWorker) { worker.on('exit', common.mustCall(function() { process.exit(0); })); - }); + })); process.once('exit', function() { - forEach(checks, function(check, type) { + forEach(checks, common.mustCallAtLeast((check, type) => { assert.ok(check.receive, `The ${type} did not receive any message`); assert.ok(check.correct, `The ${type} did not get the correct message`); - }); + })); }); } diff --git a/test/parallel/test-cluster-net-send.js b/test/parallel/test-cluster-net-send.js index f6b735db997d8a..72b88dd1f87fbd 100644 --- a/test/parallel/test-cluster-net-send.js +++ b/test/parallel/test-cluster-net-send.js @@ -36,10 +36,10 @@ if (process.argv[2] !== 'child') { assert.ok(handle); worker.send('got'); - handle.on('data', function(data) { + handle.on('data', common.mustCall((data) => { called = true; assert.strictEqual(data.toString(), 'hello'); - }); + })); handle.on('end', function() { worker.kill(); @@ -59,13 +59,13 @@ if (process.argv[2] !== 'child') { process.send('handle', socket); } - const server = net.createServer(function(c) { + const server = net.createServer(common.mustCall((c) => { process.once('message', common.mustCall(function(msg) { assert.strictEqual(msg, 'got'); c.end('hello'); })); socketConnected(); - }); + })); server.listen(0, function() { socket = net.connect(server.address().port, '127.0.0.1', socketConnected); diff --git a/test/parallel/test-cluster-rr-handle-keep-loop-alive.js b/test/parallel/test-cluster-rr-handle-keep-loop-alive.js index 0b18408a192ba1..c31bbe5cbcb9a5 100644 --- a/test/parallel/test-cluster-rr-handle-keep-loop-alive.js +++ b/test/parallel/test-cluster-rr-handle-keep-loop-alive.js @@ -13,10 +13,10 @@ if (cluster.isPrimary) { worker.on('exit', () => { exited = true; }); - setTimeout(() => { + setTimeout(common.mustCall(() => { assert.ok(!exited); worker.kill(); - }, 3000); + }), 3000); } else { const server = net.createServer(common.mustNotCall()); server.listen(0, common.mustCall(() => process.channel.unref())); diff --git a/test/parallel/test-cluster-send-deadlock.js b/test/parallel/test-cluster-send-deadlock.js index 8ddc40c2529441..076e903a4060b0 100644 --- a/test/parallel/test-cluster-send-deadlock.js +++ b/test/parallel/test-cluster-send-deadlock.js @@ -23,18 +23,18 @@ // Testing mutual send of handles: from primary to worker, and from worker to // primary. -require('../common'); +const common = require('../common'); const assert = require('assert'); const cluster = require('cluster'); const net = require('net'); if (cluster.isPrimary) { const worker = cluster.fork(); - worker.on('exit', (code, signal) => { + worker.on('exit', common.mustCall((code, signal) => { assert.strictEqual(code, 0, `Worker exited with an error code: ${code}`); assert(!signal, `Worker exited by a signal: ${signal}`); server.close(); - }); + })); const server = net.createServer((socket) => { worker.send('handle', socket); diff --git a/test/parallel/test-cluster-send-handle-twice.js b/test/parallel/test-cluster-send-handle-twice.js index c413f6f82bffca..7064a9c7e18d20 100644 --- a/test/parallel/test-cluster-send-handle-twice.js +++ b/test/parallel/test-cluster-send-handle-twice.js @@ -45,14 +45,14 @@ if (cluster.isPrimary) { process.send('send-handle-2', socket); })); - server.listen(0, function() { + server.listen(0, common.mustCall(() => { const client = net.connect({ host: 'localhost', port: server.address().port }); client.on('close', common.mustCall(() => { cluster.worker.disconnect(); })); client.on('connect', () => { client.end(); }); - }).on('error', function(e) { + })).on('error', function(e) { console.error(e); assert.fail('server.listen failed'); }); diff --git a/test/parallel/test-cluster-server-restart-none.js b/test/parallel/test-cluster-server-restart-none.js index fdc3fa5a36a718..b8fca694904e1e 100644 --- a/test/parallel/test-cluster-server-restart-none.js +++ b/test/parallel/test-cluster-server-restart-none.js @@ -9,7 +9,7 @@ if (cluster.isPrimary) { const worker1 = cluster.fork(); worker1.on('listening', common.mustCall(() => { const worker2 = cluster.fork(); - worker2.on('exit', (code, signal) => { + worker2.on('exit', common.mustCall((code, signal) => { assert.strictEqual(code, 0, 'worker2 did not exit normally. ' + `exited with code ${code}`); @@ -17,7 +17,7 @@ if (cluster.isPrimary) { 'worker2 did not exit normally. ' + `exited with signal ${signal}`); worker1.disconnect(); - }); + })); })); worker1.on('exit', common.mustCall((code, signal) => { @@ -33,13 +33,13 @@ if (cluster.isPrimary) { const server = net.createServer(); server.listen(0, common.mustCall(() => { if (cluster.worker.id === 2) { - server.close(() => { + server.close(common.mustCall(() => { server.listen(0, common.mustCall(() => { server.close(() => { process.disconnect(); }); })); - }); + })); } })); } diff --git a/test/parallel/test-cluster-server-restart-rr.js b/test/parallel/test-cluster-server-restart-rr.js index 446a7de1549072..9fbbf63f5b711c 100644 --- a/test/parallel/test-cluster-server-restart-rr.js +++ b/test/parallel/test-cluster-server-restart-rr.js @@ -9,7 +9,7 @@ if (cluster.isPrimary) { const worker1 = cluster.fork(); worker1.on('listening', common.mustCall(() => { const worker2 = cluster.fork(); - worker2.on('exit', (code, signal) => { + worker2.on('exit', common.mustCall((code, signal) => { assert.strictEqual( code, 0, @@ -21,7 +21,7 @@ if (cluster.isPrimary) { `worker${worker2.id} did not exit normally. Exit with signal: ${signal}` ); worker1.disconnect(); - }); + })); })); worker1.on('exit', common.mustCall((code, signal) => { @@ -41,13 +41,13 @@ if (cluster.isPrimary) { const server = net.createServer(); server.listen(0, common.mustCall(() => { if (cluster.worker.id === 2) { - server.close(() => { + server.close(common.mustCall(() => { server.listen(0, common.mustCall(() => { server.close(() => { process.disconnect(); }); })); - }); + })); } })); } diff --git a/test/parallel/test-cluster-shared-leak.js b/test/parallel/test-cluster-shared-leak.js index 67c11ea32145e0..48c07c7cc04df5 100644 --- a/test/parallel/test-cluster-shared-leak.js +++ b/test/parallel/test-cluster-shared-leak.js @@ -15,7 +15,7 @@ if (cluster.isPrimary) { const worker1 = cluster.fork(); worker1.on('listening', common.mustCall(function(address) { worker2 = cluster.fork(); - worker2.on('online', function() { + worker2.on('online', common.mustCall(() => { conn = net.connect(address.port, common.mustCall(function() { worker1.disconnect(); worker2.disconnect(); @@ -25,16 +25,16 @@ if (cluster.isPrimary) { if (e.code !== 'ECONNRESET') throw e; }); - }); + })); })); - cluster.on('exit', function(worker, exitCode, signalCode) { + cluster.on('exit', common.mustCall((worker, exitCode, signalCode) => { assert(worker === worker1 || worker === worker2); assert.strictEqual(exitCode, 0); assert.strictEqual(signalCode, null); if (Object.keys(cluster.workers).length === 0) conn.destroy(); - }); + }, 2)); return; } diff --git a/test/parallel/test-cluster-worker-events.js b/test/parallel/test-cluster-worker-events.js index cbb14405c1f363..d83068de026e93 100644 --- a/test/parallel/test-cluster-worker-events.js +++ b/test/parallel/test-cluster-worker-events.js @@ -51,7 +51,7 @@ let sawWorker; const messages = []; -const check = (m) => { +const check = common.mustCallAtLeast((m) => { messages.push(m); if (messages.length < 2) return; @@ -64,7 +64,7 @@ const check = (m) => { })); process.emit('error', 'HI'); -}; +}); process.on('message', (m) => { assert(!sawProcess); diff --git a/test/parallel/test-console.js b/test/parallel/test-console.js index bc08ba395e787e..7aab6414cd23ce 100644 --- a/test/parallel/test-console.js +++ b/test/parallel/test-console.js @@ -179,11 +179,11 @@ console.timeEnd(NaN); // Make sure calling time twice without timeEnd doesn't reset the timer. console.time('test'); const time = console._times.get('test'); -setTimeout(() => { +setTimeout(common.mustCall(() => { console.time('test'); assert.deepStrictEqual(console._times.get('test'), time); console.timeEnd('test'); -}, 1); +}), 1); console.time('log1'); console.timeLog('log1'); diff --git a/test/parallel/test-cppheap-stats.js b/test/parallel/test-cppheap-stats.js index cbc6dd4981cd7f..b77847602aa828 100644 --- a/test/parallel/test-cppheap-stats.js +++ b/test/parallel/test-cppheap-stats.js @@ -40,7 +40,7 @@ const expectedSpaceKeys = [ 'free_list_stats', ].sort(); -heapStatsDetailed.space_statistics.forEach((space) => { +for (const space of heapStatsDetailed.space_statistics) { const actualSpaceKeys = Object.keys(space).sort(); assert.deepStrictEqual(actualSpaceKeys, expectedSpaceKeys); assert.strictEqual(typeof space.name, 'string'); @@ -49,7 +49,7 @@ heapStatsDetailed.space_statistics.forEach((space) => { assert.strictEqual(typeof space.used_size_bytes, 'number'); assert.strictEqual(Array.isArray(space.page_stats), true); assert.strictEqual(typeof space.free_list_stats, 'object'); -}); +} // Check page statistics array const expectedPageKeys = [ @@ -59,46 +59,46 @@ const expectedPageKeys = [ 'object_statistics', ].sort(); -heapStatsDetailed.space_statistics.forEach((space) => { - space.page_stats.forEach((page) => { +for (const space of heapStatsDetailed.space_statistics) { + for (const page of space.page_stats) { const actualPageKeys = Object.keys(page).sort(); assert.deepStrictEqual(actualPageKeys, expectedPageKeys); assert.strictEqual(typeof page.committed_size_bytes, 'number'); assert.strictEqual(typeof page.resident_size_bytes, 'number'); assert.strictEqual(typeof page.used_size_bytes, 'number'); assert.strictEqual(Array.isArray(page.object_statistics), true); - }); -}); + } +} // Check free list statistics const expectedFreeListKeys = ['bucket_size', 'free_count', 'free_size'].sort(); -heapStatsDetailed.space_statistics.forEach((space) => { +for (const space of heapStatsDetailed.space_statistics) { const actualFreeListKeys = Object.keys(space.free_list_stats).sort(); assert.deepStrictEqual(actualFreeListKeys, expectedFreeListKeys); assert.strictEqual(Array.isArray(space.free_list_stats.bucket_size), true); assert.strictEqual(Array.isArray(space.free_list_stats.free_count), true); assert.strictEqual(Array.isArray(space.free_list_stats.free_size), true); -}); +} // Check object statistics const expectedObjectStatsKeys = ['allocated_bytes', 'object_count'].sort(); -heapStatsDetailed.space_statistics.forEach((space) => { - space.page_stats.forEach((page) => { - page.object_statistics.forEach((objectStats) => { +for (const space of heapStatsDetailed.space_statistics) { + for (const page of space.page_stats) { + for (const objectStats of page.object_statistics) { const actualObjectStatsKeys = Object.keys(objectStats).sort(); assert.deepStrictEqual(actualObjectStatsKeys, expectedObjectStatsKeys); assert.strictEqual(typeof objectStats.allocated_bytes, 'number'); assert.strictEqual(typeof objectStats.object_count, 'number'); - }); - }); -}); + } + } +} // Check type names -heapStatsDetailed.type_names.forEach((typeName) => { +for (const typeName of heapStatsDetailed.type_names) { assert.strictEqual(typeof typeName, 'string'); -}); +} // Brief heap statistics const heapStatsBrief = v8.getCppHeapStatistics('brief'); diff --git a/test/parallel/test-crypto-op-during-process-exit.js b/test/parallel/test-crypto-op-during-process-exit.js index 28858dd1b57e49..e48b38caedd996 100644 --- a/test/parallel/test-crypto-op-during-process-exit.js +++ b/test/parallel/test-crypto-op-during-process-exit.js @@ -1,6 +1,7 @@ 'use strict'; const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); } +const assert = require('assert'); const { generateKeyPair } = require('crypto'); if (common.isWindows) { @@ -20,6 +21,9 @@ generateKeyPair('rsa', { type: 'pkcs1', format: 'pem' } -}, common.mustNotCall()); +}, (err/* , publicKey, privateKey */) => { + // eslint-disable-next-line node-core/must-call-assert + assert.ifError(err); +}); setTimeout(() => process.exit(), common.platformTimeout(10)); diff --git a/test/parallel/test-crypto-pqc-keygen-ml-dsa.js b/test/parallel/test-crypto-pqc-keygen-ml-dsa.js index 9fa0a0ffef5d72..abad2c15cf01d1 100644 --- a/test/parallel/test-crypto-pqc-keygen-ml-dsa.js +++ b/test/parallel/test-crypto-pqc-keygen-ml-dsa.js @@ -42,6 +42,7 @@ if (!hasOpenSSL(3, 5)) { } for (const [publicKeyEncoding, validate] of [ + /* eslint-disable node-core/must-call-assert */ [undefined, (publicKey) => { assert.strictEqual(publicKey.type, 'public'); assert.strictEqual(publicKey.asymmetricKeyType, asymmetricKeyType); @@ -50,10 +51,12 @@ if (!hasOpenSSL(3, 5)) { [{ format: 'jwk' }, (publicKey) => assertPublicJwk(publicKey)], [{ format: 'pem', type: 'spki' }, (publicKey) => assert.strictEqual(typeof publicKey, 'string')], [{ format: 'der', type: 'spki' }, (publicKey) => assert.strictEqual(Buffer.isBuffer(publicKey), true)], + /* eslint-enable node-core/must-call-assert */ ]) { generateKeyPair(asymmetricKeyType, { publicKeyEncoding }, common.mustSucceed(validate)); } for (const [privateKeyEncoding, validate] of [ + /* eslint-disable node-core/must-call-assert */ [undefined, (_, privateKey) => { assert.strictEqual(privateKey.type, 'private'); assert.strictEqual(privateKey.asymmetricKeyType, asymmetricKeyType); @@ -62,6 +65,7 @@ if (!hasOpenSSL(3, 5)) { [{ format: 'jwk' }, (_, privateKey) => assertPrivateJwk(privateKey)], [{ format: 'pem', type: 'pkcs8' }, (_, privateKey) => assert.strictEqual(typeof privateKey, 'string')], [{ format: 'der', type: 'pkcs8' }, (_, privateKey) => assert.strictEqual(Buffer.isBuffer(privateKey), true)], + /* eslint-enable node-core/must-call-assert */ ]) { generateKeyPair(asymmetricKeyType, { privateKeyEncoding }, common.mustSucceed(validate)); } diff --git a/test/parallel/test-crypto-pqc-keygen-ml-kem.js b/test/parallel/test-crypto-pqc-keygen-ml-kem.js index fbbbc4f8de9663..adb5fcb56ce6ef 100644 --- a/test/parallel/test-crypto-pqc-keygen-ml-kem.js +++ b/test/parallel/test-crypto-pqc-keygen-ml-kem.js @@ -21,6 +21,7 @@ if (!hasOpenSSL(3, 5)) { } else { for (const asymmetricKeyType of ['ml-kem-512', 'ml-kem-768', 'ml-kem-1024']) { for (const [publicKeyEncoding, validate] of [ + /* eslint-disable node-core/must-call-assert */ [undefined, (publicKey) => { assert.strictEqual(publicKey.type, 'public'); assert.strictEqual(publicKey.asymmetricKeyType, asymmetricKeyType); @@ -28,10 +29,12 @@ if (!hasOpenSSL(3, 5)) { }], [{ format: 'pem', type: 'spki' }, (publicKey) => assert.strictEqual(typeof publicKey, 'string')], [{ format: 'der', type: 'spki' }, (publicKey) => assert.strictEqual(Buffer.isBuffer(publicKey), true)], + /* eslint-enable node-core/must-call-assert */ ]) { generateKeyPair(asymmetricKeyType, { publicKeyEncoding }, common.mustSucceed(validate)); } for (const [privateKeyEncoding, validate] of [ + /* eslint-disable node-core/must-call-assert */ [undefined, (_, privateKey) => { assert.strictEqual(privateKey.type, 'private'); assert.strictEqual(privateKey.asymmetricKeyType, asymmetricKeyType); @@ -39,6 +42,7 @@ if (!hasOpenSSL(3, 5)) { }], [{ format: 'pem', type: 'pkcs8' }, (_, privateKey) => assert.strictEqual(typeof privateKey, 'string')], [{ format: 'der', type: 'pkcs8' }, (_, privateKey) => assert.strictEqual(Buffer.isBuffer(privateKey), true)], + /* eslint-enable node-core/must-call-assert */ ]) { generateKeyPair(asymmetricKeyType, { privateKeyEncoding }, common.mustSucceed(validate)); } diff --git a/test/parallel/test-crypto-pqc-keygen-slh-dsa.js b/test/parallel/test-crypto-pqc-keygen-slh-dsa.js index 78dde3bea4775e..6b741e37f0cc11 100644 --- a/test/parallel/test-crypto-pqc-keygen-slh-dsa.js +++ b/test/parallel/test-crypto-pqc-keygen-slh-dsa.js @@ -29,6 +29,7 @@ if (!hasOpenSSL(3, 5)) { 'slh-dsa-shake-192f', 'slh-dsa-shake-192s', 'slh-dsa-shake-256f', 'slh-dsa-shake-256s', ]) { for (const [publicKeyEncoding, validate] of [ + /* eslint-disable node-core/must-call-assert */ [undefined, (publicKey) => { assert.strictEqual(publicKey.type, 'public'); assert.strictEqual(publicKey.asymmetricKeyType, asymmetricKeyType); @@ -47,6 +48,7 @@ if (!hasOpenSSL(3, 5)) { }], [{ format: 'pem', type: 'pkcs8' }, (_, privateKey) => assert.strictEqual(typeof privateKey, 'string')], [{ format: 'der', type: 'pkcs8' }, (_, privateKey) => assert.strictEqual(Buffer.isBuffer(privateKey), true)], + /* eslint-enable node-core/must-call-assert */ ]) { generateKeyPair(asymmetricKeyType, { privateKeyEncoding }, common.mustSucceed(validate)); } From c7eac810b32f50e0bbe6049b1b0c7b03c4821b10 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 7 Nov 2025 09:19:42 +0100 Subject: [PATCH 3/3] fixup! test: ensure assertions are reached on more tests --- test/parallel/test-cluster-message.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-cluster-message.js b/test/parallel/test-cluster-message.js index 49b5793187b53f..58d0a88c8921f6 100644 --- a/test/parallel/test-cluster-message.js +++ b/test/parallel/test-cluster-message.js @@ -138,9 +138,9 @@ if (cluster.isWorker) { })); process.once('exit', function() { - forEach(checks, common.mustCallAtLeast((check, type) => { + for (const [type, check] of Object.entries(checks)) { assert.ok(check.receive, `The ${type} did not receive any message`); assert.ok(check.correct, `The ${type} did not get the correct message`); - })); + } }); }