diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index bbf9264c513137..2fa5b0e157a271 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -194,8 +194,8 @@ export default [ ].join(',')}}/**/*.{js,mjs,cjs}`, `test/parallel/test-{${ // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' - Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') - },http-*,http2-*,${ + Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') + },${ // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…' Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') }}.{js,mjs,cjs}`, diff --git a/test/parallel/test-h2leak-destroy-session-on-socket-ended.js b/test/parallel/test-h2leak-destroy-session-on-socket-ended.js index af692b278f7d06..3d733a4432f45e 100644 --- a/test/parallel/test-h2leak-destroy-session-on-socket-ended.js +++ b/test/parallel/test-h2leak-destroy-session-on-socket-ended.js @@ -69,9 +69,7 @@ function client() { rejectUnauthorized: false, ALPNProtocols: ['h2'] }, () => { - client.end(Buffer.concat(h2fstStream.map((s) => Buffer.from(s, 'base64'))), (err) => { - assert.ifError(err); - }); + client.end(Buffer.concat(h2fstStream.map((s) => Buffer.from(s, 'base64'))), common.mustSucceed()); }); client.on('error', (error) => { diff --git a/test/parallel/test-handle-wrap-hasref.js b/test/parallel/test-handle-wrap-hasref.js index f76194d0495781..327f0a64051dcc 100644 --- a/test/parallel/test-handle-wrap-hasref.js +++ b/test/parallel/test-handle-wrap-hasref.js @@ -2,7 +2,7 @@ 'use strict'; const common = require('../common'); -const strictEqual = require('assert').strictEqual; +const assert = require('assert'); const { internalBinding } = require('internal/test/binding'); // child_process @@ -10,17 +10,13 @@ const { internalBinding } = require('internal/test/binding'); const spawn = require('child_process').spawn; const cmd = common.isWindows ? 'rundll32' : 'ls'; const cp = spawn(cmd); - strictEqual(cp._handle.hasRef(), - true, 'process_wrap: not initially refed'); + assert.strictEqual(cp._handle.hasRef(), true); cp.unref(); - strictEqual(cp._handle.hasRef(), - false, 'process_wrap: unref() ineffective'); + assert.strictEqual(cp._handle.hasRef(), false); cp.ref(); - strictEqual(cp._handle.hasRef(), - true, 'process_wrap: ref() ineffective'); + assert.strictEqual(cp._handle.hasRef(), true); cp._handle.close(common.mustCall(() => - strictEqual(cp._handle.hasRef(), - false, 'process_wrap: not unrefed on close'))); + assert.strictEqual(cp._handle.hasRef(), false))); } @@ -32,17 +28,13 @@ const { kStateSymbol } = require('internal/dgram'); const sock4 = dgram.createSocket('udp4'); const handle = sock4[kStateSymbol].handle; - strictEqual(handle.hasRef(), - true, 'udp_wrap: ipv4: not initially refed'); + assert.strictEqual(handle.hasRef(), true); sock4.unref(); - strictEqual(handle.hasRef(), - false, 'udp_wrap: ipv4: unref() ineffective'); + assert.strictEqual(handle.hasRef(), false); sock4.ref(); - strictEqual(handle.hasRef(), - true, 'udp_wrap: ipv4: ref() ineffective'); + assert.strictEqual(handle.hasRef(), true); handle.close(common.mustCall(() => - strictEqual(handle.hasRef(), - false, 'udp_wrap: ipv4: not unrefed on close'))); + assert.strictEqual(handle.hasRef(), false))); } @@ -51,17 +43,13 @@ const { kStateSymbol } = require('internal/dgram'); const sock6 = dgram.createSocket('udp6'); const handle = sock6[kStateSymbol].handle; - strictEqual(handle.hasRef(), - true, 'udp_wrap: ipv6: not initially refed'); + assert.strictEqual(handle.hasRef(), true); sock6.unref(); - strictEqual(handle.hasRef(), - false, 'udp_wrap: ipv6: unref() ineffective'); + assert.strictEqual(handle.hasRef(), false); sock6.ref(); - strictEqual(handle.hasRef(), - true, 'udp_wrap: ipv6: ref() ineffective'); + assert.strictEqual(handle.hasRef(), true); handle.close(common.mustCall(() => - strictEqual(handle.hasRef(), - false, 'udp_wrap: ipv6: not unrefed on close'))); + assert.strictEqual(handle.hasRef(), false))); } @@ -69,17 +57,13 @@ const { kStateSymbol } = require('internal/dgram'); { const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap'); const handle = new Pipe(PipeConstants.SOCKET); - strictEqual(handle.hasRef(), - true, 'pipe_wrap: not initially refed'); + assert.strictEqual(handle.hasRef(), true); handle.unref(); - strictEqual(handle.hasRef(), - false, 'pipe_wrap: unref() ineffective'); + assert.strictEqual(handle.hasRef(), false); handle.ref(); - strictEqual(handle.hasRef(), - true, 'pipe_wrap: ref() ineffective'); + assert.strictEqual(handle.hasRef(), true); handle.close(common.mustCall(() => - strictEqual(handle.hasRef(), - false, 'pipe_wrap: not unrefed on close'))); + assert.strictEqual(handle.hasRef(), false))); } @@ -87,49 +71,42 @@ const { kStateSymbol } = require('internal/dgram'); { const net = require('net'); const server = net.createServer(() => {}).listen(0); - strictEqual(server._handle.hasRef(), - true, 'tcp_wrap: not initially refed'); - strictEqual(server._unref, - false, 'tcp_wrap: _unref initially incorrect'); + assert.strictEqual(server._handle.hasRef(), true); + assert.strictEqual(server._unref, false); server.unref(); - strictEqual(server._handle.hasRef(), - false, 'tcp_wrap: unref() ineffective'); - strictEqual(server._unref, - true, 'tcp_wrap: _unref not updated on unref()'); + assert.strictEqual(server._handle.hasRef(), false); + assert.strictEqual(server._unref, true); server.ref(); - strictEqual(server._handle.hasRef(), - true, 'tcp_wrap: ref() ineffective'); - strictEqual(server._unref, - false, 'tcp_wrap: _unref not updated on ref()'); + assert.strictEqual(server._handle.hasRef(), true); + assert.strictEqual(server._unref, false); server._handle.close(common.mustCall(() => - strictEqual(server._handle.hasRef(), - false, 'tcp_wrap: not unrefed on close'))); + assert.strictEqual(server._handle.hasRef(), false))); } // timers { - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Timeout').length, 0); const timeout = setTimeout(() => {}, 500); - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Timeout').length, 1); timeout.unref(); - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Timeout').length, 0); timeout.ref(); - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Timeout').length, 1); - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Immediate').length, 0); const immediate = setImmediate(() => {}); - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Immediate').length, 1); immediate.unref(); - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Immediate').length, 0); immediate.ref(); - strictEqual(process.getActiveResourcesInfo().filter( + assert.strictEqual(process.getActiveResourcesInfo().filter( (type) => type === 'Immediate').length, 1); } diff --git a/test/parallel/test-heapdump-async-hooks-init-promise.js b/test/parallel/test-heapdump-async-hooks-init-promise.js index 63b26843d1254e..5de40cb966f946 100644 --- a/test/parallel/test-heapdump-async-hooks-init-promise.js +++ b/test/parallel/test-heapdump-async-hooks-init-promise.js @@ -31,10 +31,10 @@ async_hooks.createHook({ if (promiseIds.includes(id)) createSnapshot(); }, - promiseResolve(id) { + promiseResolve: common.mustCallAtLeast((id) => { assert(promiseIds.includes(id)); createSnapshot(); - }, + }), destroy(id) { if (promiseIds.includes(id)) createSnapshot(); diff --git a/test/parallel/test-http.js b/test/parallel/test-http.js index 366fb42d1569d9..96fc358cb184a9 100644 --- a/test/parallel/test-http.js +++ b/test/parallel/test-http.js @@ -61,7 +61,7 @@ const server = http.Server(common.mustCall((req, res) => { }, 3)); server.listen(0); -server.on('listening', () => { +server.on('listening', common.mustCall(() => { const agent = new http.Agent({ port: server.address().port, maxSockets: 1 }); const req = http.get({ port: server.address().port, @@ -133,4 +133,4 @@ server.on('listening', () => { })); req.end(); }), 2); -}); +})); diff --git a/test/parallel/test-https-agent-create-connection.js b/test/parallel/test-https-agent-create-connection.js index 705a5f8bf709bc..56e967476c8b3a 100644 --- a/test/parallel/test-https-agent-create-connection.js +++ b/test/parallel/test-https-agent-create-connection.js @@ -19,7 +19,7 @@ const expectedHeader = /^HTTP\/1\.1 200 OK/; const expectedBody = /hello world\n/; const expectCertError = /^UNABLE_TO_VERIFY_LEAF_SIGNATURE$/; -const checkRequest = (socket, server) => { +function checkRequest(socket, server) { let result = ''; socket.on('connect', common.mustCall((data) => { socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n'); diff --git a/test/parallel/test-https-agent-keylog.js b/test/parallel/test-https-agent-keylog.js index 2fc13cbe6d8549..dc6fbfa2ab9ccb 100644 --- a/test/parallel/test-https-agent-keylog.js +++ b/test/parallel/test-https-agent-keylog.js @@ -36,9 +36,9 @@ const server = https.createServer({ }); }); -const verifyKeylog = (line, tlsSocket) => { +const verifyKeylog = common.mustCallAtLeast((line, tlsSocket) => { assert(Buffer.isBuffer(line)); assert.strictEqual(tlsSocket.encrypted, true); -}; +}); server.on('keylog', common.mustCall(verifyKeylog, 10)); https.globalAgent.on('keylog', common.mustCall(verifyKeylog, 10)); diff --git a/test/parallel/test-https-agent-servername.js b/test/parallel/test-https-agent-servername.js index aa3f75894b8e64..2d4c966eae7914 100644 --- a/test/parallel/test-https-agent-servername.js +++ b/test/parallel/test-https-agent-servername.js @@ -21,19 +21,16 @@ const server = https.Server(options, (req, res) => { }); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { https.get({ path: '/', port: this.address().port, rejectUnauthorized: true, servername: 'agent1', ca: options.ca - }, (res) => { + }, common.mustCall((res) => { res.resume(); assert.strictEqual(res.statusCode, 200); server.close(); - }).on('error', (e) => { - console.log(e.message); - process.exit(1); - }); -}); + })).on('error', common.mustNotCall()); +})); diff --git a/test/parallel/test-https-agent-sni.js b/test/parallel/test-https-agent-sni.js index 1ddeff7ce205d9..6809f237a2fb2e 100644 --- a/test/parallel/test-https-agent-sni.js +++ b/test/parallel/test-https-agent-sni.js @@ -27,7 +27,7 @@ const server = https.Server(options, function(req, res) { res.end('hello world'); }); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { function expectResponse(id) { return common.mustCall(function(res) { res.resume(); @@ -59,4 +59,4 @@ server.listen(0, function() { servername: '', rejectUnauthorized: false }, expectResponse(false)); -}); +})); diff --git a/test/parallel/test-https-agent-unref-socket.js b/test/parallel/test-https-agent-unref-socket.js index 49169b523e1042..ac97ab98d420c8 100644 --- a/test/parallel/test-https-agent-unref-socket.js +++ b/test/parallel/test-https-agent-unref-socket.js @@ -17,13 +17,13 @@ if (process.argv[2] === 'localhost') { const net = require('net'); const server = net.createServer(); server.listen(0); - server.on('listening', () => { + server.on('listening', common.mustCall(() => { const port = server.address().port; const { fork } = require('child_process'); const child = fork(__filename, ['localhost', port], {}); - child.on('close', (exit_code) => { + child.on('close', common.mustCall((exit_code) => { server.close(); assert.strictEqual(exit_code, 0); - }); - }); + })); + })); } diff --git a/test/parallel/test-https-agent.js b/test/parallel/test-https-agent.js index ce4bc6e5bdb86b..e3c1e200e9de5f 100644 --- a/test/parallel/test-https-agent.js +++ b/test/parallel/test-https-agent.js @@ -46,25 +46,23 @@ const N = 4; const M = 4; -server.listen(0, () => { +server.listen(0, common.mustCall(() => { for (let i = 0; i < N; i++) { - setTimeout(() => { + setTimeout(common.mustCall(() => { for (let j = 0; j < M; j++) { https.get({ path: '/', port: server.address().port, rejectUnauthorized: false - }, function(res) { + }, common.mustCall((res) => { res.resume(); assert.strictEqual(res.statusCode, 200); if (++responses === N * M) server.close(); - }).on('error', (e) => { - throw e; - }); + })).on('error', common.mustNotCall()); } - }, i); + }), i); } -}); +})); process.on('exit', () => { diff --git a/test/parallel/test-https-autoselectfamily.js b/test/parallel/test-https-autoselectfamily.js index 21df1654538002..5734d5aa7d932d 100644 --- a/test/parallel/test-https-autoselectfamily.js +++ b/test/parallel/test-https-autoselectfamily.js @@ -25,7 +25,7 @@ const options = { // Test that happy eyeballs algorithm is properly implemented when using HTTP. function _lookup(resolver, hostname, options, cb) { - resolver.resolve(hostname, 'ANY', (err, replies) => { + resolver.resolve(hostname, 'ANY', common.mustCall((err, replies) => { assert.notStrictEqual(options.family, 4); if (err) { @@ -41,7 +41,7 @@ function _lookup(resolver, hostname, options, cb) { } return cb(null, hosts[0].address, hosts[0].family); - }); + })); } function createDnsServer(ipv6Addr, ipv4Addr, cb) { @@ -89,7 +89,7 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) { autoSelectFamily: true, servername: 'example.org', }, - (res) => { + common.mustCall((res) => { assert.strictEqual(res.statusCode, 200); res.setEncoding('utf-8'); @@ -104,7 +104,7 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) { ipv4Server.close(); dnsServer.close(); })); - } + }) ).end(); })); })); @@ -113,11 +113,7 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) { // Test that IPV4 is NOT reached if IPV6 is reachable if (common.hasIPv6) { createDnsServer('::1', '127.0.0.1', common.mustCall(function({ dnsServer, lookup }) { - const ipv4Server = createServer(options, common.mustNotCall((req, res) => { - assert.strictEqual(req.socket.servername, 'example.org'); - res.writeHead(200, { Connection: 'close' }); - res.end('response-ipv4'); - })); + const ipv4Server = createServer(options, common.mustNotCall()); const ipv6Server = createServer(options, common.mustCall((req, res) => { assert.strictEqual(req.socket.servername, 'example.org'); @@ -137,7 +133,7 @@ if (common.hasIPv6) { autoSelectFamily: true, servername: 'example.org', }, - (res) => { + common.mustCall((res) => { assert.strictEqual(res.statusCode, 200); res.setEncoding('utf-8'); @@ -153,7 +149,7 @@ if (common.hasIPv6) { ipv6Server.close(); dnsServer.close(); })); - } + }) ).end(); })); })); diff --git a/test/parallel/test-https-byteswritten.js b/test/parallel/test-https-byteswritten.js index 8ce0f7d8225033..5251393a39acd6 100644 --- a/test/parallel/test-https-byteswritten.js +++ b/test/parallel/test-https-byteswritten.js @@ -35,16 +35,16 @@ const options = { const body = 'hello world\n'; -const httpsServer = https.createServer(options, function(req, res) { - res.on('finish', function() { +const httpsServer = https.createServer(options, common.mustCallAtLeast((req, res) => { + res.on('finish', common.mustCall(() => { assert.strictEqual(typeof req.connection.bytesWritten, 'number'); assert(req.connection.bytesWritten > 0); httpsServer.close(); console.log('ok'); - }); + })); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(body); -}); +})); httpsServer.listen(0, function() { https.get({ diff --git a/test/parallel/test-https-client-checkServerIdentity.js b/test/parallel/test-https-client-checkServerIdentity.js index 87c9ec8229f30a..18a6c121cb5423 100644 --- a/test/parallel/test-https-client-checkServerIdentity.js +++ b/test/parallel/test-https-client-checkServerIdentity.js @@ -63,10 +63,10 @@ function override() { } }; options.agent = new https.Agent(options); - const req = https.request(options, function(res) { + const req = https.request(options, common.mustCall((res) => { assert(req.socket.authorized); server.close(); - }); + })); req.on('error', function(err) { throw err; }); diff --git a/test/parallel/test-https-client-reject.js b/test/parallel/test-https-client-reject.js index 113b56fda66fe4..4272ab0d1a6dbd 100644 --- a/test/parallel/test-https-client-reject.js +++ b/test/parallel/test-https-client-reject.js @@ -46,11 +46,11 @@ function unauthorized() { const req = https.request({ port: server.address().port, rejectUnauthorized: false - }, function(res) { + }, common.mustCall((res) => { assert(!req.socket.authorized); res.resume(); rejectUnauthorized(); - }); + })); req.on('error', function(err) { throw err; }); @@ -75,11 +75,11 @@ function authorized() { ca: [fixtures.readKey('rsa_cert.crt')] }; options.agent = new https.Agent(options); - const req = https.request(options, function(res) { + const req = https.request(options, common.mustCall((res) => { res.resume(); assert(req.socket.authorized); server.close(); - }); + })); req.on('error', common.mustNotCall()); req.end(); } diff --git a/test/parallel/test-https-client-renegotiation-limit.js b/test/parallel/test-https-client-renegotiation-limit.js index d96ba416240000..6614090e737614 100644 --- a/test/parallel/test-https-client-renegotiation-limit.js +++ b/test/parallel/test-https-client-renegotiation-limit.js @@ -52,17 +52,17 @@ function test(next) { key: fixtures.readKey('rsa_private.pem'), }; - const server = https.createServer(options, (req, res) => { + const server = https.createServer(options, common.mustCallAtLeast((req, res) => { const conn = req.connection; - conn.on('error', (err) => { + conn.on('error', common.mustCallAtLeast((err) => { console.error(`Caught exception: ${err}`); assert.match(err.message, /TLS session renegotiation attack/); conn.destroy(); - }); + })); res.end('ok'); - }); + })); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const agent = https.Agent({ keepAlive: true, }); @@ -77,15 +77,15 @@ function test(next) { const { port } = server.address(); - https.get(`https://localhost:${port}/`, options, (res) => { + https.get(`https://localhost:${port}/`, options, common.mustCall((res) => { client = res.socket; - client.on('close', (hadErr) => { + client.on('close', common.mustCall((hadErr) => { assert.strictEqual(hadErr, false); assert.strictEqual(renegs, tls.CLIENT_RENEG_LIMIT + 1); server.close(); process.nextTick(next); - }); + })); client.on('error', (err) => { console.log('CLIENT ERR', err); @@ -96,14 +96,14 @@ function test(next) { // Simulate renegotiation attack function spam() { - client.renegotiate({}, (err) => { + client.renegotiate({}, common.mustCallAtLeast((err) => { assert.ifError(err); assert.ok(renegs <= tls.CLIENT_RENEG_LIMIT); setImmediate(spam); - }); + }, 0)); renegs++; } - }); + })); - }); + })); } diff --git a/test/parallel/test-https-drain.js b/test/parallel/test-https-drain.js index 1c8a29258f26f6..5d7bf973645890 100644 --- a/test/parallel/test-https-drain.js +++ b/test/parallel/test-https-drain.js @@ -42,13 +42,13 @@ const server = https.createServer(options, function(req, res) { req.pipe(res); }); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { let resumed = false; const req = https.request({ method: 'POST', port: this.address().port, rejectUnauthorized: false - }, function(res) { + }, common.mustCall((res) => { let timer; res.pause(); console.error('paused'); @@ -69,7 +69,7 @@ server.listen(0, function() { }, 1000); } - res.on('data', function(data) { + res.on('data', common.mustCallAtLeast(function(data) { assert.ok(resumed); if (timer) { clearTimeout(timer); @@ -81,11 +81,11 @@ server.listen(0, function() { req.end(); server.close(); } - }); - }); + })); + })); req.write('a'); ++sent; -}); +})); process.on('exit', function() { assert.strictEqual(sent, received); diff --git a/test/parallel/test-https-foafssl.js b/test/parallel/test-https-foafssl.js index ec009c6a768185..ffa44f218b935d 100644 --- a/test/parallel/test-https-foafssl.js +++ b/test/parallel/test-https-foafssl.js @@ -63,7 +63,7 @@ const server = https.createServer(options, common.mustCall(function(req, res) { console.log('sent response'); })); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { const args = ['s_client', '-quiet', '-connect', `127.0.0.1:${this.address().port}`, @@ -72,21 +72,20 @@ server.listen(0, function() { const client = spawn(opensslCli, args); - client.stdout.on('data', function(data) { + client.stdout.on('data', common.mustCallAtLeast((data) => { console.log('response received'); const message = data.toString(); const contents = message.split('\r\n\r\n').pop(); assert.strictEqual(body, contents); - server.close((e) => { - assert.ifError(e); + server.close(common.mustSucceed(() => { console.log('server closed'); - }); + })); console.log('server.close() called'); - }); + })); client.stdin.write('GET /\r\n\r\n'); client.on('error', function(error) { throw error; }); -}); +})); diff --git a/test/parallel/test-https-localaddress.js b/test/parallel/test-https-localaddress.js index 2a4629b34e4105..bd459df614b5ee 100644 --- a/test/parallel/test-https-localaddress.js +++ b/test/parallel/test-https-localaddress.js @@ -39,7 +39,7 @@ const options = { cert: fixtures.readKey('agent1-cert.pem') }; -const server = https.createServer(options, function(req, res) { +const server = https.createServer(options, common.mustCallAtLeast((req, res) => { console.log(`Connect from: ${req.connection.remoteAddress}`); assert.strictEqual(req.connection.remoteAddress, '127.0.0.2'); @@ -48,7 +48,7 @@ const server = https.createServer(options, function(req, res) { res.end(`You are from: ${req.connection.remoteAddress}`); }); req.resume(); -}); +})); server.listen(0, '127.0.0.1', function() { const options = { diff --git a/test/parallel/test-https-max-headers-count.js b/test/parallel/test-https-max-headers-count.js index 6b188b0780eb7c..cffde90114ff47 100644 --- a/test/parallel/test-https-max-headers-count.js +++ b/test/parallel/test-https-max-headers-count.js @@ -57,7 +57,7 @@ server.listen(0, common.mustCall(() => { port: server.address().port, headers: headers, rejectUnauthorized: false - }, (res) => { + }, common.mustCall((res) => { assert.strictEqual(Object.keys(res.headers).length, expected); res.on('end', () => { if (++responses < maxAndExpected.length) { @@ -67,7 +67,7 @@ server.listen(0, common.mustCall(() => { } }); res.resume(); - }); + })); req.maxHeadersCount = max; req.end(); }, 3); diff --git a/test/parallel/test-https-pfx.js b/test/parallel/test-https-pfx.js index 4246913a037ec1..3c0aa82b3dbed2 100644 --- a/test/parallel/test-https-pfx.js +++ b/test/parallel/test-https-pfx.js @@ -42,13 +42,13 @@ const options = { rejectUnauthorized: false }; -const server = https.createServer(options, function(req, res) { +const server = https.createServer(options, common.mustCallAtLeast((req, res) => { assert.strictEqual(req.socket.authorized, false); // not a client cert assert.strictEqual(req.socket.authorizationError, 'DEPTH_ZERO_SELF_SIGNED_CERT'); res.writeHead(200); res.end('OK'); -}); +})); server.listen(0, options.host, common.mustCall(function() { options.port = this.address().port; diff --git a/test/parallel/test-https-selfsigned-no-keycertsign-no-crash.js b/test/parallel/test-https-selfsigned-no-keycertsign-no-crash.js index 2dd46ac878c5b0..667be03d58cefc 100644 --- a/test/parallel/test-https-selfsigned-no-keycertsign-no-crash.js +++ b/test/parallel/test-https-selfsigned-no-keycertsign-no-crash.js @@ -45,7 +45,7 @@ const httpsServer = https.createServer(serverOptions, (req, res) => { }); httpsServer.listen(0); -httpsServer.on('listening', () => { +httpsServer.on('listening', common.mustCall(() => { // Once the server started listening, built the client config // with the server´s used port const clientOptions = { @@ -60,4 +60,4 @@ httpsServer.on('listening', () => { req.on('error', common.mustNotCall()); req.end(); -}); +})); diff --git a/test/parallel/test-https-server-close-all.js b/test/parallel/test-https-server-close-all.js index 170d95db8f919e..a5ffadf7c98c72 100644 --- a/test/parallel/test-https-server-close-all.js +++ b/test/parallel/test-https-server-close-all.js @@ -31,7 +31,7 @@ server.on('connection', function() { connections++; }); -server.listen(0, function() { +server.listen(0, common.mustCall(() => { const port = server.address().port; // Create a first request but never finish it @@ -68,4 +68,4 @@ server.listen(0, function() { client1.on('error', () => {}); client1.write('GET / HTTP/1.1'); -}); +})); diff --git a/test/parallel/test-https-server-close-idle.js b/test/parallel/test-https-server-close-idle.js index 9a9f3758746181..9cbf67b974063d 100644 --- a/test/parallel/test-https-server-close-idle.js +++ b/test/parallel/test-https-server-close-idle.js @@ -31,7 +31,7 @@ server.on('connection', function() { connections++; }); -server.listen(0, function() { +server.listen(0, common.mustCall(() => { const port = server.address().port; let client1Closed = false; let client2Closed = false; @@ -79,4 +79,4 @@ server.listen(0, function() { client1.on('error', () => {}); client1.write('GET / HTTP/1.1'); -}); +})); diff --git a/test/parallel/test-https-server-options-incoming-message.js b/test/parallel/test-https-server-options-incoming-message.js index 102ee56751b800..c69fde05778634 100644 --- a/test/parallel/test-https-server-options-incoming-message.js +++ b/test/parallel/test-https-server-options-incoming-message.js @@ -34,18 +34,18 @@ const server = https.createServer({ })); server.listen(); -server.on('listening', function makeRequest() { +server.on('listening', common.mustCall(function makeRequest() { https.get({ port: this.address().port, rejectUnauthorized: false, headers: { 'User-Agent': 'node-test' } - }, (res) => { + }, common.mustCall((res) => { assert.strictEqual(res.statusCode, 200); res.on('end', () => { server.close(); }); res.resume(); - }); -}); + })); +})); diff --git a/test/parallel/test-https-server-options-server-response.js b/test/parallel/test-https-server-options-server-response.js index 8745415f8b6596..49563104d714b2 100644 --- a/test/parallel/test-https-server-options-server-response.js +++ b/test/parallel/test-https-server-options-server-response.js @@ -33,15 +33,15 @@ const server = https.createServer({ })); server.listen(); -server.on('listening', function makeRequest() { +server.on('listening', common.mustCall(function makeRequest() { https.get({ port: this.address().port, rejectUnauthorized: false - }, (res) => { + }, common.mustCall((res) => { assert.strictEqual(res.statusCode, 200); res.on('end', () => { server.close(); }); res.resume(); - }); -}); + })); +})); diff --git a/test/parallel/test-https-set-timeout-server.js b/test/parallel/test-https-set-timeout-server.js index c67155e9d53143..e1b833611a1f61 100644 --- a/test/parallel/test-https-set-timeout-server.js +++ b/test/parallel/test-https-set-timeout-server.js @@ -139,7 +139,7 @@ test(function serverResponseTimeoutWithPipeline(cb) { process.on('exit', () => { assert.strictEqual(caughtTimeout, '/2'); }); - const server = https.createServer(serverOptions, (req, res) => { + const server = https.createServer(serverOptions, common.mustCallAtLeast((req, res) => { if (req.url === '/2') secReceived = true; if (req.url === '/1') { @@ -150,7 +150,7 @@ test(function serverResponseTimeoutWithPipeline(cb) { caughtTimeout += req.url; }); assert.ok(s instanceof http.OutgoingMessage); - }); + })); server.on('timeout', common.mustCall((socket) => { if (secReceived) { socket.destroy(); diff --git a/test/parallel/test-https-timeout-server-2.js b/test/parallel/test-https-timeout-server-2.js index f4c423ec4a5b72..4f947039bbe8a7 100644 --- a/test/parallel/test-https-timeout-server-2.js +++ b/test/parallel/test-https-timeout-server-2.js @@ -37,13 +37,13 @@ const options = { const server = https.createServer(options, common.mustNotCall()); -server.on('secureConnection', function(cleartext) { +server.on('secureConnection', common.mustCall((cleartext) => { const s = cleartext.setTimeout(50, function() { cleartext.destroy(); server.close(); }); assert.ok(s instanceof tls.TLSSocket); -}); +})); server.listen(0, function() { tls.connect({ diff --git a/test/parallel/test-inspect-address-in-use.js b/test/parallel/test-inspect-address-in-use.js index eb076b21c9beaa..d900fdfb679530 100644 --- a/test/parallel/test-inspect-address-in-use.js +++ b/test/parallel/test-inspect-address-in-use.js @@ -23,7 +23,7 @@ function testOnServerListen(fn) { } function testChildProcess(getArgs, exitCode, options) { - testOnServerListen((server) => { + testOnServerListen(common.mustCall((server) => { const { port } = server.address(); const child = spawnSync(process.execPath, getArgs(port), options); const stderr = child.stderr.toString().trim(); @@ -38,7 +38,7 @@ function testChildProcess(getArgs, exitCode, options) { assert.notStrictEqual(match, null); assert.strictEqual(match[1], port + ''); assert.strictEqual(child.status, exitCode); - }); + })); } tmpdir.refresh(); @@ -50,7 +50,7 @@ testChildProcess( testChildProcess( (port) => [`--inspect=${port}`, entry], 0); -testOnServerListen((server) => { +testOnServerListen(common.mustCall((server) => { const { port } = server.address(); const worker = new Worker(entry, { execArgv: [`--inspect=${port}`] @@ -61,4 +61,4 @@ testOnServerListen((server) => { worker.on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); })); -}); +})); diff --git a/test/parallel/test-inspect-publish-uid.js b/test/parallel/test-inspect-publish-uid.js index 32550ddb66983a..220ccab54e61ef 100644 --- a/test/parallel/test-inspect-publish-uid.js +++ b/test/parallel/test-inspect-publish-uid.js @@ -34,9 +34,9 @@ async function testArg(argValue) { function scriptMain(code) { const url = require('inspector').url(); const { host } = require('url').parse(url); - require('http').get('http://' + host + '/json/list', (response) => { + require('http').get('http://' + host + '/json/list', common.mustCall((response) => { assert.strictEqual(response.statusCode, code); response.destroy(); - }); + })); } } diff --git a/test/parallel/test-inspector-async-call-stack-abort.js b/test/parallel/test-inspector-async-call-stack-abort.js index 64eb2bd0ac8974..275ac67320f241 100644 --- a/test/parallel/test-inspector-async-call-stack-abort.js +++ b/test/parallel/test-inspector-async-call-stack-abort.js @@ -5,7 +5,7 @@ const common = require('../common'); common.skipIfInspectorDisabled(); common.skipIf32Bits(); -const { strictEqual } = require('assert'); +const assert = require('assert'); const eyecatcher = 'nou, houdoe he?'; if (process.argv[2] === 'child') { @@ -20,9 +20,9 @@ if (process.argv[2] === 'child') { session.connect(); session.post = promisify(session.post); await session.post('Debugger.enable'); - strictEqual(enabled, 0); + assert.strictEqual(enabled, 0); await session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 42 }); - strictEqual(enabled, 1); + assert.strictEqual(enabled, 1); throw new Error(eyecatcher); })().finally(common.mustCall()); } else { @@ -30,7 +30,7 @@ if (process.argv[2] === 'child') { const options = { encoding: 'utf8' }; const proc = spawnSync( process.execPath, ['--expose-internals', __filename, 'child'], options); - strictEqual(proc.status, 1); - strictEqual(proc.signal, null); - strictEqual(proc.stderr.includes(eyecatcher), true); + assert.strictEqual(proc.status, 1); + assert.strictEqual(proc.signal, null); + assert.strictEqual(proc.stderr.includes(eyecatcher), true); } diff --git a/test/parallel/test-inspector-async-hook-after-done.js b/test/parallel/test-inspector-async-hook-after-done.js index b49fe32982e132..f9cd7b49136042 100644 --- a/test/parallel/test-inspector-async-hook-after-done.js +++ b/test/parallel/test-inspector-async-hook-after-done.js @@ -57,12 +57,12 @@ session.connect(); session.on('NodeWorker.attachedToWorker', common.mustCall(onAttachToWorker)); -session.post('NodeWorker.enable', { waitForDebuggerOnStart: true }, () => { +session.post('NodeWorker.enable', { waitForDebuggerOnStart: true }, common.mustCall(() => { new Worker('console.log("Worker is done")', { eval: true }) - .once('exit', () => { - setTimeout(() => { + .once('exit', common.mustCall(() => { + setTimeout(common.mustCall(() => { assert.strictEqual(done, true); console.log('Test is done'); - }, 0); - }); -}); + }), 0); + })); +})); diff --git a/test/parallel/test-inspector-debug-end.js b/test/parallel/test-inspector-debug-end.js index bb63bceb150645..328f15628e3c6a 100644 --- a/test/parallel/test-inspector-debug-end.js +++ b/test/parallel/test-inspector-debug-end.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); common.skipIfInspectorDisabled(); -const { strictEqual } = require('assert'); +const assert = require('assert'); const { NodeInstance } = require('../common/inspector-helper.js'); async function testNoServerNoCrash() { @@ -9,14 +9,14 @@ async function testNoServerNoCrash() { const instance = new NodeInstance([], `process._debugEnd(); process.exit(42);`); - strictEqual((await instance.expectShutdown()).exitCode, 42); + assert.strictEqual((await instance.expectShutdown()).exitCode, 42); } async function testNoSessionNoCrash() { console.log('Test there\'s no crash stopping server without connecting'); const instance = new NodeInstance('--inspect=0', 'process._debugEnd();process.exit(42);'); - strictEqual((await instance.expectShutdown()).exitCode, 42); + assert.strictEqual((await instance.expectShutdown()).exitCode, 42); } async function testSessionNoCrash() { @@ -34,7 +34,7 @@ async function testSessionNoCrash() { await session.waitForNotification('NodeRuntime.waitingForDebugger'); await session.send({ 'method': 'Runtime.runIfWaitingForDebugger' }); await session.waitForServerDisconnect(); - strictEqual((await instance.expectShutdown()).exitCode, 42); + assert.strictEqual((await instance.expectShutdown()).exitCode, 42); } async function runTest() { diff --git a/test/parallel/test-inspector-emit-protocol-event.js b/test/parallel/test-inspector-emit-protocol-event.js index 3125287c3a53d5..bffea8c1cd867e 100644 --- a/test/parallel/test-inspector-emit-protocol-event.js +++ b/test/parallel/test-inspector-emit-protocol-event.js @@ -140,7 +140,7 @@ for (const [domain, events] of Object.entries(EXPECTED_EVENTS)) { } } -const runAsyncTest = async () => { +(async () => { const session = new inspector.Session(); session.connect(); @@ -167,8 +167,4 @@ const runAsyncTest = async () => { await session.post('Network.disable'); session.on('Network.requestWillBeSent', common.mustNotCall()); inspector.Network.requestWillBeSent({}); -}; - -runAsyncTest().then(common.mustCall()).catch((e) => { - assert.fail(e); -}); +})().then(common.mustCall()); diff --git a/test/parallel/test-inspector-heap-allocation-tracker.js b/test/parallel/test-inspector-heap-allocation-tracker.js index 0003a8fb694f1d..4002d15b3c162c 100644 --- a/test/parallel/test-inspector-heap-allocation-tracker.js +++ b/test/parallel/test-inspector-heap-allocation-tracker.js @@ -15,11 +15,11 @@ session.post('HeapProfiler.startTrackingHeapObjects', { trackAllocations: true }); // Perform some silly heap allocations for the next 100 ms. -const interval = setInterval(() => { +const interval = setInterval(common.mustCallAtLeast(() => { new stream.PassThrough().end('abc').on('data', common.mustCall()); -}, 1); +}), 1); -setTimeout(() => { +setTimeout(common.mustCall(() => { clearInterval(interval); // Once the main test is done, we re-run it from inside a Worker thread @@ -43,4 +43,4 @@ setTimeout(() => { assert(data.includes('PassThrough'), data); new Worker(__filename, { workerData: 'stopEarly' }); -}, 100); +}), 100); diff --git a/test/parallel/test-inspector-invalid-protocol.js b/test/parallel/test-inspector-invalid-protocol.js index 28c02028aed472..53ef9b3c0f62d0 100644 --- a/test/parallel/test-inspector-invalid-protocol.js +++ b/test/parallel/test-inspector-invalid-protocol.js @@ -22,9 +22,9 @@ const assert = require('node:assert'); }); }); - child.once('exit', (_, signal) => { + child.once('exit', common.mustCall((_, signal) => { assert.strictEqual(signal, 'SIGTERM'); - }); + })); const socket = new WebSocket(url); diff --git a/test/parallel/test-inspector-network-content-type.js b/test/parallel/test-inspector-network-content-type.js index c8744e521fc5ec..b6ed579533e9c5 100644 --- a/test/parallel/test-inspector-network-content-type.js +++ b/test/parallel/test-inspector-network-content-type.js @@ -8,7 +8,7 @@ const assert = require('node:assert'); const http = require('node:http'); const inspector = require('node:inspector/promises'); -const testNetworkInspection = async (session, port, assert) => { +const testNetworkInspection = common.mustCallAtLeast(async (session, port, assert) => { let assertPromise = assert(session); fetch(`http://127.0.0.1:${port}/hello-world`).then(common.mustCall()); await assertPromise; @@ -31,7 +31,7 @@ const testNetworkInspection = async (session, port, assert) => { }); await assertPromise; session.removeAllListeners(); -}; +}); const test = (handleRequest, testSessionFunc) => new Promise((resolve) => { const session = new inspector.Session(); diff --git a/test/parallel/test-inspector-network-data-received.js b/test/parallel/test-inspector-network-data-received.js index e9c0208b75986d..6aa2f68b0486f9 100644 --- a/test/parallel/test-inspector-network-data-received.js +++ b/test/parallel/test-inspector-network-data-received.js @@ -118,11 +118,11 @@ test('should stream Network.dataReceived with data chunks', async () => { totalDataLength += data.byteLength; chunks.push(data); }); - session.on('Network.dataReceived', ({ params }) => { + session.on('Network.dataReceived', common.mustCallAtLeast(({ params }) => { assert.strictEqual(params.requestId, requestId); totalDataLength += params.dataLength; chunks.push(Buffer.from(params.data, 'base64')); - }); + })); await triggerNetworkEvents(requestId); await responseReceivedFuture; diff --git a/test/parallel/test-inspector-network-fetch.js b/test/parallel/test-inspector-network-fetch.js index 02d6b584fbcfd3..790446c84bfb66 100644 --- a/test/parallel/test-inspector-network-fetch.js +++ b/test/parallel/test-inspector-network-fetch.js @@ -40,7 +40,7 @@ const setResponseHeaders = (res) => { res.setHeader('Content-Type', 'text/plain; charset=utf-8'); }; -const handleRequest = (req, res) => { +const handleRequest = common.mustCallAtLeast((req, res) => { const path = req.url; switch (path) { case '/hello-world': { @@ -49,17 +49,17 @@ const handleRequest = (req, res) => { req.on('data', (chunk) => { chunks.push(chunk); }); - req.on('end', () => { + req.on('end', common.mustCall(() => { assert.strictEqual(Buffer.concat(chunks).toString(), 'foobar'); res.writeHead(200); res.end('hello world\n'); - }); + })); break; } default: - assert(false, `Unexpected path: ${path}`); + assert.fail(`Unexpected path: ${path}`); } -}; +}); const httpServer = http.createServer(handleRequest); diff --git a/test/parallel/test-inspector-network-http.js b/test/parallel/test-inspector-network-http.js index 74c6488ef399a5..3f0014f2459253 100644 --- a/test/parallel/test-inspector-network-http.js +++ b/test/parallel/test-inspector-network-http.js @@ -47,7 +47,7 @@ const handleRequest = (req, res) => { }, kTimeout); break; default: - assert(false, `Unexpected path: ${path}`); + assert.fail(`Unexpected path: ${path}`); } }; @@ -138,12 +138,12 @@ function verifyHttpResponse(response) { assert.strictEqual(response.readableFlowing, null); // Verifies that the data listener may be added at a later time, and it can // still observe the data in full. - queueMicrotask(() => { + queueMicrotask(common.mustCall(() => { response.on('data', (chunk) => { chunks.push(chunk); }); assert.strictEqual(response.readableFlowing, true); - }); + })); response.on('end', common.mustCall(() => { const body = Buffer.concat(chunks).toString(); diff --git a/test/parallel/test-inspector-network-http2.js b/test/parallel/test-inspector-network-http2.js index 9c29fc219273b5..c24719a485ee1d 100644 --- a/test/parallel/test-inspector-network-http2.js +++ b/test/parallel/test-inspector-network-http2.js @@ -63,7 +63,7 @@ const serverResponse = 'hello world\n'; const kTimeout = 1000; const kDelta = 200; -const handleStream = (stream, headers) => { +const handleStream = common.mustCallAtLeast((stream, headers) => { const path = headers[http2.constants.HTTP2_HEADER_PATH]; let body = ''; switch (path) { @@ -72,7 +72,7 @@ const handleStream = (stream, headers) => { body += chunk; }); - stream.on('end', () => { + stream.on('end', common.mustCall(() => { assert.strictEqual(body, JSON.stringify(requestBody)); stream.pushStream(pushRequestHeaders, common.mustSucceed((pushStream) => { @@ -85,7 +85,7 @@ const handleStream = (stream, headers) => { setTimeout(() => { stream.end(serverResponse); }, kTimeout); - }); + })); break; case '/trigger-error': stream.close(http2.constants.NGHTTP2_STREAM_CLOSED); @@ -98,7 +98,7 @@ const handleStream = (stream, headers) => { default: assert(false, `Unexpected path: ${path}`); } -}; +}); const http2Server = http2.createServer(); diff --git a/test/parallel/test-inspector-open.js b/test/parallel/test-inspector-open.js index 93a2c74a0e4156..7c2adc14748af4 100644 --- a/test/parallel/test-inspector-open.js +++ b/test/parallel/test-inspector-open.js @@ -54,11 +54,11 @@ function tryToOpenWhenOpen(msg) { function closeWhenOpen(msg) { assert.strictEqual(msg.cmd, 'url'); assert.strictEqual(msg.url, undefined); - ping(firstPort, (err) => { + ping(firstPort, common.mustCall((err) => { assert(err); child.send({ cmd: 'close' }); child.once('message', common.mustCall(tryToCloseWhenClosed)); - }); + })); } function tryToCloseWhenClosed(msg) { @@ -92,7 +92,7 @@ function beChild() { process.send({ cmd: 'started' }); - process.on('message', (msg) => { + process.on('message', common.mustCall((msg) => { if (msg.cmd === 'open') { if (msg.args[0] === kFirstOpen) { inspector.open(0, false, undefined); @@ -110,5 +110,5 @@ function beChild() { inspector.close(); } process.send({ cmd: 'url', url: inspector.url() }); - }); + })); } diff --git a/test/parallel/test-inspector-overwrite-config.js b/test/parallel/test-inspector-overwrite-config.js index 53599b31df8acc..a487f72dfd5481 100644 --- a/test/parallel/test-inspector-overwrite-config.js +++ b/test/parallel/test-inspector-overwrite-config.js @@ -26,13 +26,13 @@ let asserted = false; async function testConsoleLog() { const session = new inspector.Session(); session.connect(); - session.on('inspectorNotification', (data) => { + session.on('inspectorNotification', common.mustCallAtLeast((data) => { if (data.method === 'Runtime.consoleAPICalled') { assert.strictEqual(data.params.args.length, 1); assert.strictEqual(data.params.args[0].value, msg); asserted = true; } - }); + })); session.post('Runtime.enable'); console.log(msg); session.disconnect(); diff --git a/test/parallel/test-inspector-port-zero.js b/test/parallel/test-inspector-port-zero.js index 3f55e2777cc39d..d49a30cdcd8d1a 100644 --- a/test/parallel/test-inspector-port-zero.js +++ b/test/parallel/test-inspector-port-zero.js @@ -1,5 +1,5 @@ 'use strict'; -const { mustCall, skipIfInspectorDisabled } = require('../common'); +const { mustCall, skipIfInspectorDisabled, mustCallAtLeast } = require('../common'); skipIfInspectorDisabled(); @@ -15,24 +15,24 @@ function test(arg, port = '') { let stderr = ''; proc.stdout.on('data', (data) => stdout += data); proc.stderr.on('data', (data) => stderr += data); - proc.stdout.on('close', (hadErr) => assert(!hadErr)); - proc.stderr.on('close', (hadErr) => assert(!hadErr)); - proc.stderr.on('data', () => { + proc.stdout.on('close', mustCall((hadErr) => assert(!hadErr))); + proc.stderr.on('close', mustCall((hadErr) => assert(!hadErr))); + proc.stderr.on('data', mustCallAtLeast(() => { if (!stderr.includes('\n')) return; assert.match(stderr, /Debugger listening on (.+)/); port = new URL(RegExp.$1).port; assert(+port > 0); - }); + }, 0)); if (/inspect-brk/.test(arg)) { proc.stderr.on('data', () => { if (stderr.includes('\n') && !proc.killed) proc.kill(); }); } else { - let onclose = () => { - onclose = () => assert.strictEqual(port, stdout.trim()); - }; - proc.stdout.on('close', mustCall(() => onclose())); - proc.stderr.on('close', mustCall(() => onclose())); + let onclose = mustCall(() => { + onclose = mustCall(() => assert.strictEqual(port, stdout.trim())); + }); + proc.stdout.on('close', () => onclose()); + proc.stderr.on('close', () => onclose()); proc.on('exit', mustCall((exitCode, signal) => assert.strictEqual( exitCode, 0, diff --git a/test/parallel/test-inspector-resource-name-to-url.js b/test/parallel/test-inspector-resource-name-to-url.js index 0465c065b96379..d56d4e25847949 100644 --- a/test/parallel/test-inspector-resource-name-to-url.js +++ b/test/parallel/test-inspector-resource-name-to-url.js @@ -4,7 +4,7 @@ const common = require('../common'); common.skipIfInspectorDisabled(); (async function test() { - const { strictEqual } = require('assert'); + const assert = require('assert'); const { Session } = require('inspector'); const { promisify } = require('util'); const vm = require('vm'); @@ -35,6 +35,6 @@ common.skipIfInspectorDisabled(); new Promise((resolve) => session.once('inspectorNotification', resolve)); new vm.Script('42', { filename }).runInThisContext(); const { params: { url } } = await promise; - strictEqual(url, expected); + assert.strictEqual(url, expected); } })().then(common.mustCall()); diff --git a/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js b/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js index 89414e50346871..6f54231882dbba 100644 --- a/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js +++ b/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js @@ -23,11 +23,10 @@ session.post('Runtime.evaluate', { expression: 'a', throwOnSideEffect: true, contextId: 2 // context's id -}, (error, res) => { - assert.ifError(error); +}, common.mustSucceed((res) => { const { exception } = res.exceptionDetails; assert.strictEqual(exception.className, 'EvalError'); assert.match(exception.description, /Possible side-effect/); assert(context); // Keep 'context' alive and make linter happy. -}); +})); diff --git a/test/parallel/test-internal-module-require.js b/test/parallel/test-internal-module-require.js index 213838150b96d9..3605d98e5e27bc 100644 --- a/test/parallel/test-internal-module-require.js +++ b/test/parallel/test-internal-module-require.js @@ -76,7 +76,7 @@ const expectedPublicModules = new Set([ if (process.argv[2] === 'child') { assert(!process.execArgv.includes('--expose-internals')); - process.once('message', ({ allBuiltins }) => { + process.once('message', common.mustCall(({ allBuiltins }) => { const publicModules = new Set(); for (const id of allBuiltins) { if (id.startsWith('internal/')) { @@ -102,7 +102,7 @@ if (process.argv[2] === 'child') { new Set(require('module').builtinModules) ); assert.deepStrictEqual(publicModules, expectedPublicModules); - }); + })); } else { assert(process.execArgv.includes('--expose-internals')); const child = fork(__filename, ['child'], { diff --git a/test/parallel/test-internal-socket-list-send.js b/test/parallel/test-internal-socket-list-send.js index a4012c7cc3e293..41df85f50a9b18 100644 --- a/test/parallel/test-internal-socket-list-send.js +++ b/test/parallel/test-internal-socket-list-send.js @@ -73,13 +73,13 @@ const key = 'test-key'; { const child = Object.assign(new EventEmitter(), { connected: true, - _send: function(msg) { + _send: common.mustCall(function(msg) { assert.strictEqual(msg.cmd, 'NODE_SOCKET_NOTIFY_CLOSE'); assert.strictEqual(msg.key, key); process.nextTick(() => this.emit('internalMessage', { key, cmd: 'NODE_SOCKET_ALL_CLOSED' }) ); - } + }) }); const list = new SocketListSend(child, key); @@ -98,7 +98,7 @@ const key = 'test-key'; const count = 1; const child = Object.assign(new EventEmitter(), { connected: true, - _send: function(msg) { + _send: common.mustCall(function(msg) { assert.strictEqual(msg.cmd, 'NODE_SOCKET_GET_COUNT'); assert.strictEqual(msg.key, key); process.nextTick(() => @@ -108,7 +108,7 @@ const key = 'test-key'; cmd: 'NODE_SOCKET_COUNT' }) ); - } + }) }); const list = new SocketListSend(child, key); diff --git a/test/parallel/test-kill-segfault-freebsd.js b/test/parallel/test-kill-segfault-freebsd.js index e17b00741bd9aa..baba07f3f1510c 100644 --- a/test/parallel/test-kill-segfault-freebsd.js +++ b/test/parallel/test-kill-segfault-freebsd.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); // This test ensures Node.js doesn't crash on hitting Ctrl+C in order to // terminate the currently running process (especially on FreeBSD). @@ -14,6 +14,6 @@ const cp = child_process.spawn(process.execPath, [ 'process.kill(process.pid, "SIGINT")', ]); -cp.on('exit', function(code) { +cp.on('exit', common.mustCall((code) => { assert.notStrictEqual(code, 0); -}); +})); diff --git a/test/parallel/test-listen-fd-cluster.js b/test/parallel/test-listen-fd-cluster.js index ea46b037a233d4..e8a07677509951 100644 --- a/test/parallel/test-listen-fd-cluster.js +++ b/test/parallel/test-listen-fd-cluster.js @@ -59,23 +59,23 @@ test(function(parent, port) { server: 'localhost', port: port, path: '/', - }).on('response', function(res) { + }).on('response', common.mustCall((res) => { let s = ''; res.on('data', function(c) { s += c.toString(); }); - res.on('end', function() { + res.on('end', common.mustCall(() => { // Kill the worker before we start doing asserts. // it's really annoying when tests leave orphans! parent.kill(); - parent.on('exit', function() { + parent.on('exit', common.mustCall(() => { assert.strictEqual(s, 'hello from worker\n'); assert.strictEqual(res.statusCode, 200); console.log('ok'); ok = true; - }); - }); - }); + })); + })); + })); }); function test(cb) { diff --git a/test/parallel/test-listen-fd-detached-inherit.js b/test/parallel/test-listen-fd-detached-inherit.js index 2a8e70f0f94230..3c87794d073abe 100644 --- a/test/parallel/test-listen-fd-detached-inherit.js +++ b/test/parallel/test-listen-fd-detached-inherit.js @@ -58,12 +58,12 @@ function test() { server: 'localhost', port: child.port, path: '/', - }).on('response', function(res) { + }).on('response', common.mustCall((res) => { let s = ''; res.on('data', function(c) { s += c.toString(); }); - res.on('end', function() { + res.on('end', common.mustCall(() => { // Kill the subprocess before we start doing asserts. // It's really annoying when tests leave orphans! process.kill(child.pid, 'SIGKILL'); @@ -75,8 +75,8 @@ function test() { assert.strictEqual(s, 'hello from child\n'); assert.strictEqual(res.statusCode, 200); - }); - }); + })); + })); } } diff --git a/test/parallel/test-listen-fd-detached.js b/test/parallel/test-listen-fd-detached.js index fba96a112f89b0..4506bd4ab8f95f 100644 --- a/test/parallel/test-listen-fd-detached.js +++ b/test/parallel/test-listen-fd-detached.js @@ -58,12 +58,12 @@ function test() { server: 'localhost', port: child.port, path: '/', - }).on('response', function(res) { + }).on('response', common.mustCall((res) => { let s = ''; res.on('data', function(c) { s += c.toString(); }); - res.on('end', function() { + res.on('end', common.mustCall(() => { // Kill the subprocess before we start doing asserts. // it's really annoying when tests leave orphans! process.kill(child.pid, 'SIGKILL'); @@ -75,8 +75,8 @@ function test() { assert.strictEqual(s, 'hello from child\n'); assert.strictEqual(res.statusCode, 200); - }); - }); + })); + })); } } diff --git a/test/parallel/test-listen-fd-server.js b/test/parallel/test-listen-fd-server.js index 3b6a0a0fac7abd..4b8a956953b7b4 100644 --- a/test/parallel/test-listen-fd-server.js +++ b/test/parallel/test-listen-fd-server.js @@ -49,21 +49,21 @@ test(function(child, port) { server: 'localhost', port: port, path: '/', - }).on('response', function(res) { + }).on('response', common.mustCall((res) => { let s = ''; res.on('data', function(c) { s += c.toString(); }); - res.on('end', function() { + res.on('end', common.mustCall(() => { child.kill(); - child.on('exit', function() { + child.on('exit', common.mustCall(() => { assert.strictEqual(s, 'hello from child\n'); assert.strictEqual(res.statusCode, 200); console.log('ok'); ok = true; - }); - }); - }); + })); + })); + })); }); function child() { diff --git a/test/parallel/test-messageport-hasref.js b/test/parallel/test-messageport-hasref.js index bc213f7897d277..563a598b3658eb 100644 --- a/test/parallel/test-messageport-hasref.js +++ b/test/parallel/test-messageport-hasref.js @@ -3,7 +3,7 @@ const common = require('../common'); const { MessageChannel } = require('worker_threads'); const { createHook } = require('async_hooks'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const handles = []; @@ -16,42 +16,42 @@ createHook({ }).enable(); const { port1, port2 } = new MessageChannel(); -strictEqual(handles[0], port1); -strictEqual(handles[1], port2); +assert.strictEqual(handles[0], port1); +assert.strictEqual(handles[1], port2); -strictEqual(handles[0].hasRef(), false); -strictEqual(handles[1].hasRef(), false); +assert.strictEqual(handles[0].hasRef(), false); +assert.strictEqual(handles[1].hasRef(), false); port1.unref(); -strictEqual(handles[0].hasRef(), false); +assert.strictEqual(handles[0].hasRef(), false); port1.ref(); -strictEqual(handles[0].hasRef(), true); +assert.strictEqual(handles[0].hasRef(), true); port1.unref(); -strictEqual(handles[0].hasRef(), false); +assert.strictEqual(handles[0].hasRef(), false); port1.on('message', () => {}); -strictEqual(handles[0].hasRef(), true); +assert.strictEqual(handles[0].hasRef(), true); port2.unref(); -strictEqual(handles[1].hasRef(), false); +assert.strictEqual(handles[1].hasRef(), false); port2.ref(); -strictEqual(handles[1].hasRef(), true); +assert.strictEqual(handles[1].hasRef(), true); port2.unref(); -strictEqual(handles[1].hasRef(), false); +assert.strictEqual(handles[1].hasRef(), false); port2.on('message', () => {}); -strictEqual(handles[0].hasRef(), true); +assert.strictEqual(handles[0].hasRef(), true); port1.on('close', common.mustCall(() => { - strictEqual(handles[0].hasRef(), false); - strictEqual(handles[1].hasRef(), false); + assert.strictEqual(handles[0].hasRef(), false); + assert.strictEqual(handles[1].hasRef(), false); })); port2.close(); -strictEqual(handles[0].hasRef(), true); -strictEqual(handles[1].hasRef(), true); +assert.strictEqual(handles[0].hasRef(), true); +assert.strictEqual(handles[1].hasRef(), true); diff --git a/test/parallel/test-microtask-queue-integration.js b/test/parallel/test-microtask-queue-integration.js index 69d55253a25295..1c4812d360f6c1 100644 --- a/test/parallel/test-microtask-queue-integration.js +++ b/test/parallel/test-microtask-queue-integration.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 implementations = [ @@ -40,16 +40,16 @@ function test(scheduleMicrotask) { let nextTickCalled = false; expected++; - scheduleMicrotask(function() { + scheduleMicrotask(common.mustCall(() => { process.nextTick(function() { nextTickCalled = true; }); - setTimeout(function() { + setTimeout(common.mustCall(() => { assert(nextTickCalled); done++; - }, 0); - }); + }), 0); + })); } // first tick case diff --git a/test/parallel/test-module-loading-globalpaths.js b/test/parallel/test-module-loading-globalpaths.js index a7b846019957d6..88e348b4fc99fd 100644 --- a/test/parallel/test-module-loading-globalpaths.js +++ b/test/parallel/test-module-loading-globalpaths.js @@ -32,12 +32,12 @@ if (process.argv[2] === 'child') { fs.copyFileSync(process.execPath, testExecPath, COPYFILE_FICLONE); fs.chmodSync(testExecPath, mode); - const runTest = (expectedString, env) => { + const runTest = common.mustCallAtLeast((expectedString, env) => { const child = child_process.execFileSync(testExecPath, [ __filename, 'child' ], { encoding: 'utf8', env: env }); assert.strictEqual(child.trim(), expectedString); - }; + }); const testFixturesDir = fixtures.path(path.basename(__filename, '.js')); diff --git a/test/parallel/test-module-stat.js b/test/parallel/test-module-stat.js index 0ab63f8edf9573..a15365b784ebd8 100644 --- a/test/parallel/test-module-stat.js +++ b/test/parallel/test-module-stat.js @@ -6,7 +6,7 @@ require('../common'); const Module = require('module'); const fs = require('fs'); const tmpdir = require('../common/tmpdir'); -const { ok, strictEqual } = require('assert'); +const assert = require('assert'); const directory = tmpdir.resolve('directory'); const doesNotExist = tmpdir.resolve('does-not-exist'); @@ -16,9 +16,9 @@ tmpdir.refresh(); fs.writeFileSync(file, "module.exports = { a: 'b' }"); fs.mkdirSync(directory); -strictEqual(Module._stat(directory), 1); // Returns 1 for directories. -strictEqual(Module._stat(file), 0); // Returns 0 for files. -ok(Module._stat(doesNotExist) < 0); // Returns a negative integer for any other kind of strings. +assert.strictEqual(Module._stat(directory), 1); // Returns 1 for directories. +assert.strictEqual(Module._stat(file), 0); // Returns 0 for files. +assert.ok(Module._stat(doesNotExist) < 0); // Returns a negative integer for any other kind of strings. // TODO(RaisinTen): Add tests that make sure that Module._stat() does not crash when called // with a non-string data type. It crashes currently.