From 1e3e91f6f70df2dcb929006da09d237893ac0186 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 21 Nov 2025 19:28:56 +0100 Subject: [PATCH] test: ensure assertions are reached on all tests --- test/eslint.config_partial.mjs | 52 +---- .../output/hooks-with-no-global-test.js | 1 - test/parallel/test-os.js | 28 ++- test/parallel/test-perf-hooks-histogram.js | 111 +++++---- test/parallel/test-performance-gc.js | 4 +- test/parallel/test-performance-global.js | 10 +- test/parallel/test-performance-measure.js | 4 +- .../test-permission-allow-worker-cli.js | 4 +- ...test-permission-fs-internal-module-stat.js | 4 +- test/parallel/test-permission-net-dns.js | 4 +- test/parallel/test-pipe-file-to-http.js | 4 +- test/parallel/test-pipe-stream.js | 8 +- test/parallel/test-pipe-writev.js | 8 +- test/parallel/test-preload.js | 8 +- ...rocess-env-allowed-flags-are-documented.js | 4 +- .../test-process-env-allowed-flags.js | 4 +- test/parallel/test-process-env-sideeffects.js | 5 +- test/parallel/test-process-execve-abort.js | 6 +- test/parallel/test-process-execve-no-args.js | 4 +- test/parallel/test-process-execve-on-exit.js | 4 +- .../test-process-execve-permission-fail.js | 6 +- .../test-process-execve-permission-granted.js | 4 +- test/parallel/test-process-execve-socket.js | 8 +- .../test-process-execve-validation.js | 18 +- .../test-process-execve-worker-threads.js | 4 +- test/parallel/test-process-execve.js | 12 +- .../test-process-exit-code-validation.js | 14 +- test/parallel/test-process-exit-code.js | 10 +- test/parallel/test-process-getgroups.js | 5 +- test/parallel/test-process-raw-debug.js | 4 +- test/parallel/test-process-ref-unref.js | 18 +- ...test-process-threadCpuUsage-main-thread.js | 26 +-- ...t-process-threadCpuUsage-worker-threads.js | 18 +- test/parallel/test-process-uptime.js | 6 +- test/parallel/test-process-warning.js | 8 +- test/parallel/test-promise-hook-on-resolve.js | 8 +- .../test-promises-unhandled-rejections.js | 170 +++++++------- test/parallel/test-punycode.js | 16 +- test/parallel/test-quic-exports.mjs | 50 ++--- .../test-quic-handshake-ipv6-only.mjs | 23 +- test/parallel/test-quic-handshake.mjs | 23 +- ...quic-internal-endpoint-listen-defaults.mjs | 49 ++-- .../test-quic-internal-endpoint-options.mjs | 10 +- ...est-quic-internal-endpoint-stats-state.mjs | 210 +++++++++--------- .../test-quic-internal-setcallbacks.mjs | 4 +- test/parallel/test-quic-test-client.mjs | 6 +- 46 files changed, 469 insertions(+), 538 deletions(-) diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index c972e4de13d5ed..b5fd7fb1adccc2 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -133,6 +133,7 @@ export default [ ], 'node-core/require-common-first': 'error', 'node-core/no-duplicate-requires': 'off', + 'node-core/must-call-assert': 'error', }, }, { @@ -154,56 +155,6 @@ export default [ ], }, }, - { - files: [ - `test/{${[ - 'abort', - 'addons', - 'async-hooks', - 'benchmark', - 'cctest', - 'client-proxy', - 'doctool', - 'embedding', - 'es-module', - 'fixtures', - 'fuzzers', - 'internet', - 'js-native-api', - 'known_issues', - 'message', - 'module-hooks', - 'node-api', - 'nop', - 'overlapped-checker', - 'pseudo-tty', - 'pummel', - 'report', - 'sea', - 'sequential', - 'sqlite', - 'system-ca', - 'test426', - 'testpy', - 'tick-processor', - 'tools', - 'v8-updates', - 'wasi', - '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: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') - },n*,r*,${ - // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…' - Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') - }}.{js,mjs,cjs}`, - ], - rules: { - 'node-core/must-call-assert': 'error', - }, - }, { files: [ 'test/{common,fixtures,wpt}/**/*.{js,mjs,cjs}', @@ -212,6 +163,7 @@ export default [ rules: { 'node-core/required-modules': 'off', 'node-core/require-common-first': 'off', + 'node-core/must-call-assert': 'off', }, }, { diff --git a/test/fixtures/test-runner/output/hooks-with-no-global-test.js b/test/fixtures/test-runner/output/hooks-with-no-global-test.js index abe65ee04456db..02e5d94ce169e3 100644 --- a/test/fixtures/test-runner/output/hooks-with-no-global-test.js +++ b/test/fixtures/test-runner/output/hooks-with-no-global-test.js @@ -9,7 +9,6 @@ before(() => testArr.push('global before')); after(() => { testArr.push('global after'); - // eslint-disable-next-line node-core/must-call-assert assert.deepStrictEqual(testArr, [ 'global before', 'describe before', diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index 3d9fe5c1a60e2e..f15499d692e123 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -27,16 +27,16 @@ const path = require('path'); const { inspect } = require('util'); const is = { - number: (value, key) => { + number: common.mustCallAtLeast((value, key) => { assert(!Number.isNaN(value), `${key} should not be NaN`); assert.strictEqual(typeof value, 'number'); - }, - string: (value) => { assert.strictEqual(typeof value, 'string'); }, - array: (value) => { assert.ok(Array.isArray(value)); }, - object: (value) => { + }), + string: common.mustCallAtLeast((value) => { assert.strictEqual(typeof value, 'string'); }), + array: common.mustCallAtLeast((value) => { assert.ok(Array.isArray(value)); }), + object: common.mustCallAtLeast((value) => { assert.strictEqual(typeof value, 'object'); assert.notStrictEqual(value, null); - } + }), }; process.env.TMPDIR = '/tmpdir'; @@ -181,15 +181,13 @@ const netmaskToCIDRSuffixMap = new Map(Object.entries({ 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff': 128 })); -Object.values(interfaces) - .flat(Infinity) - .map((v) => ({ v, mask: netmaskToCIDRSuffixMap.get(v.netmask) })) - .forEach(({ v, mask }) => { - assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`); - if (mask) { - assert.strictEqual(v.cidr, `${v.address}/${mask}`); - } - }); +for (const v of Object.values(interfaces).flat(Infinity)) { + assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`); + const mask = netmaskToCIDRSuffixMap.get(v.netmask); + if (mask) { + assert.strictEqual(v.cidr, `${v.address}/${mask}`); + } +} const EOL = os.EOL; if (common.isWindows) { diff --git a/test/parallel/test-perf-hooks-histogram.js b/test/parallel/test-perf-hooks-histogram.js index 7d9bd476a76209..e63746d712111e 100644 --- a/test/parallel/test-perf-hooks-histogram.js +++ b/test/parallel/test-perf-hooks-histogram.js @@ -2,12 +2,7 @@ const common = require('../common'); -const { - deepStrictEqual, - ok, - strictEqual, - throws, -} = require('assert'); +const assert = require('assert'); const { createHistogram, @@ -19,64 +14,64 @@ const { inspect } = require('util'); { const h = createHistogram(); - strictEqual(h.min, 9223372036854776000); - strictEqual(h.minBigInt, 9223372036854775807n); - strictEqual(h.max, 0); - strictEqual(h.maxBigInt, 0n); - strictEqual(h.exceeds, 0); - strictEqual(h.exceedsBigInt, 0n); - ok(Number.isNaN(h.mean)); - ok(Number.isNaN(h.stddev)); + assert.strictEqual(h.min, 9223372036854776000); + assert.strictEqual(h.minBigInt, 9223372036854775807n); + assert.strictEqual(h.max, 0); + assert.strictEqual(h.maxBigInt, 0n); + assert.strictEqual(h.exceeds, 0); + assert.strictEqual(h.exceedsBigInt, 0n); + assert.ok(Number.isNaN(h.mean)); + assert.ok(Number.isNaN(h.stddev)); - strictEqual(h.count, 0); - strictEqual(h.countBigInt, 0n); + assert.strictEqual(h.count, 0); + assert.strictEqual(h.countBigInt, 0n); h.record(1); - strictEqual(h.count, 1); - strictEqual(h.countBigInt, 1n); + assert.strictEqual(h.count, 1); + assert.strictEqual(h.countBigInt, 1n); [false, '', {}, undefined, null].forEach((i) => { - throws(() => h.record(i), { + assert.throws(() => h.record(i), { code: 'ERR_INVALID_ARG_TYPE' }); }); [0, Number.MAX_SAFE_INTEGER + 1].forEach((i) => { - throws(() => h.record(i), { + assert.throws(() => h.record(i), { code: 'ERR_OUT_OF_RANGE' }); }); - strictEqual(h.min, 1); - strictEqual(h.minBigInt, 1n); - strictEqual(h.max, 1); - strictEqual(h.maxBigInt, 1n); - strictEqual(h.exceeds, 0); - strictEqual(h.mean, 1); - strictEqual(h.stddev, 0); + assert.strictEqual(h.min, 1); + assert.strictEqual(h.minBigInt, 1n); + assert.strictEqual(h.max, 1); + assert.strictEqual(h.maxBigInt, 1n); + assert.strictEqual(h.exceeds, 0); + assert.strictEqual(h.mean, 1); + assert.strictEqual(h.stddev, 0); - strictEqual(h.percentile(1), 1); - strictEqual(h.percentile(100), 1); + assert.strictEqual(h.percentile(1), 1); + assert.strictEqual(h.percentile(100), 1); - strictEqual(h.percentileBigInt(1), 1n); - strictEqual(h.percentileBigInt(100), 1n); + assert.strictEqual(h.percentileBigInt(1), 1n); + assert.strictEqual(h.percentileBigInt(100), 1n); - deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]])); + assert.deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]])); - deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]])); + assert.deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]])); const mc = new MessageChannel(); mc.port1.onmessage = common.mustCall(({ data }) => { - strictEqual(h.min, 1); - strictEqual(h.max, 1); - strictEqual(h.exceeds, 0); - strictEqual(h.mean, 1); - strictEqual(h.stddev, 0); + assert.strictEqual(h.min, 1); + assert.strictEqual(h.max, 1); + assert.strictEqual(h.exceeds, 0); + assert.strictEqual(h.mean, 1); + assert.strictEqual(h.stddev, 0); data.record(2n); data.recordDelta(); - strictEqual(h.max, 2); + assert.strictEqual(h.max, 2); mc.port1.close(); }); @@ -85,15 +80,15 @@ const { inspect } = require('util'); { const e = monitorEventLoopDelay(); - strictEqual(e.count, 0); + assert.strictEqual(e.count, 0); e.enable(); const mc = new MessageChannel(); mc.port1.onmessage = common.mustCall(({ data }) => { - strictEqual(typeof data.min, 'number'); - ok(data.min > 0); - ok(data.count > 0); - strictEqual(data.disable, undefined); - strictEqual(data.enable, undefined); + assert.strictEqual(typeof data.min, 'number'); + assert.ok(data.min > 0); + assert.ok(data.count > 0); + assert.strictEqual(data.disable, undefined); + assert.strictEqual(data.enable, undefined); mc.port1.close(); }); const interval = setInterval(() => { @@ -112,19 +107,19 @@ const { inspect } = require('util'); histogram = hi; } // The histogram should already be disabled. - strictEqual(histogram.disable(), false); + assert.strictEqual(histogram.disable(), false); } { const h = createHistogram(); - ok(inspect(h, { depth: null }).startsWith('Histogram')); - strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]'); + assert.ok(inspect(h, { depth: null }).startsWith('Histogram')); + assert.strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]'); } { // Tests that RecordableHistogram is impossible to construct manually const h = createHistogram(); - throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' }); + assert.throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' }); } { @@ -133,7 +128,7 @@ const { inspect } = require('util'); 1, null, ].forEach((i) => { - throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' }); + assert.throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' }); }); [ @@ -142,20 +137,20 @@ const { inspect } = require('util'); null, {}, ].forEach((i) => { - throws(() => createHistogram({ lowest: i }), { + assert.throws(() => createHistogram({ lowest: i }), { code: 'ERR_INVALID_ARG_TYPE', }); - throws(() => createHistogram({ highest: i }), { + assert.throws(() => createHistogram({ highest: i }), { code: 'ERR_INVALID_ARG_TYPE', }); - throws(() => createHistogram({ figures: i }), { + assert.throws(() => createHistogram({ figures: i }), { code: 'ERR_INVALID_ARG_TYPE', }); }); // Number greater than 5 is not allowed for (const i of [6, 10]) { - throws(() => createHistogram({ figures: i }), { + assert.throws(() => createHistogram({ figures: i }), { code: 'ERR_OUT_OF_RANGE', }); } @@ -169,12 +164,12 @@ const { inspect } = require('util'); h1.record(1); - strictEqual(h2.count, 0); - strictEqual(h1.count, 1); + assert.strictEqual(h2.count, 0); + assert.strictEqual(h1.count, 1); h2.add(h1); - strictEqual(h2.count, 1); + assert.strictEqual(h2.count, 1); [ 'hello', @@ -182,7 +177,7 @@ const { inspect } = require('util'); false, {}, ].forEach((i) => { - throws(() => h1.add(i), { + assert.throws(() => h1.add(i), { code: 'ERR_INVALID_ARG_TYPE', }); }); diff --git a/test/parallel/test-performance-gc.js b/test/parallel/test-performance-gc.js index 786fe6ff8d56e5..4fad8b5b9ff349 100644 --- a/test/parallel/test-performance-gc.js +++ b/test/parallel/test-performance-gc.js @@ -46,9 +46,9 @@ const kinds = [ // GC should not keep the event loop alive { let didCall = false; - process.on('beforeExit', () => { + process.on('beforeExit', common.mustCall(() => { assert(!didCall); didCall = true; globalThis.gc(); - }); + })); } diff --git a/test/parallel/test-performance-global.js b/test/parallel/test-performance-global.js index 416d017117e9f0..82d339eb9489f4 100644 --- a/test/parallel/test-performance-global.js +++ b/test/parallel/test-performance-global.js @@ -4,15 +4,13 @@ require('../common'); const perf_hooks = require('perf_hooks'); -const { - strictEqual -} = require('assert'); +const assert = require('assert'); const perf = performance; -strictEqual(globalThis.performance, perf_hooks.performance); +assert.strictEqual(globalThis.performance, perf_hooks.performance); performance = undefined; -strictEqual(globalThis.performance, undefined); -strictEqual(typeof perf_hooks.performance.now, 'function'); +assert.strictEqual(globalThis.performance, undefined); +assert.strictEqual(typeof perf_hooks.performance.now, 'function'); // Restore the value of performance for the known globals check performance = perf; diff --git a/test/parallel/test-performance-measure.js b/test/parallel/test-performance-measure.js index 949258f96e1b2d..443dd90ca9bb41 100644 --- a/test/parallel/test-performance-measure.js +++ b/test/parallel/test-performance-measure.js @@ -9,10 +9,10 @@ const ALLOWED_MARGIN = 10; const expected = ['Start to Now', 'A to Now', 'A to B']; const obs = new PerformanceObserver(common.mustCall((items) => { - items.getEntries().forEach(({ name, duration }) => { + for (const { name, duration } of items.getEntries()) { assert.ok(duration > (DELAY - ALLOWED_MARGIN)); assert.strictEqual(expected.shift(), name); - }); + } })); obs.observe({ entryTypes: ['measure'] }); diff --git a/test/parallel/test-permission-allow-worker-cli.js b/test/parallel/test-permission-allow-worker-cli.js index 3dcafea7a3fa35..8ccbc5d4960885 100644 --- a/test/parallel/test-permission-allow-worker-cli.js +++ b/test/parallel/test-permission-allow-worker-cli.js @@ -1,7 +1,7 @@ // Flags: --permission --allow-worker --allow-fs-read=* 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const { isMainThread, Worker } = require('worker_threads'); @@ -18,5 +18,5 @@ if (!isMainThread) { // to spawn unless --allow-worker is sent { // doesNotThrow - new Worker(__filename).on('exit', (code) => assert.strictEqual(code, 0)); + new Worker(__filename).on('exit', common.mustCall((code) => assert.strictEqual(code, 0))); } diff --git a/test/parallel/test-permission-fs-internal-module-stat.js b/test/parallel/test-permission-fs-internal-module-stat.js index db7129e8554f23..f293a07f0096ba 100644 --- a/test/parallel/test-permission-fs-internal-module-stat.js +++ b/test/parallel/test-permission-fs-internal-module-stat.js @@ -3,7 +3,7 @@ const common = require('../common'); const { isMainThread } = require('worker_threads'); -const { strictEqual } = require('assert'); +const assert = require('assert'); if (!isMainThread) { common.skip('This test only works on a main thread'); @@ -19,4 +19,4 @@ const fixtures = require('../common/fixtures'); const blockedFile = fixtures.path('permission', 'deny', 'protected-file.md'); const internalFsBinding = internalBinding('fs'); -strictEqual(internalFsBinding.internalModuleStat(blockedFile), 0); +assert.strictEqual(internalFsBinding.internalModuleStat(blockedFile), 0); diff --git a/test/parallel/test-permission-net-dns.js b/test/parallel/test-permission-net-dns.js index 282f298d0e44b7..13eaecf9279606 100644 --- a/test/parallel/test-permission-net-dns.js +++ b/test/parallel/test-permission-net-dns.js @@ -19,9 +19,9 @@ const { Resolver } = dns.promises; dns.resolve('localhost', common.mustCall((err) => { assert.strictEqual(err.code, 'ERR_ACCESS_DENIED'); })); - dns.resolve('come.on.fhqwhgads.test', (err) => { + dns.resolve('come.on.fhqwhgads.test', common.mustCall((err) => { assert.strictEqual(err.code, 'ERR_ACCESS_DENIED'); - }); + })); dns.promises.resolve('localhost').catch(common.mustCall((err) => { assert.strictEqual(err.code, 'ERR_ACCESS_DENIED'); })); diff --git a/test/parallel/test-pipe-file-to-http.js b/test/parallel/test-pipe-file-to-http.js index ffbab21f71fd9d..2242d81095c563 100644 --- a/test/parallel/test-pipe-file-to-http.js +++ b/test/parallel/test-pipe-file-to-http.js @@ -31,7 +31,7 @@ tmpdir.refresh(); const filename = tmpdir.resolve('big'); let count = 0; -const server = http.createServer((req, res) => { +const server = http.createServer(common.mustCall((req, res) => { assert.strictEqual(req.method, 'POST'); req.pause(); @@ -50,7 +50,7 @@ const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(); }); -}); +})); server.listen(0); server.on('listening', () => { diff --git a/test/parallel/test-pipe-stream.js b/test/parallel/test-pipe-stream.js index c697530c0d5d81..85560ffc98b4dd 100644 --- a/test/parallel/test-pipe-stream.js +++ b/test/parallel/test-pipe-stream.js @@ -26,11 +26,11 @@ function test(clazz, cb) { conn.write('PING', 'utf-8'); }); - conn.on('data', function(data) { + conn.on('data', common.mustCallAtLeast((data) => { assert.strictEqual(data.toString(), 'PONG'); have_pong = true; conn.destroy(); - }); + })); } function pong(conn) { @@ -38,11 +38,11 @@ function test(clazz, cb) { throw err; }); - conn.on('data', function(data) { + conn.on('data', common.mustCall((data) => { assert.strictEqual(data.toString(), 'PING'); have_ping = true; conn.write('PONG', 'utf-8'); - }); + })); conn.on('close', function() { server.close(); diff --git a/test/parallel/test-pipe-writev.js b/test/parallel/test-pipe-writev.js index 5e5b42e6a78d88..ba02dd82b82b40 100644 --- a/test/parallel/test-pipe-writev.js +++ b/test/parallel/test-pipe-writev.js @@ -10,7 +10,7 @@ const net = require('net'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); -const server = net.createServer((connection) => { +const server = net.createServer(common.mustCallAtLeast((connection) => { connection.on('error', (err) => { throw err; }); @@ -22,13 +22,13 @@ const server = net.createServer((connection) => { connection.write('pi'); connection.write('ng'); connection.end(); -}); +})); server.on('error', (err) => { throw err; }); -server.listen(common.PIPE, () => { +server.listen(common.PIPE, common.mustCall(() => { const client = net.connect(common.PIPE); client.on('error', (err) => { @@ -42,4 +42,4 @@ server.listen(common.PIPE, () => { client.on('end', () => { server.close(); }); -}); +})); diff --git a/test/parallel/test-preload.js b/test/parallel/test-preload.js index 24fe181da20423..5861f26dceaf60 100644 --- a/test/parallel/test-preload.js +++ b/test/parallel/test-preload.js @@ -88,10 +88,10 @@ let stdinStdout = ''; stdinProc.stdout.on('data', function(d) { stdinStdout += d; }); -stdinProc.on('close', function(code) { +stdinProc.on('close', common.mustCall((code) => { assert.strictEqual(code, 0); assert.strictEqual(stdinStdout, 'A\nhello\n'); -}); +})); // Test that preload can be used with repl const replProc = childProcess.spawn( @@ -104,7 +104,7 @@ let replStdout = ''; replProc.stdout.on('data', (d) => { replStdout += d; }); -replProc.on('close', function(code) { +replProc.on('close', common.mustCall((code) => { assert.strictEqual(code, 0); const output = [ 'A', @@ -112,7 +112,7 @@ replProc.on('close', function(code) { ]; assert.ok(replStdout.startsWith(output[0])); assert.ok(replStdout.endsWith(output[1])); -}); +})); // Test that preload placement at other points in the cmdline // also test that duplicated preload only gets loaded once diff --git a/test/parallel/test-process-env-allowed-flags-are-documented.js b/test/parallel/test-process-env-allowed-flags-are-documented.js index 338a1506700031..97301c99e17556 100644 --- a/test/parallel/test-process-env-allowed-flags-are-documented.js +++ b/test/parallel/test-process-env-allowed-flags-are-documented.js @@ -14,8 +14,8 @@ const cliText = fs.readFileSync(cliMd, { encoding: 'utf8' }); const parseSection = (text, startMarker, endMarker) => { const regExp = new RegExp(`${RegExp.escape(startMarker)}\r?\n([^]*)\r?\n${RegExp.escape(endMarker)}`); const match = text.match(regExp); - assert(match, - `Unable to locate text between '${startMarker}' and '${endMarker}'.`); + if (!match) + assert.fail(`Unable to locate text between '${startMarker}' and '${endMarker}'.`); return match[1] .split(/\r?\n/) .filter((val) => val.trim() !== ''); diff --git a/test/parallel/test-process-env-allowed-flags.js b/test/parallel/test-process-env-allowed-flags.js index a4558200fa8af8..777abc957221d8 100644 --- a/test/parallel/test-process-env-allowed-flags.js +++ b/test/parallel/test-process-env-allowed-flags.js @@ -50,9 +50,9 @@ const assert = require('assert'); // Assert all "canonical" flags begin with dash(es) { - process.allowedNodeEnvironmentFlags.forEach((flag) => { + for (const flag of process.allowedNodeEnvironmentFlags) { assert.match(flag, /^--?[a-zA-Z0-9._-]+$/); - }); + } } // Assert immutability of process.allowedNodeEnvironmentFlags diff --git a/test/parallel/test-process-env-sideeffects.js b/test/parallel/test-process-env-sideeffects.js index ee05e40e579c80..2e5149f33b826e 100644 --- a/test/parallel/test-process-env-sideeffects.js +++ b/test/parallel/test-process-env-sideeffects.js @@ -16,9 +16,8 @@ process.env.TESTVAR = 'foobar'; session.post('Runtime.evaluate', { expression: 'process.env.TESTVAR', throwOnSideEffect: true -}, (error, res) => { - assert.ifError(error); +}, common.mustSucceed((res) => { assert.deepStrictEqual(res, { result: { type: 'string', value: 'foobar' } }); -}); +})); diff --git a/test/parallel/test-process-execve-abort.js b/test/parallel/test-process-execve-abort.js index 4a36944ac83ab0..e7c90fd1301c41 100644 --- a/test/parallel/test-process-execve-abort.js +++ b/test/parallel/test-process-execve-abort.js @@ -1,7 +1,7 @@ 'use strict'; const { skip, isWindows, isIBMi } = require('../common'); -const { ok } = require('assert'); +const assert = require('assert'); const { spawnSync } = require('child_process'); const { isMainThread } = require('worker_threads'); @@ -21,6 +21,6 @@ if (process.argv[2] === 'child') { const child = spawnSync(`${process.execPath}`, [`${__filename}`, 'child']); const stderr = child.stderr.toString(); - ok(stderr.includes('process.execve failed with error code ENOENT'), stderr); - ok(stderr.includes('execve (node:internal/process/per_thread'), stderr); + assert.ok(stderr.includes('process.execve failed with error code ENOENT'), stderr); + assert.ok(stderr.includes('execve (node:internal/process/per_thread'), stderr); } diff --git a/test/parallel/test-process-execve-no-args.js b/test/parallel/test-process-execve-no-args.js index 908512622cf00f..dc3484a034f0ee 100644 --- a/test/parallel/test-process-execve-no-args.js +++ b/test/parallel/test-process-execve-no-args.js @@ -1,7 +1,7 @@ 'use strict'; const { skip, isWindows, isIBMi } = require('../common'); -const { fail } = require('assert'); +const assert = require('assert'); const { isMainThread } = require('worker_threads'); const { dirname, join } = require('path'); const { existsSync } = require('fs'); @@ -22,4 +22,4 @@ if (!existsSync(executable)) { process.execve(executable); // If process.execve succeeds, this should never be executed. -fail('process.execve failed'); +assert.fail('process.execve failed'); diff --git a/test/parallel/test-process-execve-on-exit.js b/test/parallel/test-process-execve-on-exit.js index ff01b0b50e2581..77d0cd4674554d 100644 --- a/test/parallel/test-process-execve-on-exit.js +++ b/test/parallel/test-process-execve-on-exit.js @@ -1,7 +1,7 @@ 'use strict'; const { mustNotCall, skip, isWindows, isIBMi } = require('../common'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const { isMainThread } = require('worker_threads'); if (!isMainThread) { @@ -11,7 +11,7 @@ if (!isMainThread) { } if (process.argv[2] === 'replaced') { - strictEqual(process.argv[2], 'replaced'); + assert.strictEqual(process.argv[2], 'replaced'); } else { process.on('exit', mustNotCall()); process.execve(process.execPath, [process.execPath, __filename, 'replaced'], process.env); diff --git a/test/parallel/test-process-execve-permission-fail.js b/test/parallel/test-process-execve-permission-fail.js index ffaa70627975b8..7b4ff254b7b5d3 100644 --- a/test/parallel/test-process-execve-permission-fail.js +++ b/test/parallel/test-process-execve-permission-fail.js @@ -3,7 +3,7 @@ 'use strict'; const { mustCall, skip, isWindows, isIBMi } = require('../common'); -const { fail, throws } = require('assert'); +const assert = require('assert'); const { isMainThread } = require('worker_threads'); if (!isMainThread) { @@ -13,9 +13,9 @@ if (!isMainThread) { } if (process.argv[2] === 'replaced') { - fail('process.execve should not have been allowed.'); + assert.fail('process.execve should not have been allowed.'); } else { - throws(mustCall(() => { + assert.throws(mustCall(() => { process.execve(process.execPath, [process.execPath, __filename, 'replaced'], process.env); }), { code: 'ERR_ACCESS_DENIED', permission: 'ChildProcess', resource: process.execPath }); } diff --git a/test/parallel/test-process-execve-permission-granted.js b/test/parallel/test-process-execve-permission-granted.js index f4d36d83f07a29..fcafe5df1b963f 100644 --- a/test/parallel/test-process-execve-permission-granted.js +++ b/test/parallel/test-process-execve-permission-granted.js @@ -3,7 +3,7 @@ 'use strict'; const { skip, isWindows, isIBMi } = require('../common'); -const { deepStrictEqual } = require('assert'); +const assert = require('assert'); const { isMainThread } = require('worker_threads'); if (!isMainThread) { @@ -13,7 +13,7 @@ if (!isMainThread) { } if (process.argv[2] === 'replaced') { - deepStrictEqual(process.argv, [process.execPath, __filename, 'replaced']); + assert.deepStrictEqual(process.argv, [process.execPath, __filename, 'replaced']); } else { process.execve(process.execPath, [process.execPath, __filename, 'replaced'], process.env); } diff --git a/test/parallel/test-process-execve-socket.js b/test/parallel/test-process-execve-socket.js index d113f690a09ab9..c229e4781c0f37 100644 --- a/test/parallel/test-process-execve-socket.js +++ b/test/parallel/test-process-execve-socket.js @@ -1,7 +1,7 @@ 'use strict'; const { mustCall, mustNotCall, skip, isWindows, isIBMi } = require('../common'); -const { fail, ok } = require('assert'); +const assert = require('assert'); const { createServer } = require('net'); const { isMainThread } = require('worker_threads'); @@ -13,7 +13,7 @@ if (!isMainThread) { if (process.argv[2] === 'replaced') { const port = parseInt(process.env.PORT, 10); - ok(Number.isInteger(port)); + assert.ok(Number.isInteger(port)); const server = createServer(); server.on('error', mustNotCall()); @@ -39,11 +39,11 @@ if (process.argv[2] === 'replaced') { ); // If process.execve succeed, this should never be executed. - fail('process.execve failed'); + assert.fail('process.execve failed'); })); server2.listen(port, mustCall(() => { - fail('server2.listen unexpectedly succeeded'); + assert.fail('server2.listen unexpectedly succeeded'); })); })); } diff --git a/test/parallel/test-process-execve-validation.js b/test/parallel/test-process-execve-validation.js index febaa12d06c30f..e3c588dde31aba 100644 --- a/test/parallel/test-process-execve-validation.js +++ b/test/parallel/test-process-execve-validation.js @@ -1,7 +1,7 @@ 'use strict'; const { skip, isWindows, isIBMi } = require('../common'); -const { throws } = require('assert'); +const assert = require('assert'); const { isMainThread } = require('worker_threads'); if (!isMainThread) { @@ -11,7 +11,7 @@ if (!isMainThread) { if (!isWindows && !isIBMi) { // Invalid path name { - throws(() => { + assert.throws(() => { process.execve(123); }, { name: 'TypeError', @@ -22,7 +22,7 @@ if (!isWindows && !isIBMi) { // Invalid args { - throws(() => { + assert.throws(() => { process.execve(process.execPath, '123'); }, { name: 'TypeError', @@ -30,7 +30,7 @@ if (!isWindows && !isIBMi) { message: `The "args" argument must be an instance of Array. Received type string ('123')` }); - throws(() => { + assert.throws(() => { process.execve(process.execPath, [123]); }, { name: 'TypeError', @@ -38,7 +38,7 @@ if (!isWindows && !isIBMi) { message: "The argument 'args[0]' must be a string without null bytes. Received 123", }); - throws(() => { + assert.throws(() => { process.execve(process.execPath, ['123', 'abc\u0000cde']); }, { name: 'TypeError', @@ -49,7 +49,7 @@ if (!isWindows && !isIBMi) { // Invalid env { - throws(() => { + assert.throws(() => { process.execve(process.execPath, [], '123'); }, { name: 'TypeError', @@ -57,7 +57,7 @@ if (!isWindows && !isIBMi) { message: `The "env" argument must be of type object. Received type string ('123')` }); - throws(() => { + assert.throws(() => { process.execve(process.execPath, [], { abc: 123 }); }, { name: 'TypeError', @@ -66,7 +66,7 @@ if (!isWindows && !isIBMi) { "The argument 'env' must be an object with string keys and values without null bytes. Received { abc: 123 }" }); - throws(() => { + assert.throws(() => { process.execve(process.execPath, [], { abc: '123', cde: 'abc\u0000cde' }); }, { name: 'TypeError', @@ -77,7 +77,7 @@ if (!isWindows && !isIBMi) { }); } } else { - throws(() => { + assert.throws(() => { process.execve( process.execPath, [__filename, 'replaced'], diff --git a/test/parallel/test-process-execve-worker-threads.js b/test/parallel/test-process-execve-worker-threads.js index 551f6f7ac30691..2d86befa08eb5a 100644 --- a/test/parallel/test-process-execve-worker-threads.js +++ b/test/parallel/test-process-execve-worker-threads.js @@ -1,7 +1,7 @@ 'use strict'; const { isWindows, isIBMi, mustCall, skip } = require('../common'); -const { throws } = require('assert'); +const assert = require('assert'); const { isMainThread, Worker } = require('worker_threads'); if (isWindows || isIBMi) { @@ -11,7 +11,7 @@ if (isWindows || isIBMi) { if (isMainThread) { new Worker(__filename); } else { - throws(mustCall(() => { + assert.throws(mustCall(() => { process.execve( process.execPath, [__filename, 'replaced'], diff --git a/test/parallel/test-process-execve.js b/test/parallel/test-process-execve.js index b0d4bc05158f62..577de22a188703 100644 --- a/test/parallel/test-process-execve.js +++ b/test/parallel/test-process-execve.js @@ -1,7 +1,7 @@ 'use strict'; const { isWindows, isIBMi, skip } = require('../common'); -const { deepStrictEqual, fail, strictEqual } = require('assert'); +const assert = require('assert'); const { isMainThread } = require('worker_threads'); if (!isMainThread) { @@ -11,10 +11,10 @@ if (!isMainThread) { } if (process.argv[2] === 'replaced') { - deepStrictEqual(process.argv, [process.execPath, __filename, 'replaced']); - strictEqual(process.env.CWD, process.cwd()); - strictEqual(process.env.EXECVE_A, 'FIRST'); - strictEqual(process.env.EXECVE_B, 'SECOND'); + assert.deepStrictEqual(process.argv, [process.execPath, __filename, 'replaced']); + assert.strictEqual(process.env.CWD, process.cwd()); + assert.strictEqual(process.env.EXECVE_A, 'FIRST'); + assert.strictEqual(process.env.EXECVE_B, 'SECOND'); } else { process.execve( process.execPath, @@ -23,5 +23,5 @@ if (process.argv[2] === 'replaced') { ); // If process.execve succeed, this should never be executed. - fail('process.execve failed'); + assert.fail('process.execve failed'); } diff --git a/test/parallel/test-process-exit-code-validation.js b/test/parallel/test-process-exit-code-validation.js index 9987b58c867c99..6051f9b6dbc8ee 100644 --- a/test/parallel/test-process-exit-code-validation.js +++ b/test/parallel/test-process-exit-code-validation.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const invalids = [ { @@ -90,35 +90,35 @@ const args = [...invalids, ...valids]; if (process.argv[2] === undefined) { const { spawnSync } = require('node:child_process'); const { inspect, debuglog } = require('node:util'); - const { throws, strictEqual } = require('node:assert'); + const assert = require('node:assert'); const debug = debuglog('test'); const node = process.execPath; - const test = (index, useProcessExitCode) => { + const test = common.mustCallAtLeast((index, useProcessExitCode) => { const { status: code } = spawnSync(node, [ __filename, index, useProcessExitCode, ]); debug(`actual: ${code}, ${inspect(args[index])} ${!!useProcessExitCode}`); - strictEqual( + assert.strictEqual( code, args[index].expected, `actual: ${code}, ${inspect(args[index])}` ); - }; + }); // Check process.exitCode for (const arg of invalids) { debug(`invaild code: ${inspect(arg.code)}`); - throws(() => (process.exitCode = arg.code), new RegExp(arg.pattern)); + assert.throws(() => (process.exitCode = arg.code), new RegExp(arg.pattern)); } for (const arg of valids) { debug(`vaild code: ${inspect(arg.code)}`); process.exitCode = arg.code; } - throws(() => { + assert.throws(() => { delete process.exitCode; }, /Cannot delete property 'exitCode' of #/); process.exitCode = 0; diff --git a/test/parallel/test-process-exit-code.js b/test/parallel/test-process-exit-code.js index 1049f372d7219e..63f6322d077ab5 100644 --- a/test/parallel/test-process-exit-code.js +++ b/test/parallel/test-process-exit-code.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 debug = require('util').debuglog('test'); @@ -45,14 +45,14 @@ function parent() { const f = __filename; const option = { stdio: [ 0, 1, 'ignore' ] }; - const test = (arg, name = 'child', exit) => { - spawn(node, [f, arg], option).on('exit', (code) => { + const test = common.mustCallAtLeast((arg, name = 'child', exit) => { + spawn(node, [f, arg], option).on('exit', common.mustCall((code) => { assert.strictEqual( code, exit, `wrong exit for ${arg}-${name}\nexpected:${exit} but got:${code}`); debug(`ok - ${arg} exited with ${exit}`); - }); - }; + })); + }); testCases.forEach((tc, i) => test(i, tc.func.name, tc.result)); } diff --git a/test/parallel/test-process-getgroups.js b/test/parallel/test-process-getgroups.js index 28df13205f44fc..a5fd23ae26d82b 100644 --- a/test/parallel/test-process-getgroups.js +++ b/test/parallel/test-process-getgroups.js @@ -34,13 +34,12 @@ if (typeof process.getgroups === 'function') { const groups = unique(process.getgroups()); assert(Array.isArray(groups)); assert(groups.length > 0); - exec('id -G', function(err, stdout) { - assert.ifError(err); + exec('id -G', common.mustSucceed((stdout) => { const real_groups = unique(stdout.match(/\d+/g).map(Number)); assert.deepStrictEqual(groups, real_groups); check(groups, real_groups); check(real_groups, groups); - }); + })); } function check(a, b) { diff --git a/test/parallel/test-process-raw-debug.js b/test/parallel/test-process-raw-debug.js index ba5ae74f0ff720..6a98c5de6086e3 100644 --- a/test/parallel/test-process-raw-debug.js +++ b/test/parallel/test-process-raw-debug.js @@ -46,10 +46,10 @@ function parent() { child.stderr.setEncoding('utf8'); - child.stderr.on('end', function() { + child.stderr.on('end', common.mustCall(() => { assert.strictEqual(output, `I can still debug!${os.EOL}`); console.log('ok - got expected message'); - }); + })); child.on('exit', common.mustCall(function(c) { assert(!c); diff --git a/test/parallel/test-process-ref-unref.js b/test/parallel/test-process-ref-unref.js index 19665703cfe341..b80085d559af28 100644 --- a/test/parallel/test-process-ref-unref.js +++ b/test/parallel/test-process-ref-unref.js @@ -7,9 +7,7 @@ const { it, } = require('node:test'); -const { - strictEqual, -} = require('node:assert'); +const assert = require('node:assert'); class Foo { refCalled = 0; @@ -43,18 +41,18 @@ describe('process.ref/unref work as expected', () => { process.unref(foo1); process.ref(foo2); process.unref(foo2); - strictEqual(foo1.refCalled, 1); - strictEqual(foo1.unrefCalled, 1); - strictEqual(foo2.refCalled, 1); - strictEqual(foo2.unrefCalled, 1); + assert.strictEqual(foo1.refCalled, 1); + assert.strictEqual(foo1.unrefCalled, 1); + assert.strictEqual(foo2.refCalled, 1); + assert.strictEqual(foo2.unrefCalled, 1); // Objects that implement the legacy API also just work. const i = setInterval(() => {}, 1000); - strictEqual(i.hasRef(), true); + assert.strictEqual(i.hasRef(), true); process.unref(i); - strictEqual(i.hasRef(), false); + assert.strictEqual(i.hasRef(), false); process.ref(i); - strictEqual(i.hasRef(), true); + assert.strictEqual(i.hasRef(), true); clearInterval(i); }); }); diff --git a/test/parallel/test-process-threadCpuUsage-main-thread.js b/test/parallel/test-process-threadCpuUsage-main-thread.js index 82c98783987c2a..f304ca9402f320 100644 --- a/test/parallel/test-process-threadCpuUsage-main-thread.js +++ b/test/parallel/test-process-threadCpuUsage-main-thread.js @@ -2,16 +2,16 @@ const { isSunOS } = require('../common'); -const { ok, throws, notStrictEqual } = require('assert'); +const assert = require('assert'); function validateResult(result) { - notStrictEqual(result, null); + assert.notStrictEqual(result, null); - ok(Number.isFinite(result.user)); - ok(Number.isFinite(result.system)); + assert.ok(Number.isFinite(result.user)); + assert.ok(Number.isFinite(result.system)); - ok(result.user >= 0); - ok(result.system >= 0); + assert.ok(result.user >= 0); + assert.ok(result.system >= 0); } // Test that process.threadCpuUsage() works on the main thread @@ -32,12 +32,12 @@ if (!isSunOS) { for (let i = 0; i < 10; i++) { thisUsage = process.threadCpuUsage(); validateResult(thisUsage); - ok(thisUsage.user >= lastUsage.user); - ok(thisUsage.system >= lastUsage.system); + assert.ok(thisUsage.user >= lastUsage.user); + assert.ok(thisUsage.system >= lastUsage.system); lastUsage = thisUsage; } } else { - throws( + assert.throws( () => process.threadCpuUsage(), { code: 'ERR_OPERATION_FAILED', @@ -49,7 +49,7 @@ if (!isSunOS) { // Test argument validaton { - throws( + assert.throws( () => process.threadCpuUsage(123), { code: 'ERR_INVALID_ARG_TYPE', @@ -58,7 +58,7 @@ if (!isSunOS) { } ); - throws( + assert.throws( () => process.threadCpuUsage([]), { code: 'ERR_INVALID_ARG_TYPE', @@ -67,7 +67,7 @@ if (!isSunOS) { } ); - throws( + assert.throws( () => process.threadCpuUsage({ user: -123 }), { code: 'ERR_INVALID_ARG_VALUE', @@ -76,7 +76,7 @@ if (!isSunOS) { } ); - throws( + assert.throws( () => process.threadCpuUsage({ user: 0, system: 'bar' }), { code: 'ERR_INVALID_ARG_TYPE', diff --git a/test/parallel/test-process-threadCpuUsage-worker-threads.js b/test/parallel/test-process-threadCpuUsage-worker-threads.js index e306e08e8266e2..afe2798511de4b 100644 --- a/test/parallel/test-process-threadCpuUsage-worker-threads.js +++ b/test/parallel/test-process-threadCpuUsage-worker-threads.js @@ -14,7 +14,7 @@ if (isSunOS) { skip('Operation not supported yet on SmartOS'); } -const { ok } = require('assert'); +const assert = require('assert'); const { randomBytes, createHash } = require('crypto'); const { once } = require('events'); const { Worker, parentPort, workerData } = require('worker_threads'); @@ -40,17 +40,17 @@ function validateResults(results) { // Unfortunately, the real values are not really predictable on the CI so we // just check that all the values are positive numbers. for (let i = 0; i < 3; i++) { - ok(typeof results[i].process.user === 'number'); - ok(results[i].process.user >= 0); + assert.ok(typeof results[i].process.user === 'number'); + assert.ok(results[i].process.user >= 0); - ok(typeof results[i].process.system === 'number'); - ok(results[i].process.system >= 0); + assert.ok(typeof results[i].process.system === 'number'); + assert.ok(results[i].process.system >= 0); - ok(typeof results[i].thread.user === 'number'); - ok(results[i].thread.user >= 0); + assert.ok(typeof results[i].thread.user === 'number'); + assert.ok(results[i].thread.user >= 0); - ok(typeof results[i].thread.system === 'number'); - ok(results[i].thread.system >= 0); + assert.ok(typeof results[i].thread.system === 'number'); + assert.ok(results[i].thread.system >= 0); } } diff --git a/test/parallel/test-process-uptime.js b/test/parallel/test-process-uptime.js index eabb6cf2661c87..017fa06c71c658 100644 --- a/test/parallel/test-process-uptime.js +++ b/test/parallel/test-process-uptime.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); console.error(process.uptime()); @@ -31,7 +31,7 @@ assert.ok(process.uptime() <= 15); const original = process.uptime(); -setTimeout(function() { +setTimeout(common.mustCall(() => { const uptime = process.uptime(); assert.ok(original < uptime); -}, 10); +}), 10); diff --git a/test/parallel/test-process-warning.js b/test/parallel/test-process-warning.js index c1fbbf775fb45e..cc11d61f103bc5 100644 --- a/test/parallel/test-process-warning.js +++ b/test/parallel/test-process-warning.js @@ -38,9 +38,9 @@ function test4() { // process.emitWarning will throw when process.throwDeprecation is true // and type is `DeprecationWarning`. process.throwDeprecation = true; - process.once('uncaughtException', (err) => { + process.once('uncaughtException', common.mustCall((err) => { assert.match(err.toString(), /^DeprecationWarning: test$/); - }); + })); try { process.emitWarning('test', 'DeprecationWarning'); } catch { @@ -60,9 +60,9 @@ function test5() { function test6() { process.emitWarning('test', { detail: 'foo' }); - process.on('warning', (warning) => { + process.on('warning', common.mustCallAtLeast((warning) => { assert.strictEqual(warning.detail, 'foo'); - }); + })); } test1(); diff --git a/test/parallel/test-promise-hook-on-resolve.js b/test/parallel/test-promise-hook-on-resolve.js index 45bfb8ca409d26..f6379bf1e8d8a9 100644 --- a/test/parallel/test-promise-hook-on-resolve.js +++ b/test/parallel/test-promise-hook-on-resolve.js @@ -20,26 +20,26 @@ const stop = promiseHooks.onSettled(common.mustCall((promise) => { // Constructor resolve triggers hook const promise = new Promise((resolve, reject) => { assert.strictEqual(seen, undefined); - setImmediate(() => { + setImmediate(common.mustCall(() => { resolve(); assert.strictEqual(seen, promise); seen = undefined; constructorReject(); - }); + })); }); // Constructor reject triggers hook function constructorReject() { const promise = new Promise((resolve, reject) => { assert.strictEqual(seen, undefined); - setImmediate(() => { + setImmediate(common.mustCall(() => { reject(); assert.strictEqual(seen, promise); seen = undefined; simpleResolveReject(); - }); + })); }); promise.catch(() => {}); } diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index 761923c5cc30c6..527840a91bdb0a 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); const { inspect } = require('util'); -const asyncTest = (function() { +const test = (function() { let asyncTestsEnabled = false; let asyncTestLastCheck; const asyncTestQueue = []; @@ -107,32 +107,32 @@ function onUnhandledFail(done) { }, 10); } -asyncTest('synchronously rejected promise should trigger' + +test('synchronously rejected promise should trigger' + ' unhandledRejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); - }); + })); Promise.reject(e); }); -asyncTest('synchronously rejected promise should trigger' + +test('synchronously rejected promise should trigger' + ' unhandledRejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); - }); + })); new Promise(function(_, reject) { reject(e); }); }); -asyncTest('Promise rejected after setImmediate should trigger' + +test('Promise rejected after setImmediate should trigger' + ' unhandledRejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); - }); + })); new Promise(function(_, reject) { setImmediate(function() { reject(e); @@ -140,12 +140,12 @@ asyncTest('Promise rejected after setImmediate should trigger' + }); }); -asyncTest('Promise rejected after setTimeout(,1) should trigger' + +test('Promise rejected after setTimeout(,1) should trigger' + ' unhandled rejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); - }); + })); new Promise(function(_, reject) { setTimeout(function() { reject(e); @@ -153,12 +153,12 @@ asyncTest('Promise rejected after setTimeout(,1) should trigger' + }); }); -asyncTest('Catching a promise rejection after setImmediate is not' + +test('Catching a promise rejection after setImmediate is not' + ' soon enough to stop unhandledRejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); - }); + })); let _reject; const promise = new Promise(function(_, reject) { _reject = reject; @@ -169,39 +169,39 @@ asyncTest('Catching a promise rejection after setImmediate is not' + }); }); -asyncTest('When re-throwing new errors in a promise catch, only the' + +test('When re-throwing new errors in a promise catch, only the' + ' re-thrown error should hit unhandledRejection', function(done) { const e = new Error(); const e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e2); assert.strictEqual(promise, promise2); - }); + })); const promise2 = Promise.reject(e).then(assert.fail, function(reason) { assert.strictEqual(reason, e); throw e2; }); }); -asyncTest('Test params of unhandledRejection for a synchronously-rejected ' + +test('Test params of unhandledRejection for a synchronously-rejected ' + 'promise', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); assert.strictEqual(promise, promise); - }); + })); Promise.reject(e); }); -asyncTest('When re-throwing new errors in a promise catch, only the ' + +test('When re-throwing new errors in a promise catch, only the ' + 're-thrown error should hit unhandledRejection: original promise' + ' rejected async with setTimeout(,1)', function(done) { const e = new Error(); const e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e2); assert.strictEqual(promise, promise2); - }); + })); const promise2 = new Promise(function(_, reject) { setTimeout(function() { reject(e); @@ -212,15 +212,15 @@ asyncTest('When re-throwing new errors in a promise catch, only the ' + }); }); -asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' + +test('When re-throwing new errors in a promise catch, only the re-thrown' + ' error should hit unhandledRejection: promise catch attached a' + ' process.nextTick after rejection', function(done) { const e = new Error(); const e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e2); assert.strictEqual(promise, promise2); - }); + })); const promise = new Promise(function(_, reject) { setTimeout(function() { reject(e); @@ -235,7 +235,7 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' + let promise2; }); -asyncTest( +test( 'unhandledRejection should not be triggered if a promise catch is' + ' attached synchronously upon the promise\'s creation', function(done) { @@ -245,7 +245,7 @@ asyncTest( } ); -asyncTest( +test( 'unhandledRejection should not be triggered if a promise catch is' + ' attached synchronously upon the promise\'s creation', function(done) { @@ -257,7 +257,7 @@ asyncTest( } ); -asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + +test('Attaching a promise catch in a process.nextTick is soon enough to' + ' prevent unhandledRejection', function(done) { const e = new Error(); onUnhandledFail(done); @@ -267,7 +267,7 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + }); }); -asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + +test('Attaching a promise catch in a process.nextTick is soon enough to' + ' prevent unhandledRejection', function(done) { const e = new Error(); onUnhandledFail(done); @@ -279,7 +279,7 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + }); }); -asyncTest('While inside setImmediate, catching a rejected promise derived ' + +test('While inside setImmediate, catching a rejected promise derived ' + 'from returning a rejected promise in a fulfillment handler ' + 'prevents unhandledRejection', function(done) { onUnhandledFail(done); @@ -295,7 +295,7 @@ asyncTest('While inside setImmediate, catching a rejected promise derived ' + }); // State adaptation tests -asyncTest('catching a promise which is asynchronously rejected (via ' + +test('catching a promise which is asynchronously rejected (via ' + 'resolution to an asynchronously-rejected promise) prevents' + ' unhandledRejection', function(done) { const e = new Error(); @@ -311,7 +311,7 @@ asyncTest('catching a promise which is asynchronously rejected (via ' + }); }); -asyncTest('Catching a rejected promise derived from throwing in a' + +test('Catching a rejected promise derived from throwing in a' + ' fulfillment handler prevents unhandledRejection', function(done) { const e = new Error(); onUnhandledFail(done); @@ -322,7 +322,7 @@ asyncTest('Catching a rejected promise derived from throwing in a' + }); }); -asyncTest('Catching a rejected promise derived from returning a' + +test('Catching a rejected promise derived from returning a' + ' synchronously-rejected promise in a fulfillment handler' + ' prevents unhandledRejection', function(done) { const e = new Error(); @@ -334,14 +334,14 @@ asyncTest('Catching a rejected promise derived from returning a' + }); }); -asyncTest('A rejected promise derived from returning an' + +test('A rejected promise derived from returning an' + ' asynchronously-rejected promise in a fulfillment handler' + ' does trigger unhandledRejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); assert.strictEqual(promise, _promise); - }); + })); const _promise = Promise.resolve().then(function() { return new Promise(function(_, reject) { setTimeout(function() { @@ -351,27 +351,27 @@ asyncTest('A rejected promise derived from returning an' + }); }); -asyncTest('A rejected promise derived from throwing in a fulfillment handler' + +test('A rejected promise derived from throwing in a fulfillment handler' + ' does trigger unhandledRejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); assert.strictEqual(promise, _promise); - }); + })); const _promise = Promise.resolve().then(function() { throw e; }); }); -asyncTest( +test( 'A rejected promise derived from returning a synchronously-rejected' + ' promise in a fulfillment handler does trigger unhandledRejection', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); assert.strictEqual(promise, _promise); - }); + })); const _promise = Promise.resolve().then(function() { return Promise.reject(e); }); @@ -379,14 +379,14 @@ asyncTest( ); // Combinations with Promise.all -asyncTest('Catching the Promise.all() of a collection that includes a ' + +test('Catching the Promise.all() of a collection that includes a ' + 'rejected promise prevents unhandledRejection', function(done) { const e = new Error(); onUnhandledFail(done); Promise.all([Promise.reject(e)]).then(assert.fail, function() {}); }); -asyncTest( +test( 'Catching the Promise.all() of a collection that includes a ' + 'nextTick-async rejected promise prevents unhandledRejection', function(done) { @@ -404,32 +404,32 @@ asyncTest( } ); -asyncTest('Failing to catch the Promise.all() of a collection that includes' + +test('Failing to catch the Promise.all() of a collection that includes' + ' a rejected promise triggers unhandledRejection for the returned' + ' promise, not the passed promise', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); assert.strictEqual(promise, p); - }); + })); const p = Promise.all([Promise.reject(e)]); }); -asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + +test('Waiting setTimeout(, 10) to catch a promise causes an' + ' unhandledRejection + rejectionHandled pair', function(done) { clean(); const unhandledPromises = []; const e = new Error(); - process.on('unhandledRejection', function(reason, promise) { + process.on('unhandledRejection', common.mustCall((reason, promise) => { assert.strictEqual(reason, e); unhandledPromises.push(promise); - }); - process.on('rejectionHandled', function(promise) { + })); + process.on('rejectionHandled', common.mustCall((promise) => { assert.strictEqual(unhandledPromises.length, 1); assert.strictEqual(unhandledPromises[0], promise); assert.strictEqual(promise, thePromise); done(); - }); + })); const thePromise = new Promise(function() { throw e; @@ -441,7 +441,7 @@ asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + }, 10); }); -asyncTest('Waiting for some combination of process.nextTick + promise' + +test('Waiting for some combination of process.nextTick + promise' + ' microtasks to attach a catch handler is still soon enough to' + ' prevent unhandledRejection', function(done) { const e = new Error(); @@ -460,7 +460,7 @@ asyncTest('Waiting for some combination of process.nextTick + promise' + }); }); -asyncTest('Waiting for some combination of process.nextTick + promise' + +test('Waiting for some combination of process.nextTick + promise' + ' microtasks to attach a catch handler is still soon enough to ' + 'prevent unhandledRejection: inside setImmediate', function(done) { const e = new Error(); @@ -480,7 +480,7 @@ asyncTest('Waiting for some combination of process.nextTick + promise' + }); }); -asyncTest('Waiting for some combination of process.nextTick + promise ' + +test('Waiting for some combination of process.nextTick + promise ' + 'microtasks to attach a catch handler is still soon enough to ' + 'prevent unhandledRejection: inside setTimeout', function(done) { const e = new Error(); @@ -500,7 +500,7 @@ asyncTest('Waiting for some combination of process.nextTick + promise ' + }, 0); }); -asyncTest('Waiting for some combination of promise microtasks + ' + +test('Waiting for some combination of promise microtasks + ' + 'process.nextTick to attach a catch handler is still soon enough' + ' to prevent unhandledRejection', function(done) { const e = new Error(); @@ -519,7 +519,7 @@ asyncTest('Waiting for some combination of promise microtasks + ' + }); }); -asyncTest( +test( 'Waiting for some combination of promise microtasks +' + ' process.nextTick to attach a catch handler is still soon enough' + ' to prevent unhandledRejection: inside setImmediate', @@ -542,7 +542,7 @@ asyncTest( } ); -asyncTest('Waiting for some combination of promise microtasks +' + +test('Waiting for some combination of promise microtasks +' + ' process.nextTick to attach a catch handler is still soon enough' + ' to prevent unhandledRejection: inside setTimeout', function(done) { const e = new Error(); @@ -562,14 +562,14 @@ asyncTest('Waiting for some combination of promise microtasks +' + }, 0); }); -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + +test('setImmediate + promise microtasks is too late to attach a catch' + ' handler; unhandledRejection will be triggered in that case.' + ' (setImmediate before promise creation/rejection)', function(done) { const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, e); assert.strictEqual(promise, p); - }); + })); const p = Promise.reject(e); setImmediate(function() { Promise.resolve().then(function() { @@ -578,13 +578,13 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' + }); }); -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + +test('setImmediate + promise microtasks is too late to attach a catch' + ' handler; unhandledRejection will be triggered in that case' + ' (setImmediate before promise creation/rejection)', function(done) { - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, undefined); assert.strictEqual(promise, p); - }); + })); setImmediate(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { @@ -599,13 +599,13 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' + const p = Promise.reject(); }); -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + +test('setImmediate + promise microtasks is too late to attach a catch' + ' handler; unhandledRejection will be triggered in that case' + ' (setImmediate after promise creation/rejection)', function(done) { - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, undefined); assert.strictEqual(promise, p); - }); + })); const p = Promise.reject(); setImmediate(function() { Promise.resolve().then(function() { @@ -620,35 +620,35 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' + }); }); -asyncTest('nextTick is immediately scheduled when called inside an event' + +test('nextTick is immediately scheduled when called inside an event' + ' handler', function(done) { clean(); const e = new Error('error'); - process.on('unhandledRejection', function(reason, promise) { + process.on('unhandledRejection', common.mustCall((reason, promise) => { const order = []; process.nextTick(function() { order.push(1); }); - setTimeout(function() { + setTimeout(common.mustCall(() => { order.push(2); assert.deepStrictEqual([1, 2], order); done(); - }, 1); - }); + }), 1); + })); Promise.reject(e); }); -asyncTest('Throwing an error inside a rejectionHandled handler goes to' + +test('Throwing an error inside a rejectionHandled handler goes to' + ' unhandledException, and does not cause .catch() to throw an ' + 'exception', function(done) { clean(); const e = new Error(); const e2 = new Error(); - const tearDownException = setupException(function(err) { + const tearDownException = setupException(common.mustCall((err) => { assert.strictEqual(err, e2); tearDownException(); done(); - }); + })); process.on('rejectionHandled', function() { throw e2; }); @@ -662,20 +662,20 @@ asyncTest('Throwing an error inside a rejectionHandled handler goes to' + }, 1); }); -asyncTest('Rejected promise inside unhandledRejection allows nextTick loop' + +test('Rejected promise inside unhandledRejection allows nextTick loop' + ' to proceed first', function(done) { clean(); Promise.reject(0); let didCall = false; - process.on('unhandledRejection', () => { + process.on('unhandledRejection', common.mustCall(() => { assert(!didCall); didCall = true; const promise = Promise.reject(0); process.nextTick(() => promise.catch(() => done())); - }); + })); }); -asyncTest( +test( 'Promise rejection triggers unhandledRejection immediately', function(done) { clean(); @@ -693,12 +693,12 @@ asyncTest( ); // https://github.com/nodejs/node/issues/30953 -asyncTest( +test( 'Catching a promise should not take effect on previous promises', function(done) { - onUnhandledSucceed(done, function(reason, promise) { + onUnhandledSucceed(done, common.mustCall((reason, promise) => { assert.strictEqual(reason, '1'); - }); + })); Promise.reject('1'); Promise.reject('2').catch(function() {}); } diff --git a/test/parallel/test-punycode.js b/test/parallel/test-punycode.js index da711aae1bb044..1d20d43b989588 100644 --- a/test/parallel/test-punycode.js +++ b/test/parallel/test-punycode.js @@ -215,21 +215,21 @@ const handleError = (error, name) => { const regexNonASCII = /[^\x20-\x7E]/; const testBattery = { - encode: (test) => assert.strictEqual( + encode: common.mustCallAtLeast((test) => assert.strictEqual( punycode.encode(test.decoded), test.encoded - ), - decode: (test) => assert.strictEqual( + )), + decode: common.mustCallAtLeast((test) => assert.strictEqual( punycode.decode(test.encoded), test.decoded - ), - toASCII: (test) => assert.strictEqual( + )), + toASCII: common.mustCallAtLeast((test) => assert.strictEqual( punycode.toASCII(test.decoded), regexNonASCII.test(test.decoded) ? `xn--${test.encoded}` : test.decoded - ), - toUnicode: (test) => assert.strictEqual( + )), + toUnicode: common.mustCallAtLeast((test) => assert.strictEqual( punycode.toUnicode( regexNonASCII.test(test.decoded) ? `xn--${test.encoded}` : @@ -238,7 +238,7 @@ const testBattery = { regexNonASCII.test(test.decoded) ? test.decoded.toLowerCase() : test.decoded - ) + )) }; tests.forEach((testCase) => { diff --git a/test/parallel/test-quic-exports.mjs b/test/parallel/test-quic-exports.mjs index 47de1edfee9255..d977d452d7d43c 100644 --- a/test/parallel/test-quic-exports.mjs +++ b/test/parallel/test-quic-exports.mjs @@ -1,6 +1,6 @@ // Flags: --experimental-quic --no-warnings import { hasQuic, skip } from '../common/index.mjs'; -import { strictEqual, throws } from 'node:assert'; +import assert from 'node:assert'; if (!hasQuic) { skip('QUIC is not enabled'); @@ -9,35 +9,35 @@ if (!hasQuic) { const quic = await import('node:quic'); // Test that the main exports exist and are of the correct type. -strictEqual(typeof quic.connect, 'function'); -strictEqual(typeof quic.listen, 'function'); -strictEqual(typeof quic.QuicEndpoint, 'function'); -strictEqual(typeof quic.QuicSession, 'function'); -strictEqual(typeof quic.QuicStream, 'function'); -strictEqual(typeof quic.QuicEndpoint.Stats, 'function'); -strictEqual(typeof quic.QuicSession.Stats, 'function'); -strictEqual(typeof quic.QuicStream.Stats, 'function'); -strictEqual(typeof quic.constants, 'object'); -strictEqual(typeof quic.constants.cc, 'object'); +assert.strictEqual(typeof quic.connect, 'function'); +assert.strictEqual(typeof quic.listen, 'function'); +assert.strictEqual(typeof quic.QuicEndpoint, 'function'); +assert.strictEqual(typeof quic.QuicSession, 'function'); +assert.strictEqual(typeof quic.QuicStream, 'function'); +assert.strictEqual(typeof quic.QuicEndpoint.Stats, 'function'); +assert.strictEqual(typeof quic.QuicSession.Stats, 'function'); +assert.strictEqual(typeof quic.QuicStream.Stats, 'function'); +assert.strictEqual(typeof quic.constants, 'object'); +assert.strictEqual(typeof quic.constants.cc, 'object'); // Test that the constants exist and are of the correct type. -strictEqual(quic.constants.cc.RENO, 'reno'); -strictEqual(quic.constants.cc.CUBIC, 'cubic'); -strictEqual(quic.constants.cc.BBR, 'bbr'); -strictEqual(quic.constants.DEFAULT_CIPHERS, - 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:' + +assert.strictEqual(quic.constants.cc.RENO, 'reno'); +assert.strictEqual(quic.constants.cc.CUBIC, 'cubic'); +assert.strictEqual(quic.constants.cc.BBR, 'bbr'); +assert.strictEqual(quic.constants.DEFAULT_CIPHERS, + 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:' + 'TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256'); -strictEqual(quic.constants.DEFAULT_GROUPS, 'X25519:P-256:P-384:P-521'); +assert.strictEqual(quic.constants.DEFAULT_GROUPS, 'X25519:P-256:P-384:P-521'); // Ensure the constants are.. well, constant. -throws(() => { quic.constants.cc.RENO = 'foo'; }, TypeError); -strictEqual(quic.constants.cc.RENO, 'reno'); +assert.throws(() => { quic.constants.cc.RENO = 'foo'; }, TypeError); +assert.strictEqual(quic.constants.cc.RENO, 'reno'); -throws(() => { quic.constants.cc.NEW_CONSTANT = 'bar'; }, TypeError); -strictEqual(quic.constants.cc.NEW_CONSTANT, undefined); +assert.throws(() => { quic.constants.cc.NEW_CONSTANT = 'bar'; }, TypeError); +assert.strictEqual(quic.constants.cc.NEW_CONSTANT, undefined); -throws(() => { quic.constants.DEFAULT_CIPHERS = 123; }, TypeError); -strictEqual(typeof quic.constants.DEFAULT_CIPHERS, 'string'); +assert.throws(() => { quic.constants.DEFAULT_CIPHERS = 123; }, TypeError); +assert.strictEqual(typeof quic.constants.DEFAULT_CIPHERS, 'string'); -throws(() => { quic.constants.NEW_CONSTANT = 456; }, TypeError); -strictEqual(quic.constants.NEW_CONSTANT, undefined); +assert.throws(() => { quic.constants.NEW_CONSTANT = 456; }, TypeError); +assert.strictEqual(quic.constants.NEW_CONSTANT, undefined); diff --git a/test/parallel/test-quic-handshake-ipv6-only.mjs b/test/parallel/test-quic-handshake-ipv6-only.mjs index 8163fad4c15e4d..fb62a4759afe0e 100644 --- a/test/parallel/test-quic-handshake-ipv6-only.mjs +++ b/test/parallel/test-quic-handshake-ipv6-only.mjs @@ -1,7 +1,7 @@ // Flags: --experimental-quic --no-warnings -import { hasQuic, hasIPv6, skip } from '../common/index.mjs'; -import { ok, partialDeepStrictEqual } from 'node:assert'; +import { hasQuic, hasIPv6, skip, mustCall } from '../common/index.mjs'; +import assert from 'node:assert'; import { readKey } from '../common/fixtures.mjs'; if (!hasQuic) { @@ -34,12 +34,13 @@ const check = { const serverOpened = Promise.withResolvers(); const clientOpened = Promise.withResolvers(); -const serverEndpoint = await listen(async (serverSession) => { - const info = await serverSession.opened; - partialDeepStrictEqual(info, check); - serverOpened.resolve(); - serverSession.close(); -}, { keys, certs, endpoint: { +const serverEndpoint = await listen(mustCall((serverSession) => { + serverSession.opened.then((info) => { + assert.partialDeepStrictEqual(info, check); + serverOpened.resolve(); + serverSession.close(); + }).then(mustCall()); +}), { keys, certs, endpoint: { address: { address: '::1', family: 'ipv6', @@ -48,7 +49,7 @@ const serverEndpoint = await listen(async (serverSession) => { } }); // The server must have an address to connect to after listen resolves. -ok(serverEndpoint.address !== undefined); +assert.ok(serverEndpoint.address !== undefined); const clientSession = await connect(serverEndpoint.address, { endpoint: { @@ -59,9 +60,9 @@ const clientSession = await connect(serverEndpoint.address, { } }); clientSession.opened.then((info) => { - partialDeepStrictEqual(info, check); + assert.partialDeepStrictEqual(info, check); clientOpened.resolve(); -}); +}).then(mustCall()); await Promise.all([serverOpened.promise, clientOpened.promise]); clientSession.close(); diff --git a/test/parallel/test-quic-handshake.mjs b/test/parallel/test-quic-handshake.mjs index faabdcd898af32..1e40269d5d7a82 100644 --- a/test/parallel/test-quic-handshake.mjs +++ b/test/parallel/test-quic-handshake.mjs @@ -1,7 +1,7 @@ // Flags: --experimental-quic --no-warnings -import { hasQuic, skip } from '../common/index.mjs'; -import { ok, partialDeepStrictEqual } from 'node:assert'; +import { hasQuic, skip, mustCall } from '../common/index.mjs'; +import assert from 'node:assert'; import { readKey } from '../common/fixtures.mjs'; if (!hasQuic) { @@ -30,21 +30,22 @@ const check = { const serverOpened = Promise.withResolvers(); const clientOpened = Promise.withResolvers(); -const serverEndpoint = await listen(async (serverSession) => { - const info = await serverSession.opened; - partialDeepStrictEqual(info, check); - serverOpened.resolve(); - serverSession.close(); -}, { keys, certs }); +const serverEndpoint = await listen(mustCall((serverSession) => { + serverSession.opened.then((info) => { + assert.partialDeepStrictEqual(info, check); + serverOpened.resolve(); + serverSession.close(); + }).then(mustCall()); +}), { keys, certs }); // The server must have an address to connect to after listen resolves. -ok(serverEndpoint.address !== undefined); +assert.ok(serverEndpoint.address !== undefined); const clientSession = await connect(serverEndpoint.address); clientSession.opened.then((info) => { - partialDeepStrictEqual(info, check); + assert.partialDeepStrictEqual(info, check); clientOpened.resolve(); -}); +}).then(mustCall()); await Promise.all([serverOpened.promise, clientOpened.promise]); clientSession.close(); diff --git a/test/parallel/test-quic-internal-endpoint-listen-defaults.mjs b/test/parallel/test-quic-internal-endpoint-listen-defaults.mjs index 2f665fee2ac61e..fabe950b370b30 100644 --- a/test/parallel/test-quic-internal-endpoint-listen-defaults.mjs +++ b/test/parallel/test-quic-internal-endpoint-listen-defaults.mjs @@ -1,12 +1,7 @@ // Flags: --expose-internals --experimental-quic --no-warnings import { hasQuic, skip } from '../common/index.mjs'; -import { - ok, - rejects, - strictEqual, - throws, -} from 'node:assert'; +import assert from 'node:assert'; import { readKey } from '../common/fixtures.mjs'; import { SocketAddress } from 'node:net'; @@ -24,48 +19,48 @@ const certs = readKey('agent1-cert.pem'); const endpoint = new QuicEndpoint(); const state = getQuicEndpointState(endpoint); -ok(!state.isBound); -ok(!state.isReceiving); -ok(!state.isListening); +assert.ok(!state.isBound); +assert.ok(!state.isReceiving); +assert.ok(!state.isListening); -strictEqual(endpoint.address, undefined); +assert.strictEqual(endpoint.address, undefined); -await rejects(listen(123, { keys, certs, endpoint }), { +await assert.rejects(listen(123, { keys, certs, endpoint }), { code: 'ERR_INVALID_ARG_TYPE', }); -await rejects(listen(() => {}, 123), { +await assert.rejects(listen(() => {}, 123), { code: 'ERR_INVALID_ARG_TYPE', }); await listen(() => {}, { keys, certs, endpoint }); -await rejects(listen(() => {}, { keys, certs, endpoint }), { +await assert.rejects(listen(() => {}, { keys, certs, endpoint }), { code: 'ERR_INVALID_STATE', }); -ok(state.isBound); -ok(state.isReceiving); -ok(state.isListening); +assert.ok(state.isBound); +assert.ok(state.isReceiving); +assert.ok(state.isListening); const address = endpoint.address; -ok(address instanceof SocketAddress); +assert.ok(address instanceof SocketAddress); -strictEqual(address.address, '127.0.0.1'); -strictEqual(address.family, 'ipv4'); -strictEqual(address.flowlabel, 0); -ok(address.port !== 0); +assert.strictEqual(address.address, '127.0.0.1'); +assert.strictEqual(address.family, 'ipv4'); +assert.strictEqual(address.flowlabel, 0); +assert.ok(address.port !== 0); -ok(!endpoint.destroyed); +assert.ok(!endpoint.destroyed); endpoint.destroy(); -strictEqual(endpoint.closed, endpoint.close()); +assert.strictEqual(endpoint.closed, endpoint.close()); await endpoint.closed; -ok(endpoint.destroyed); +assert.ok(endpoint.destroyed); -await rejects(listen(() => {}, { keys, certs, endpoint }), { +await assert.rejects(listen(() => {}, { keys, certs, endpoint }), { code: 'ERR_INVALID_STATE', }); -throws(() => { endpoint.busy = true; }, { +assert.throws(() => { endpoint.busy = true; }, { code: 'ERR_INVALID_STATE', }); await endpoint[Symbol.asyncDispose](); -strictEqual(endpoint.address, undefined); +assert.strictEqual(endpoint.address, undefined); diff --git a/test/parallel/test-quic-internal-endpoint-options.mjs b/test/parallel/test-quic-internal-endpoint-options.mjs index e6f87ba413f612..b79ce4fc4cbaf6 100644 --- a/test/parallel/test-quic-internal-endpoint-options.mjs +++ b/test/parallel/test-quic-internal-endpoint-options.mjs @@ -1,6 +1,6 @@ // Flags: --experimental-quic --no-warnings import { hasQuic, skip } from '../common/index.mjs'; -import { strictEqual, throws } from 'node:assert'; +import assert from 'node:assert'; import { inspect } from 'node:util'; if (!hasQuic) { @@ -12,7 +12,7 @@ const { QuicEndpoint } = await import('node:quic'); // Reject invalid options ['a', null, false, NaN].forEach((i) => { - throws(() => new QuicEndpoint(i), { + assert.throws(() => new QuicEndpoint(i), { code: 'ERR_INVALID_ARG_TYPE', }); }); @@ -147,7 +147,7 @@ for (const { key, valid, invalid } of cases) { for (const value of invalid) { const options = {}; options[key] = value; - throws(() => new QuicEndpoint(options), { + assert.throws(() => new QuicEndpoint(options), { message: new RegExp(`${RegExp.escape(key)}`), }, value); } @@ -155,7 +155,7 @@ for (const { key, valid, invalid } of cases) { // It can be inspected const endpoint = new QuicEndpoint({}); -strictEqual(typeof inspect(endpoint), 'string'); +assert.strictEqual(typeof inspect(endpoint), 'string'); endpoint.close(); await endpoint.closed; @@ -166,6 +166,6 @@ new QuicEndpoint({ new QuicEndpoint({ address: '127.0.0.1:0', }); -throws(() => new QuicEndpoint({ address: 123 }), { +assert.throws(() => new QuicEndpoint({ address: 123 }), { code: 'ERR_INVALID_ARG_TYPE', }); diff --git a/test/parallel/test-quic-internal-endpoint-stats-state.mjs b/test/parallel/test-quic-internal-endpoint-stats-state.mjs index b743fc1f0d524b..52ed8ba5275301 100644 --- a/test/parallel/test-quic-internal-endpoint-stats-state.mjs +++ b/test/parallel/test-quic-internal-endpoint-stats-state.mjs @@ -1,11 +1,7 @@ // Flags: --expose-internals --experimental-quic --no-warnings import { hasQuic, skip } from '../common/index.mjs'; import { inspect } from 'node:util'; -import { - deepStrictEqual, - strictEqual, - throws, -} from 'node:assert'; +import assert from 'node:assert'; if (!hasQuic) { skip('QUIC is not enabled'); @@ -32,14 +28,14 @@ const { const endpoint = new QuicEndpoint(); const state = getQuicEndpointState(endpoint); - strictEqual(state.isBound, false); - strictEqual(state.isReceiving, false); - strictEqual(state.isListening, false); - strictEqual(state.isClosing, false); - strictEqual(state.isBusy, false); - strictEqual(state.pendingCallbacks, 0n); + assert.strictEqual(state.isBound, false); + assert.strictEqual(state.isReceiving, false); + assert.strictEqual(state.isListening, false); + assert.strictEqual(state.isClosing, false); + assert.strictEqual(state.isBusy, false); + assert.strictEqual(state.pendingCallbacks, 0n); - deepStrictEqual(JSON.parse(JSON.stringify(state)), { + assert.deepStrictEqual(JSON.parse(JSON.stringify(state)), { isBound: false, isReceiving: false, isListening: false, @@ -49,10 +45,10 @@ const { }); endpoint.busy = true; - strictEqual(state.isBusy, true); + assert.strictEqual(state.isBusy, true); endpoint.busy = false; - strictEqual(state.isBusy, false); - strictEqual(typeof inspect(state), 'string'); + assert.strictEqual(state.isBusy, false); + assert.strictEqual(typeof inspect(state), 'string'); } { @@ -60,7 +56,7 @@ const { const endpoint = new QuicEndpoint(); const state = getQuicEndpointState(endpoint); state[kFinishClose](); - strictEqual(state.isBound, undefined); + assert.strictEqual(state.isBound, undefined); } { @@ -68,7 +64,7 @@ const { const endpoint = new QuicEndpoint(); const state = getQuicEndpointState(endpoint); const StateCons = state.constructor; - throws(() => new StateCons(kPrivateConstructor, 1), { + assert.throws(() => new StateCons(kPrivateConstructor, 1), { code: 'ERR_INVALID_ARG_TYPE' }); } @@ -77,22 +73,22 @@ const { // Endpoint stats are readable and have expected properties const endpoint = new QuicEndpoint(); - strictEqual(typeof endpoint.stats.isConnected, 'boolean'); - strictEqual(typeof endpoint.stats.createdAt, 'bigint'); - strictEqual(typeof endpoint.stats.destroyedAt, 'bigint'); - strictEqual(typeof endpoint.stats.bytesReceived, 'bigint'); - strictEqual(typeof endpoint.stats.bytesSent, 'bigint'); - strictEqual(typeof endpoint.stats.packetsReceived, 'bigint'); - strictEqual(typeof endpoint.stats.packetsSent, 'bigint'); - strictEqual(typeof endpoint.stats.serverSessions, 'bigint'); - strictEqual(typeof endpoint.stats.clientSessions, 'bigint'); - strictEqual(typeof endpoint.stats.serverBusyCount, 'bigint'); - strictEqual(typeof endpoint.stats.retryCount, 'bigint'); - strictEqual(typeof endpoint.stats.versionNegotiationCount, 'bigint'); - strictEqual(typeof endpoint.stats.statelessResetCount, 'bigint'); - strictEqual(typeof endpoint.stats.immediateCloseCount, 'bigint'); - - deepStrictEqual(Object.keys(endpoint.stats.toJSON()), [ + assert.strictEqual(typeof endpoint.stats.isConnected, 'boolean'); + assert.strictEqual(typeof endpoint.stats.createdAt, 'bigint'); + assert.strictEqual(typeof endpoint.stats.destroyedAt, 'bigint'); + assert.strictEqual(typeof endpoint.stats.bytesReceived, 'bigint'); + assert.strictEqual(typeof endpoint.stats.bytesSent, 'bigint'); + assert.strictEqual(typeof endpoint.stats.packetsReceived, 'bigint'); + assert.strictEqual(typeof endpoint.stats.packetsSent, 'bigint'); + assert.strictEqual(typeof endpoint.stats.serverSessions, 'bigint'); + assert.strictEqual(typeof endpoint.stats.clientSessions, 'bigint'); + assert.strictEqual(typeof endpoint.stats.serverBusyCount, 'bigint'); + assert.strictEqual(typeof endpoint.stats.retryCount, 'bigint'); + assert.strictEqual(typeof endpoint.stats.versionNegotiationCount, 'bigint'); + assert.strictEqual(typeof endpoint.stats.statelessResetCount, 'bigint'); + assert.strictEqual(typeof endpoint.stats.immediateCloseCount, 'bigint'); + + assert.deepStrictEqual(Object.keys(endpoint.stats.toJSON()), [ 'connected', 'createdAt', 'destroyedAt', @@ -108,24 +104,24 @@ const { 'statelessResetCount', 'immediateCloseCount', ]); - strictEqual(typeof inspect(endpoint.stats), 'string'); + assert.strictEqual(typeof inspect(endpoint.stats), 'string'); } { // Stats are still readable after close const endpoint = new QuicEndpoint(); - strictEqual(typeof endpoint.stats.toJSON(), 'object'); + assert.strictEqual(typeof endpoint.stats.toJSON(), 'object'); endpoint.stats[kFinishClose](); - strictEqual(endpoint.stats.isConnected, false); - strictEqual(typeof endpoint.stats.destroyedAt, 'bigint'); - strictEqual(typeof endpoint.stats.toJSON(), 'object'); + assert.strictEqual(endpoint.stats.isConnected, false); + assert.strictEqual(typeof endpoint.stats.destroyedAt, 'bigint'); + assert.strictEqual(typeof endpoint.stats.toJSON(), 'object'); } { // Stats constructor argument is ArrayBuffer const endpoint = new QuicEndpoint(); const StatsCons = endpoint.stats.constructor; - throws(() => new StatsCons(kPrivateConstructor, 1), { + assert.throws(() => new StatsCons(kPrivateConstructor, 1), { code: 'ERR_INVALID_ARG_TYPE', }); } @@ -137,77 +133,77 @@ const { const streamState = new QuicStreamState(kPrivateConstructor, new ArrayBuffer(1024)); const sessionState = new QuicSessionState(kPrivateConstructor, new ArrayBuffer(1024)); -strictEqual(streamState.pending, false); -strictEqual(streamState.finSent, false); -strictEqual(streamState.finReceived, false); -strictEqual(streamState.readEnded, false); -strictEqual(streamState.writeEnded, false); -strictEqual(streamState.paused, false); -strictEqual(streamState.reset, false); -strictEqual(streamState.hasReader, false); -strictEqual(streamState.wantsBlock, false); -strictEqual(streamState.wantsReset, false); - -strictEqual(sessionState.hasPathValidationListener, false); -strictEqual(sessionState.hasVersionNegotiationListener, false); -strictEqual(sessionState.hasDatagramListener, false); -strictEqual(sessionState.hasSessionTicketListener, false); -strictEqual(sessionState.isClosing, false); -strictEqual(sessionState.isGracefulClose, false); -strictEqual(sessionState.isSilentClose, false); -strictEqual(sessionState.isStatelessReset, false); -strictEqual(sessionState.isHandshakeCompleted, false); -strictEqual(sessionState.isHandshakeConfirmed, false); -strictEqual(sessionState.isStreamOpenAllowed, false); -strictEqual(sessionState.isPrioritySupported, false); -strictEqual(sessionState.isWrapped, false); -strictEqual(sessionState.lastDatagramId, 0n); - -strictEqual(typeof streamState.toJSON(), 'object'); -strictEqual(typeof sessionState.toJSON(), 'object'); -strictEqual(typeof inspect(streamState), 'string'); -strictEqual(typeof inspect(sessionState), 'string'); +assert.strictEqual(streamState.pending, false); +assert.strictEqual(streamState.finSent, false); +assert.strictEqual(streamState.finReceived, false); +assert.strictEqual(streamState.readEnded, false); +assert.strictEqual(streamState.writeEnded, false); +assert.strictEqual(streamState.paused, false); +assert.strictEqual(streamState.reset, false); +assert.strictEqual(streamState.hasReader, false); +assert.strictEqual(streamState.wantsBlock, false); +assert.strictEqual(streamState.wantsReset, false); + +assert.strictEqual(sessionState.hasPathValidationListener, false); +assert.strictEqual(sessionState.hasVersionNegotiationListener, false); +assert.strictEqual(sessionState.hasDatagramListener, false); +assert.strictEqual(sessionState.hasSessionTicketListener, false); +assert.strictEqual(sessionState.isClosing, false); +assert.strictEqual(sessionState.isGracefulClose, false); +assert.strictEqual(sessionState.isSilentClose, false); +assert.strictEqual(sessionState.isStatelessReset, false); +assert.strictEqual(sessionState.isHandshakeCompleted, false); +assert.strictEqual(sessionState.isHandshakeConfirmed, false); +assert.strictEqual(sessionState.isStreamOpenAllowed, false); +assert.strictEqual(sessionState.isPrioritySupported, false); +assert.strictEqual(sessionState.isWrapped, false); +assert.strictEqual(sessionState.lastDatagramId, 0n); + +assert.strictEqual(typeof streamState.toJSON(), 'object'); +assert.strictEqual(typeof sessionState.toJSON(), 'object'); +assert.strictEqual(typeof inspect(streamState), 'string'); +assert.strictEqual(typeof inspect(sessionState), 'string'); const streamStats = new QuicStreamStats(kPrivateConstructor, new ArrayBuffer(1024)); const sessionStats = new QuicSessionStats(kPrivateConstructor, new ArrayBuffer(1024)); -strictEqual(streamStats.createdAt, 0n); -strictEqual(streamStats.openedAt, 0n); -strictEqual(streamStats.receivedAt, 0n); -strictEqual(streamStats.ackedAt, 0n); -strictEqual(streamStats.destroyedAt, 0n); -strictEqual(streamStats.bytesReceived, 0n); -strictEqual(streamStats.bytesSent, 0n); -strictEqual(streamStats.maxOffset, 0n); -strictEqual(streamStats.maxOffsetAcknowledged, 0n); -strictEqual(streamStats.maxOffsetReceived, 0n); -strictEqual(streamStats.finalSize, 0n); -strictEqual(typeof streamStats.toJSON(), 'object'); -strictEqual(typeof inspect(streamStats), 'string'); +assert.strictEqual(streamStats.createdAt, 0n); +assert.strictEqual(streamStats.openedAt, 0n); +assert.strictEqual(streamStats.receivedAt, 0n); +assert.strictEqual(streamStats.ackedAt, 0n); +assert.strictEqual(streamStats.destroyedAt, 0n); +assert.strictEqual(streamStats.bytesReceived, 0n); +assert.strictEqual(streamStats.bytesSent, 0n); +assert.strictEqual(streamStats.maxOffset, 0n); +assert.strictEqual(streamStats.maxOffsetAcknowledged, 0n); +assert.strictEqual(streamStats.maxOffsetReceived, 0n); +assert.strictEqual(streamStats.finalSize, 0n); +assert.strictEqual(typeof streamStats.toJSON(), 'object'); +assert.strictEqual(typeof inspect(streamStats), 'string'); streamStats[kFinishClose](); -strictEqual(typeof sessionStats.createdAt, 'bigint'); -strictEqual(typeof sessionStats.closingAt, 'bigint'); -strictEqual(typeof sessionStats.handshakeCompletedAt, 'bigint'); -strictEqual(typeof sessionStats.handshakeConfirmedAt, 'bigint'); -strictEqual(typeof sessionStats.bytesReceived, 'bigint'); -strictEqual(typeof sessionStats.bytesSent, 'bigint'); -strictEqual(typeof sessionStats.bidiInStreamCount, 'bigint'); -strictEqual(typeof sessionStats.bidiOutStreamCount, 'bigint'); -strictEqual(typeof sessionStats.uniInStreamCount, 'bigint'); -strictEqual(typeof sessionStats.uniOutStreamCount, 'bigint'); -strictEqual(typeof sessionStats.maxBytesInFlights, 'bigint'); -strictEqual(typeof sessionStats.bytesInFlight, 'bigint'); -strictEqual(typeof sessionStats.blockCount, 'bigint'); -strictEqual(typeof sessionStats.cwnd, 'bigint'); -strictEqual(typeof sessionStats.latestRtt, 'bigint'); -strictEqual(typeof sessionStats.minRtt, 'bigint'); -strictEqual(typeof sessionStats.rttVar, 'bigint'); -strictEqual(typeof sessionStats.smoothedRtt, 'bigint'); -strictEqual(typeof sessionStats.ssthresh, 'bigint'); -strictEqual(typeof sessionStats.datagramsReceived, 'bigint'); -strictEqual(typeof sessionStats.datagramsSent, 'bigint'); -strictEqual(typeof sessionStats.datagramsAcknowledged, 'bigint'); -strictEqual(typeof sessionStats.datagramsLost, 'bigint'); -strictEqual(typeof sessionStats.toJSON(), 'object'); -strictEqual(typeof inspect(sessionStats), 'string'); +assert.strictEqual(typeof sessionStats.createdAt, 'bigint'); +assert.strictEqual(typeof sessionStats.closingAt, 'bigint'); +assert.strictEqual(typeof sessionStats.handshakeCompletedAt, 'bigint'); +assert.strictEqual(typeof sessionStats.handshakeConfirmedAt, 'bigint'); +assert.strictEqual(typeof sessionStats.bytesReceived, 'bigint'); +assert.strictEqual(typeof sessionStats.bytesSent, 'bigint'); +assert.strictEqual(typeof sessionStats.bidiInStreamCount, 'bigint'); +assert.strictEqual(typeof sessionStats.bidiOutStreamCount, 'bigint'); +assert.strictEqual(typeof sessionStats.uniInStreamCount, 'bigint'); +assert.strictEqual(typeof sessionStats.uniOutStreamCount, 'bigint'); +assert.strictEqual(typeof sessionStats.maxBytesInFlights, 'bigint'); +assert.strictEqual(typeof sessionStats.bytesInFlight, 'bigint'); +assert.strictEqual(typeof sessionStats.blockCount, 'bigint'); +assert.strictEqual(typeof sessionStats.cwnd, 'bigint'); +assert.strictEqual(typeof sessionStats.latestRtt, 'bigint'); +assert.strictEqual(typeof sessionStats.minRtt, 'bigint'); +assert.strictEqual(typeof sessionStats.rttVar, 'bigint'); +assert.strictEqual(typeof sessionStats.smoothedRtt, 'bigint'); +assert.strictEqual(typeof sessionStats.ssthresh, 'bigint'); +assert.strictEqual(typeof sessionStats.datagramsReceived, 'bigint'); +assert.strictEqual(typeof sessionStats.datagramsSent, 'bigint'); +assert.strictEqual(typeof sessionStats.datagramsAcknowledged, 'bigint'); +assert.strictEqual(typeof sessionStats.datagramsLost, 'bigint'); +assert.strictEqual(typeof sessionStats.toJSON(), 'object'); +assert.strictEqual(typeof inspect(sessionStats), 'string'); streamStats[kFinishClose](); diff --git a/test/parallel/test-quic-internal-setcallbacks.mjs b/test/parallel/test-quic-internal-setcallbacks.mjs index 4626b160aaec1a..88fb2624dd33f6 100644 --- a/test/parallel/test-quic-internal-setcallbacks.mjs +++ b/test/parallel/test-quic-internal-setcallbacks.mjs @@ -1,6 +1,6 @@ // Flags: --expose-internals --experimental-quic --no-warnings import { hasQuic, skip } from '../common/index.mjs'; -import { throws } from 'node:assert'; +import assert from 'node:assert'; if (!hasQuic) { skip('QUIC is not enabled'); @@ -30,7 +30,7 @@ const callbacks = { for (const fn of Object.keys(callbacks)) { // eslint-disable-next-line no-unused-vars const { [fn]: _, ...rest } = callbacks; - throws(() => quic.setCallbacks(rest), { + assert.throws(() => quic.setCallbacks(rest), { code: 'ERR_MISSING_ARGS', }); } diff --git a/test/parallel/test-quic-test-client.mjs b/test/parallel/test-quic-test-client.mjs index faf0238c2b659b..25918b17e8b96c 100644 --- a/test/parallel/test-quic-test-client.mjs +++ b/test/parallel/test-quic-test-client.mjs @@ -1,6 +1,6 @@ // Flags: --experimental-quic import { hasQuic, isAIX, isIBMi, isWindows, skip } from '../common/index.mjs'; -import { rejects } from 'node:assert'; +import assert from 'node:assert'; if (!hasQuic) { skip('QUIC support is not enabled'); @@ -33,5 +33,5 @@ setTimeout(() => { }, 100); // We expect this to fail since there's no server running. -await rejects(client.run('localhost', '12345', undefined, { stdio: 'ignore' }), - { message: /Process exited with code 1 and signal null/ }); +await assert.rejects(client.run('localhost', '12345', undefined, { stdio: 'ignore' }), + { message: /Process exited with code 1 and signal null/ });