From 426643bad4cc8b6e2a5f6cb5b9dcfbd382997fd6 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 30 Oct 2025 13:07:21 +0100 Subject: [PATCH 1/2] test: ensure assertions are reached on more tests --- test/eslint.config_partial.mjs | 4 + .../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, 287 insertions(+), 288 deletions(-) diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index d19e98a4bf3131..58dbaf0cbfecb3 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -190,6 +190,10 @@ export default [ 'wasm-allocation', '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: 1 }, (_, i) => String.fromCharCode(0x63 + i, 42)).join(',') + }}.{js,mjs,cjs}`, ], rules: { 'node-core/must-call-assert': 'error', 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..dfcd5567f20a4c 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.mustSucceed()); 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 c02f19aff673561034ee1109fbaa980ab42e9f5c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 30 Oct 2025 18:35:30 +0100 Subject: [PATCH 2/2] fixup! test: ensure assertions are reached on more tests --- test/parallel/test-crypto-op-during-process-exit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-crypto-op-during-process-exit.js b/test/parallel/test-crypto-op-during-process-exit.js index dfcd5567f20a4c..28858dd1b57e49 100644 --- a/test/parallel/test-crypto-op-during-process-exit.js +++ b/test/parallel/test-crypto-op-during-process-exit.js @@ -20,6 +20,6 @@ generateKeyPair('rsa', { type: 'pkcs1', format: 'pem' } -}, common.mustSucceed()); +}, common.mustNotCall()); setTimeout(() => process.exit(), common.platformTimeout(10));