From 864470d23867e5b8b16283208a7ffd52ccbb308f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 15 Nov 2025 22:57:12 +0100 Subject: [PATCH] test: ensure assertions are reached on more tests --- test/eslint.config_partial.mjs | 2 +- ...cket-writes-before-passed-to-tls-socket.js | 4 +- test/parallel/test-socketaddress.js | 92 +++++++++---------- test/parallel/test-spawn-cmd-named-pipe.js | 8 +- test/parallel/test-sqlite-custom-functions.js | 6 +- test/parallel/test-stdin-pipe-resume.js | 6 +- test/parallel/test-stdio-pipe-stderr.js | 6 +- ...out-cannot-be-closed-child-process-pipe.js | 6 +- test/parallel/test-strace-openat-openssl.js | 4 +- test/parallel/test-stream-big-push.js | 4 +- test/parallel/test-stream-compose.js | 8 +- test/parallel/test-stream-construct.js | 8 +- test/parallel/test-stream-destroy.js | 24 ++--- test/parallel/test-stream-drop-take.js | 62 ++++++------- test/parallel/test-stream-duplex-from.js | 4 +- .../test-stream-duplex-writable-finished.js | 4 +- test/parallel/test-stream-end-paused.js | 8 +- test/parallel/test-stream-filter.js | 4 +- ...est-stream-finished-async-local-storage.js | 12 +-- ...-stream-finished-bindAsyncResource-path.js | 7 +- .../test-stream-finished-default-path.js | 11 ++- test/parallel/test-stream-finished.js | 32 +++---- test/parallel/test-stream-forEach.js | 4 +- test/parallel/test-stream-pipe-await-drain.js | 4 +- test/parallel/test-stream-pipe-flow.js | 4 +- test/parallel/test-stream-pipeline-http2.js | 8 +- .../test-stream-pipeline-listeners.js | 12 +-- test/parallel/test-stream-pipeline.js | 77 ++++++++-------- test/parallel/test-stream-readable-aborted.js | 4 +- .../test-stream-readable-async-iterators.js | 38 +++----- test/parallel/test-stream-readable-didRead.js | 4 +- test/parallel/test-stream-readable-ended.js | 4 +- test/parallel/test-stream-readable-event.js | 12 +-- ...test-stream-readable-hwm-0-no-flow-data.js | 8 +- .../test-stream-readable-strategy-option.js | 11 +-- test/parallel/test-stream-reduce.js | 4 +- test/parallel/test-stream-transform-final.js | 4 +- .../test-stream-transform-flush-data.js | 6 +- test/parallel/test-stream-unpipe-event.js | 24 ++--- .../test-stream-unshift-empty-chunk.js | 6 +- .../parallel/test-stream-unshift-read-race.js | 4 +- test/parallel/test-stream-wrap.js | 4 +- ...stream-writable-change-default-encoding.js | 14 +-- .../test-stream-writable-decoded-encoding.js | 24 ++--- test/parallel/test-stream-writable-destroy.js | 4 +- .../test-stream-writable-ended-state.js | 4 +- .../test-stream-writable-finished-state.js | 4 +- .../parallel/test-stream-writable-finished.js | 4 +- test/parallel/test-stream-writable-null.js | 5 +- test/parallel/test-stream-writev.js | 9 +- ...est-stream2-base64-single-char-read-end.js | 6 +- test/parallel/test-stream2-basic.js | 20 ++-- test/parallel/test-stream2-compatibility.js | 6 +- .../test-stream2-httpclient-response-end.js | 8 +- test/parallel/test-stream2-objects.js | 8 +- test/parallel/test-stream2-push.js | 6 +- test/parallel/test-stream2-readable-wrap.js | 4 +- test/parallel/test-stream2-writable.js | 27 ++---- test/parallel/test-stream3-cork-end.js | 18 ++-- test/parallel/test-stream3-cork-uncork.js | 18 ++-- test/parallel/test-stream3-pause-then-read.js | 10 +- .../test-stream3-pipeline-async-iterator.js | 1 + 62 files changed, 369 insertions(+), 395 deletions(-) diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index bbf9264c513137..476cd38df59b30 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -197,7 +197,7 @@ export default [ Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') },http-*,http2-*,${ // 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(',') + Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') }}.{js,mjs,cjs}`, ], rules: { diff --git a/test/parallel/test-socket-writes-before-passed-to-tls-socket.js b/test/parallel/test-socket-writes-before-passed-to-tls-socket.js index 22c5b87111579c..ff4fc9a486cd95 100644 --- a/test/parallel/test-socket-writes-before-passed-to-tls-socket.js +++ b/test/parallel/test-socket-writes-before-passed-to-tls-socket.js @@ -7,7 +7,7 @@ const net = require('net'); const HEAD = Buffer.alloc(1024 * 1024, 0); -const server = net.createServer((serverSock) => { +const server = net.createServer(common.mustCallAtLeast((serverSock) => { let recvLen = 0; const recv = []; serverSock.on('data', common.mustCallAtLeast((chunk) => { @@ -21,7 +21,7 @@ const server = net.createServer((serverSock) => { process.exit(0); } }, 1)); -}) +})) .listen(client); function client() { diff --git a/test/parallel/test-socketaddress.js b/test/parallel/test-socketaddress.js index bd117cc6b5edc1..cf29795a48fcfa 100644 --- a/test/parallel/test-socketaddress.js +++ b/test/parallel/test-socketaddress.js @@ -2,11 +2,7 @@ 'use strict'; const common = require('../common'); -const { - ok, - strictEqual, - throws, -} = require('assert'); +const assert = require('assert'); const { SocketAddress, } = require('net'); @@ -26,19 +22,19 @@ describe('net.SocketAddress...', () => { it('is cloneable', () => { const sa = new SocketAddress(); - strictEqual(sa.address, '127.0.0.1'); - strictEqual(sa.port, 0); - strictEqual(sa.family, 'ipv4'); - strictEqual(sa.flowlabel, 0); + assert.strictEqual(sa.address, '127.0.0.1'); + assert.strictEqual(sa.port, 0); + assert.strictEqual(sa.family, 'ipv4'); + assert.strictEqual(sa.flowlabel, 0); const mc = new MessageChannel(); mc.port1.onmessage = common.mustCall(({ data }) => { - ok(SocketAddress.isSocketAddress(data)); + assert.ok(SocketAddress.isSocketAddress(data)); - strictEqual(data.address, '127.0.0.1'); - strictEqual(data.port, 0); - strictEqual(data.family, 'ipv4'); - strictEqual(data.flowlabel, 0); + assert.strictEqual(data.address, '127.0.0.1'); + assert.strictEqual(data.port, 0); + assert.strictEqual(data.family, 'ipv4'); + assert.strictEqual(data.flowlabel, 0); mc.port1.close(); }); @@ -47,20 +43,20 @@ describe('net.SocketAddress...', () => { it('has reasonable defaults', () => { const sa = new SocketAddress({}); - strictEqual(sa.address, '127.0.0.1'); - strictEqual(sa.port, 0); - strictEqual(sa.family, 'ipv4'); - strictEqual(sa.flowlabel, 0); + assert.strictEqual(sa.address, '127.0.0.1'); + assert.strictEqual(sa.port, 0); + assert.strictEqual(sa.family, 'ipv4'); + assert.strictEqual(sa.flowlabel, 0); }); it('interprets simple ipv4 correctly', () => { const sa = new SocketAddress({ address: '123.123.123.123', }); - strictEqual(sa.address, '123.123.123.123'); - strictEqual(sa.port, 0); - strictEqual(sa.family, 'ipv4'); - strictEqual(sa.flowlabel, 0); + assert.strictEqual(sa.address, '123.123.123.123'); + assert.strictEqual(sa.port, 0); + assert.strictEqual(sa.family, 'ipv4'); + assert.strictEqual(sa.flowlabel, 0); }); it('sets the port correctly', () => { @@ -68,20 +64,20 @@ describe('net.SocketAddress...', () => { address: '123.123.123.123', port: 80 }); - strictEqual(sa.address, '123.123.123.123'); - strictEqual(sa.port, 80); - strictEqual(sa.family, 'ipv4'); - strictEqual(sa.flowlabel, 0); + assert.strictEqual(sa.address, '123.123.123.123'); + assert.strictEqual(sa.port, 80); + assert.strictEqual(sa.family, 'ipv4'); + assert.strictEqual(sa.flowlabel, 0); }); it('interprets simple ipv6 correctly', () => { const sa = new SocketAddress({ family: 'ipv6' }); - strictEqual(sa.address, '::'); - strictEqual(sa.port, 0); - strictEqual(sa.family, 'ipv6'); - strictEqual(sa.flowlabel, 0); + assert.strictEqual(sa.address, '::'); + assert.strictEqual(sa.port, 0); + assert.strictEqual(sa.family, 'ipv6'); + assert.strictEqual(sa.flowlabel, 0); }); it('uses the flowlabel correctly', () => { @@ -89,38 +85,38 @@ describe('net.SocketAddress...', () => { family: 'ipv6', flowlabel: 1, }); - strictEqual(sa.address, '::'); - strictEqual(sa.port, 0); - strictEqual(sa.family, 'ipv6'); - strictEqual(sa.flowlabel, 1); + assert.strictEqual(sa.address, '::'); + assert.strictEqual(sa.port, 0); + assert.strictEqual(sa.family, 'ipv6'); + assert.strictEqual(sa.flowlabel, 1); }); it('validates input correctly', () => { [1, false, 'hello'].forEach((i) => { - throws(() => new SocketAddress(i), { + assert.throws(() => new SocketAddress(i), { code: 'ERR_INVALID_ARG_TYPE' }); }); [1, false, {}, [], 'test'].forEach((family) => { - throws(() => new SocketAddress({ family }), { + assert.throws(() => new SocketAddress({ family }), { code: 'ERR_INVALID_ARG_VALUE' }); }); [1, false, {}, []].forEach((address) => { - throws(() => new SocketAddress({ address }), { + assert.throws(() => new SocketAddress({ address }), { code: 'ERR_INVALID_ARG_TYPE' }); }); [-1, false, {}, []].forEach((port) => { - throws(() => new SocketAddress({ port }), { + assert.throws(() => new SocketAddress({ port }), { code: 'ERR_SOCKET_BAD_PORT' }); }); - throws(() => new SocketAddress({ flowlabel: -1 }), { + assert.throws(() => new SocketAddress({ flowlabel: -1 }), { code: 'ERR_OUT_OF_RANGE' }); }); @@ -135,11 +131,11 @@ describe('net.SocketAddress...', () => { const flowlabel = 0; const handle = new _SocketAddress(address, port, AF_INET, flowlabel); const addr = new InternalSocketAddress(handle); - ok(addr instanceof SocketAddress); - strictEqual(addr.address, address); - strictEqual(addr.port, port); - strictEqual(addr.family, 'ipv4'); - strictEqual(addr.flowlabel, flowlabel); + assert.ok(addr instanceof SocketAddress); + assert.strictEqual(addr.address, address); + assert.strictEqual(addr.port, port); + assert.strictEqual(addr.family, 'ipv4'); + assert.strictEqual(addr.flowlabel, flowlabel); }); it('SocketAddress.parse() works as expected', () => { @@ -156,9 +152,9 @@ describe('net.SocketAddress...', () => { good.forEach((i) => { const addr = SocketAddress.parse(i.input); - strictEqual(addr.address, i.address); - strictEqual(addr.port, i.port); - strictEqual(addr.family, i.family); + assert.strictEqual(addr.address, i.address); + assert.strictEqual(addr.port, i.port); + assert.strictEqual(addr.family, i.family); }); const bad = [ @@ -169,7 +165,7 @@ describe('net.SocketAddress...', () => { ]; bad.forEach((i) => { - strictEqual(SocketAddress.parse(i), undefined); + assert.strictEqual(SocketAddress.parse(i), undefined); }); }); diff --git a/test/parallel/test-spawn-cmd-named-pipe.js b/test/parallel/test-spawn-cmd-named-pipe.js index 4e7ad185a5401c..e9eb206b1b1f7f 100644 --- a/test/parallel/test-spawn-cmd-named-pipe.js +++ b/test/parallel/test-spawn-cmd-named-pipe.js @@ -16,22 +16,22 @@ if (!process.argv[2]) { const stdinPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdin`; const stdoutPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdout`; - const stdinPipeServer = net.createServer(function(c) { + const stdinPipeServer = net.createServer(common.mustCall((c) => { c.on('end', common.mustCall()); c.end('hello'); - }); + })); stdinPipeServer.listen(stdinPipeName); const output = []; - const stdoutPipeServer = net.createServer(function(c) { + const stdoutPipeServer = net.createServer(common.mustCallAtLeast((c) => { c.on('data', function(x) { output.push(x); }); c.on('end', common.mustCall(function() { assert.strictEqual(output.join(''), 'hello'); })); - }); + })); stdoutPipeServer.listen(stdoutPipeName); const args = diff --git a/test/parallel/test-sqlite-custom-functions.js b/test/parallel/test-sqlite-custom-functions.js index d535cda821e10e..6b5f974ede893e 100644 --- a/test/parallel/test-sqlite-custom-functions.js +++ b/test/parallel/test-sqlite-custom-functions.js @@ -1,5 +1,5 @@ 'use strict'; -const { skipIfSQLiteMissing } = require('../common'); +const { skipIfSQLiteMissing, mustCall } = require('../common'); skipIfSQLiteMissing(); const assert = require('node:assert'); const { DatabaseSync } = require('node:sqlite'); @@ -376,14 +376,14 @@ suite('DatabaseSync.prototype.function()', () => { test('supported argument types', () => { const db = new DatabaseSync(':memory:'); - db.function('arguments', (i, f, s, n, b) => { + db.function('arguments', mustCall((i, f, s, n, b) => { assert.strictEqual(i, 5); assert.strictEqual(f, 3.14); assert.strictEqual(s, 'foo'); assert.strictEqual(n, null); assert.deepStrictEqual(b, new Uint8Array([254])); return 42; - }); + })); const stmt = db.prepare( 'SELECT arguments(5, 3.14, \'foo\', null, x\'fe\') as result' ); diff --git a/test/parallel/test-stdin-pipe-resume.js b/test/parallel/test-stdin-pipe-resume.js index e9000933a37cfa..90e41b95405b28 100644 --- a/test/parallel/test-stdin-pipe-resume.js +++ b/test/parallel/test-stdin-pipe-resume.js @@ -1,6 +1,6 @@ 'use strict'; // This tests that piping stdin will cause it to resume() as well. -require('../common'); +const common = require('../common'); const assert = require('assert'); if (process.argv[2] === 'child') { @@ -12,11 +12,11 @@ if (process.argv[2] === 'child') { child.stdout.on('data', function(c) { buffers.push(c); }); - child.stdout.on('close', function() { + child.stdout.on('close', common.mustCall(() => { const b = Buffer.concat(buffers).toString(); assert.strictEqual(b, 'Hello, world\n'); console.log('ok'); - }); + })); child.stdin.write('Hel'); child.stdin.write('lo,'); child.stdin.write(' wo'); diff --git a/test/parallel/test-stdio-pipe-stderr.js b/test/parallel/test-stdio-pipe-stderr.js index c914877062c425..ba4d2b71772c71 100644 --- a/test/parallel/test-stdio-pipe-stderr.js +++ b/test/parallel/test-stdio-pipe-stderr.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const tmpdir = require('../common/tmpdir'); const assert = require('assert'); const fs = require('fs'); @@ -19,7 +19,7 @@ const stream = fs.createWriteStream(stderrOutputPath); // non-built-in module. fs.writeFileSync(fakeModulePath, '', 'utf8'); -stream.on('open', () => { +stream.on('open', common.mustCall(() => { spawnSync(process.execPath, { input: `require(${JSON.stringify(fakeModulePath)})`, stdio: ['pipe', 'pipe', stream] @@ -33,4 +33,4 @@ stream.on('open', () => { stream.end(); fs.unlinkSync(stderrOutputPath); fs.unlinkSync(fakeModulePath); -}); +})); diff --git a/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js b/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js index 7cd4b90c008a2f..ac2a8706890e74 100644 --- a/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js +++ b/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); if (process.argv[2] === 'child') @@ -23,10 +23,10 @@ function parent() { err += c; }); - child.on('close', function(code, signal) { + child.on('close', common.mustCall((code, signal) => { assert.strictEqual(code, 0); assert.strictEqual(err, ''); assert.strictEqual(out, 'foo'); console.log('ok'); - }); + })); } diff --git a/test/parallel/test-strace-openat-openssl.js b/test/parallel/test-strace-openat-openssl.js index 8e4a38fc6e7eaf..234c12f126f093 100644 --- a/test/parallel/test-strace-openat-openssl.js +++ b/test/parallel/test-strace-openat-openssl.js @@ -32,7 +32,7 @@ if (spawnSync('strace').error !== undefined) { // stderr is the default for strace const rl = createInterface({ input: strace.stderr }); - rl.on('line', (line) => { + rl.on('line', common.mustCallAtLeast((line) => { if (!line.startsWith('open')) { return; } @@ -48,7 +48,7 @@ if (spawnSync('strace').error !== undefined) { } assert(allowedOpenCalls.delete(file), `${file} is not in the list of allowed openat calls`); - }); + })); const debugOutput = []; strace.stderr.setEncoding('utf8'); strace.stderr.on('data', (chunk) => { diff --git a/test/parallel/test-stream-big-push.js b/test/parallel/test-stream-big-push.js index f9e75edd3f89d1..9923057932fb01 100644 --- a/test/parallel/test-stream-big-push.js +++ b/test/parallel/test-stream-big-push.js @@ -61,7 +61,7 @@ assert.strictEqual(chunk, str); chunk = r.read(); assert.strictEqual(chunk, null); -r.once('readable', () => { +r.once('readable', common.mustCall(() => { // This time, we'll get *all* the remaining data, because // it's been added synchronously, as the read WOULD take // us below the hwm, and so it triggered a _read() again, @@ -71,4 +71,4 @@ r.once('readable', () => { chunk = r.read(); assert.strictEqual(chunk, null); -}); +})); diff --git a/test/parallel/test-stream-compose.js b/test/parallel/test-stream-compose.js index d7a54e177668a2..36581d6d858276 100644 --- a/test/parallel/test-stream-compose.js +++ b/test/parallel/test-stream-compose.js @@ -219,9 +219,9 @@ const assert = require('assert'); .end(true) .on('data', common.mustNotCall()) .on('end', common.mustNotCall()) - .on('error', (err) => { + .on('error', common.mustCall((err) => { assert.strictEqual(err, _err); - }); + })); } { @@ -251,9 +251,9 @@ const assert = require('assert'); .end(true) .on('data', common.mustNotCall()) .on('end', common.mustNotCall()) - .on('error', (err) => { + .on('error', common.mustCall((err) => { assert.strictEqual(err, _err); - }); + })); } { diff --git a/test/parallel/test-stream-construct.js b/test/parallel/test-stream-construct.js index 907b9aa0e3e296..394ff503c66540 100644 --- a/test/parallel/test-stream-construct.js +++ b/test/parallel/test-stream-construct.js @@ -108,9 +108,9 @@ function testDestroy(factory) { s.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); - s.destroy(null, () => { + s.destroy(null, common.mustCall(() => { assert.strictEqual(constructed, true); - }); + })); } { @@ -142,10 +142,10 @@ function testDestroy(factory) { s.on('error', common.mustCall((err) => { assert.strictEqual(err.message, 'kaboom'); })); - s.destroy(new Error('kaboom'), (err) => { + s.destroy(new Error('kaboom'), common.mustCall((err) => { assert.strictEqual(err.message, 'kaboom'); assert.strictEqual(constructed, true); - }); + })); } { diff --git a/test/parallel/test-stream-destroy.js b/test/parallel/test-stream-destroy.js index 5269ccfec50271..12706714aa7c8a 100644 --- a/test/parallel/test-stream-destroy.js +++ b/test/parallel/test-stream-destroy.js @@ -50,7 +50,7 @@ const http = require('http'); } { - const server = http.createServer((req, res) => { + const server = http.createServer(common.mustCallAtLeast((req, res) => { destroy(req); req.on('error', common.mustCall((err) => { assert.strictEqual(err.name, 'AbortError'); @@ -58,16 +58,16 @@ const http = require('http'); req.on('close', common.mustCall(() => { res.end('hello'); })); - }); + })); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const req = http.request({ method: 'POST', port: server.address().port, agent: new http.Agent() }); - req.on('response', (res) => { + req.on('response', common.mustCall((res) => { const buf = []; res.on('data', (data) => buf.push(data)); res.on('end', common.mustCall(() => { @@ -77,14 +77,14 @@ const http = require('http'); ); server.close(); })); - }); + })); req.end('asd'); - }); + })); } { - const server = http.createServer((req, res) => { + const server = http.createServer(common.mustCallAtLeast((req, res) => { req .resume() .on('end', () => { @@ -95,15 +95,15 @@ const http = require('http'); req.on('close', common.mustCall(() => { res.end('hello'); })); - }); + })); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const req = http.request({ method: 'POST', port: server.address().port, agent: new http.Agent() }); - req.on('response', (res) => { + req.on('response', common.mustCall((res) => { const buf = []; res.on('data', (data) => buf.push(data)); res.on('end', common.mustCall(() => { @@ -113,8 +113,8 @@ const http = require('http'); ); server.close(); })); - }); + })); req.end('asd'); - }); + })); } diff --git a/test/parallel/test-stream-drop-take.js b/test/parallel/test-stream-drop-take.js index 97e6c74dfa67ea..da09d242f0c492 100644 --- a/test/parallel/test-stream-drop-take.js +++ b/test/parallel/test-stream-drop-take.js @@ -4,7 +4,7 @@ const common = require('../common'); const { Readable, } = require('stream'); -const { deepStrictEqual, rejects, throws, strictEqual } = require('assert'); +const assert = require('assert'); const { from } = Readable; @@ -20,32 +20,32 @@ const naturals = () => from(async function*() { { // Synchronous streams (async () => { - deepStrictEqual(await from([1, 2, 3]).drop(2).toArray(), [3]); - deepStrictEqual(await from([1, 2, 3]).take(1).toArray(), [1]); - deepStrictEqual(await from([]).drop(2).toArray(), []); - deepStrictEqual(await from([]).take(1).toArray(), []); - deepStrictEqual(await from([1, 2, 3]).drop(1).take(1).toArray(), [2]); - deepStrictEqual(await from([1, 2]).drop(0).toArray(), [1, 2]); - deepStrictEqual(await from([1, 2]).take(0).toArray(), []); + assert.deepStrictEqual(await from([1, 2, 3]).drop(2).toArray(), [3]); + assert.deepStrictEqual(await from([1, 2, 3]).take(1).toArray(), [1]); + assert.deepStrictEqual(await from([]).drop(2).toArray(), []); + assert.deepStrictEqual(await from([]).take(1).toArray(), []); + assert.deepStrictEqual(await from([1, 2, 3]).drop(1).take(1).toArray(), [2]); + assert.deepStrictEqual(await from([1, 2]).drop(0).toArray(), [1, 2]); + assert.deepStrictEqual(await from([1, 2]).take(0).toArray(), []); })().then(common.mustCall()); // Asynchronous streams (async () => { - deepStrictEqual(await fromAsync([1, 2, 3]).drop(2).toArray(), [3]); - deepStrictEqual(await fromAsync([1, 2, 3]).take(1).toArray(), [1]); - deepStrictEqual(await fromAsync([]).drop(2).toArray(), []); - deepStrictEqual(await fromAsync([]).take(1).toArray(), []); - deepStrictEqual(await fromAsync([1, 2, 3]).drop(1).take(1).toArray(), [2]); - deepStrictEqual(await fromAsync([1, 2]).drop(0).toArray(), [1, 2]); - deepStrictEqual(await fromAsync([1, 2]).take(0).toArray(), []); + assert.deepStrictEqual(await fromAsync([1, 2, 3]).drop(2).toArray(), [3]); + assert.deepStrictEqual(await fromAsync([1, 2, 3]).take(1).toArray(), [1]); + assert.deepStrictEqual(await fromAsync([]).drop(2).toArray(), []); + assert.deepStrictEqual(await fromAsync([]).take(1).toArray(), []); + assert.deepStrictEqual(await fromAsync([1, 2, 3]).drop(1).take(1).toArray(), [2]); + assert.deepStrictEqual(await fromAsync([1, 2]).drop(0).toArray(), [1, 2]); + assert.deepStrictEqual(await fromAsync([1, 2]).take(0).toArray(), []); })().then(common.mustCall()); // Infinite streams // Asynchronous streams (async () => { - deepStrictEqual(await naturals().take(1).toArray(), [1]); - deepStrictEqual(await naturals().drop(1).take(1).toArray(), [2]); + assert.deepStrictEqual(await naturals().take(1).toArray(), [1]); + assert.deepStrictEqual(await naturals().drop(1).take(1).toArray(), [2]); const next10 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; - deepStrictEqual(await naturals().drop(10).take(10).toArray(), next10); - deepStrictEqual(await naturals().take(5).take(1).toArray(), [1]); + assert.deepStrictEqual(await naturals().drop(10).take(10).toArray(), next10); + assert.deepStrictEqual(await naturals().take(5).take(1).toArray(), [1]); })().then(common.mustCall()); } @@ -66,7 +66,7 @@ const naturals = () => from(async function*() { stream.take(1) .toArray() .then(common.mustCall(() => { - strictEqual(reached, false); + assert.strictEqual(reached, false); })) .finally(() => resolve()); } @@ -75,20 +75,20 @@ const naturals = () => from(async function*() { // Coercion (async () => { // The spec made me do this ^^ - deepStrictEqual(await naturals().take('cat').toArray(), []); - deepStrictEqual(await naturals().take('2').toArray(), [1, 2]); - deepStrictEqual(await naturals().take(true).toArray(), [1]); + assert.deepStrictEqual(await naturals().take('cat').toArray(), []); + assert.deepStrictEqual(await naturals().take('2').toArray(), [1, 2]); + assert.deepStrictEqual(await naturals().take(true).toArray(), [1]); })().then(common.mustCall()); } { // Support for AbortSignal const ac = new AbortController(); - rejects( + assert.rejects( Readable.from([1, 2, 3]).take(1, { signal: ac.signal }).toArray(), { name: 'AbortError', }).then(common.mustCall()); - rejects( + assert.rejects( Readable.from([1, 2, 3]).drop(1, { signal: ac.signal }).toArray(), { name: 'AbortError', }).then(common.mustCall()); @@ -98,7 +98,7 @@ const naturals = () => from(async function*() { { // Support for AbortSignal, already aborted const signal = AbortSignal.abort(); - rejects( + assert.rejects( Readable.from([1, 2, 3]).take(1, { signal }).toArray(), { name: 'AbortError', }).then(common.mustCall()); @@ -113,12 +113,12 @@ const naturals = () => from(async function*() { ]; for (const example of invalidArgs) { - throws(() => from([]).take(example).toArray(), /ERR_OUT_OF_RANGE/); + assert.throws(() => from([]).take(example).toArray(), /ERR_OUT_OF_RANGE/); } - throws(() => Readable.from([1]).drop(1, 1), /ERR_INVALID_ARG_TYPE/); - throws(() => Readable.from([1]).drop(1, { signal: true }), /ERR_INVALID_ARG_TYPE/); + assert.throws(() => Readable.from([1]).drop(1, 1), /ERR_INVALID_ARG_TYPE/); + assert.throws(() => Readable.from([1]).drop(1, { signal: true }), /ERR_INVALID_ARG_TYPE/); - throws(() => Readable.from([1]).take(1, 1), /ERR_INVALID_ARG_TYPE/); - throws(() => Readable.from([1]).take(1, { signal: true }), /ERR_INVALID_ARG_TYPE/); + assert.throws(() => Readable.from([1]).take(1, 1), /ERR_INVALID_ARG_TYPE/); + assert.throws(() => Readable.from([1]).take(1, { signal: true }), /ERR_INVALID_ARG_TYPE/); } diff --git a/test/parallel/test-stream-duplex-from.js b/test/parallel/test-stream-duplex-from.js index e3c117ff8dedb0..631b3586b36191 100644 --- a/test/parallel/test-stream-duplex-from.js +++ b/test/parallel/test-stream-duplex-from.js @@ -136,13 +136,13 @@ const { Blob } = require('buffer'); } yield rest; }), - async function * (source) { // eslint-disable-line require-yield + common.mustCall(async function * (source) { // eslint-disable-line require-yield let ret = ''; for await (const x of source) { ret += x; } assert.strictEqual(ret, 'abcdefghi'); - }, + }), common.mustSucceed(), ); } diff --git a/test/parallel/test-stream-duplex-writable-finished.js b/test/parallel/test-stream-duplex-writable-finished.js index 20c0781a22273d..e679c7295d614e 100644 --- a/test/parallel/test-stream-duplex-writable-finished.js +++ b/test/parallel/test-stream-duplex-writable-finished.js @@ -14,11 +14,11 @@ const assert = require('assert'); { const duplex = new Duplex(); - duplex._write = (chunk, encoding, cb) => { + duplex._write = common.mustCall((chunk, encoding, cb) => { // The state finished should start in false. assert.strictEqual(duplex.writableFinished, false); cb(); - }; + }); duplex.on('finish', common.mustCall(() => { assert.strictEqual(duplex.writableFinished, true); diff --git a/test/parallel/test-stream-end-paused.js b/test/parallel/test-stream-end-paused.js index f29c82f532c22b..f3d7289699519a 100644 --- a/test/parallel/test-stream-end-paused.js +++ b/test/parallel/test-stream-end-paused.js @@ -28,15 +28,13 @@ const assert = require('assert'); const Readable = require('stream').Readable; const stream = new Readable(); let calledRead = false; -stream._read = function() { +stream._read = common.mustCall(function() { assert(!calledRead); calledRead = true; this.push(null); -}; - -stream.on('data', function() { - throw new Error('should not ever get data'); }); + +stream.on('data', common.mustNotCall()); stream.pause(); setTimeout(common.mustCall(function() { diff --git a/test/parallel/test-stream-filter.js b/test/parallel/test-stream-filter.js index 173e4f47e24353..0b70c391c88fb1 100644 --- a/test/parallel/test-stream-filter.js +++ b/test/parallel/test-stream-filter.js @@ -132,10 +132,10 @@ const { setTimeout } = require('timers/promises'); name: 'AbortError', }).then(common.mustCall()); - setImmediate(() => { + setImmediate(common.mustCall(() => { ac.abort(); assert.strictEqual(calls, 2); - }); + })); } { diff --git a/test/parallel/test-stream-finished-async-local-storage.js b/test/parallel/test-stream-finished-async-local-storage.js index 1440d2bb0ac991..9ae81aa75325b7 100644 --- a/test/parallel/test-stream-finished-async-local-storage.js +++ b/test/parallel/test-stream-finished-async-local-storage.js @@ -4,7 +4,7 @@ const common = require('../common'); const { Readable, finished } = require('stream'); const { AsyncLocalStorage } = require('async_hooks'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const AsyncContextFrame = require('internal/async_context_frame'); const internalAsyncHooks = require('internal/async_hooks'); @@ -13,12 +13,12 @@ const internalAsyncHooks = require('internal/async_hooks'); const als = new AsyncLocalStorage(); const readable = new Readable(); -als.run('test-context-1', () => { +als.run('test-context-1', common.mustCall(() => { finished(readable, common.mustCall(() => { - strictEqual(AsyncContextFrame.enabled || internalAsyncHooks.getHookArrays()[0].length > 0, - true, 'One of AsyncContextFrame or async hooks criteria should be met'); - strictEqual(als.getStore(), 'test-context-1', 'ALS context should be preserved'); + assert.strictEqual(AsyncContextFrame.enabled || internalAsyncHooks.getHookArrays()[0].length > 0, + true); + assert.strictEqual(als.getStore(), 'test-context-1'); })); -}); +})); readable.destroy(); diff --git a/test/parallel/test-stream-finished-bindAsyncResource-path.js b/test/parallel/test-stream-finished-bindAsyncResource-path.js index 6bec9587e3ad11..98ef2bb3b62ef1 100644 --- a/test/parallel/test-stream-finished-bindAsyncResource-path.js +++ b/test/parallel/test-stream-finished-bindAsyncResource-path.js @@ -4,7 +4,7 @@ const common = require('../common'); const { Readable, finished } = require('stream'); const { createHook, executionAsyncId } = require('async_hooks'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const internalAsyncHooks = require('internal/async_hooks'); // This test verifies that when there are active async hooks, stream.finished() uses @@ -27,9 +27,8 @@ const readable = new Readable(); finished(readable, common.mustCall(() => { const currentAsyncId = executionAsyncId(); const ctx = contextMap.get(currentAsyncId); - strictEqual(internalAsyncHooks.getHookArrays()[0].length > 0, - true, 'Should have active user async hook'); - strictEqual(ctx, 'abc-123', 'Context should be preserved'); + assert.strictEqual(internalAsyncHooks.getHookArrays()[0].length > 0, true); + assert.strictEqual(ctx, 'abc-123'); })); readable.destroy(); diff --git a/test/parallel/test-stream-finished-default-path.js b/test/parallel/test-stream-finished-default-path.js index 31fcd8d175a3fd..7beffc887b2bee 100644 --- a/test/parallel/test-stream-finished-default-path.js +++ b/test/parallel/test-stream-finished-default-path.js @@ -3,7 +3,7 @@ const common = require('../common'); const { Readable, finished } = require('stream'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const AsyncContextFrame = require('internal/async_context_frame'); const internalAsyncHooks = require('internal/async_hooks'); @@ -12,10 +12,11 @@ const internalAsyncHooks = require('internal/async_hooks'); const readable = new Readable(); finished(readable, common.mustCall(() => { - strictEqual(internalAsyncHooks.getHookArrays()[0].length === 0, - true, 'Should not have active user async hook'); - strictEqual(AsyncContextFrame.current() || internalAsyncHooks.getHookArrays()[0].length > 0, - false, 'Default callback path should be used'); + assert.strictEqual(internalAsyncHooks.getHookArrays()[0].length === 0, true); + assert.strictEqual( + AsyncContextFrame.current() || internalAsyncHooks.getHookArrays()[0].length > 0, + false, + ); })); readable.destroy(); diff --git a/test/parallel/test-stream-finished.js b/test/parallel/test-stream-finished.js index 9d66cbe59b11f3..b55107a7a6440f 100644 --- a/test/parallel/test-stream-finished.js +++ b/test/parallel/test-stream-finished.js @@ -342,10 +342,10 @@ function testClosed(factory) { const s = factory({ emitClose: false, - destroy(err, cb) { + destroy: common.mustCall((err, cb) => { cb(); finished(s, common.mustCall()); - } + }), }); s.destroy(); } @@ -354,14 +354,14 @@ function testClosed(factory) { // Invoke with deep async. const s = factory({ - destroy(err, cb) { - setImmediate(() => { + destroy: common.mustCall((err, cb) => { + setImmediate(common.mustCall(() => { cb(); - setImmediate(() => { + setImmediate(common.mustCall(() => { finished(s, common.mustCall()); - }); - }); - } + })); + })); + }), }); s.destroy(); } @@ -567,13 +567,13 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); })); res.end(); })) - .listen(0, function() { + .listen(0, common.mustCall(function() { http.request({ method: 'GET', port: this.address().port }).end() .on('response', common.mustCall()); - }); + })); } { @@ -584,12 +584,12 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); })); })); req.destroy(); - })).listen(0, function() { + })).listen(0, common.mustCall(function() { http.request({ method: 'GET', port: this.address().port }).end().on('error', common.mustCall()); - }); + })); } { @@ -601,10 +601,10 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); w.aborted = false; w.end(); let closed = false; - w.on('finish', () => { + w.on('finish', common.mustCall(() => { assert.strictEqual(closed, false); w.emit('aborted'); - }); + })); w.on('close', common.mustCall(() => { closed = true; })); @@ -655,7 +655,7 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); finished(res, common.mustCall(function(err) { assert.strictEqual(err, undefined); })); - })).listen(0, function() { + })).listen(0, common.mustCall(function() { http.request( { method: 'GET', port: this.address().port }, common.mustCall(function(res) { @@ -665,7 +665,7 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); })); }) ).end(); - }); + })); } { diff --git a/test/parallel/test-stream-forEach.js b/test/parallel/test-stream-forEach.js index 627ea0ccf1be60..cccd263adf4c70 100644 --- a/test/parallel/test-stream-forEach.js +++ b/test/parallel/test-stream-forEach.js @@ -104,10 +104,10 @@ const { once } = require('events'); name: 'AbortError', }).then(common.mustCall()); - setImmediate(() => { + setImmediate(common.mustCall(() => { ac.abort(); assert.strictEqual(calls, 2); - }); + })); } { diff --git a/test/parallel/test-stream-pipe-await-drain.js b/test/parallel/test-stream-pipe-await-drain.js index 35b86f67f99676..9ce0e465243fde 100644 --- a/test/parallel/test-stream-pipe-await-drain.js +++ b/test/parallel/test-stream-pipe-await-drain.js @@ -22,7 +22,7 @@ writer1._write = common.mustCall(function(chunk, encoding, cb) { process.nextTick(cb); }, 1); -writer1.once('chunk-received', () => { +writer1.once('chunk-received', common.mustCallAtLeast(() => { assert.strictEqual( reader._readableState.awaitDrainWriters.size, 0, @@ -34,7 +34,7 @@ writer1.once('chunk-received', () => { // "done" processing. reader.push(buffer); }); -}); +})); // A "slow" consumer: writer2._write = common.mustCall((chunk, encoding, cb) => { diff --git a/test/parallel/test-stream-pipe-flow.js b/test/parallel/test-stream-pipe-flow.js index 1f2e8f54cec409..e985f0f8aed982 100644 --- a/test/parallel/test-stream-pipe-flow.js +++ b/test/parallel/test-stream-pipe-flow.js @@ -74,9 +74,7 @@ const { Readable, Writable, PassThrough } = require('stream'); const pt = rs .pipe(new PassThrough({ objectMode: true, highWaterMark: 2 })); assert.strictEqual(pt.listenerCount('drain'), 0); - pt.on('finish', () => { - assert.strictEqual(pt.listenerCount('drain'), 0); - }); + pt.on('finish', common.mustNotCall()); rs.push('asd'); assert.strictEqual(pt.listenerCount('drain'), 0); diff --git a/test/parallel/test-stream-pipeline-http2.js b/test/parallel/test-stream-pipeline-http2.js index d7ff08888afb8a..c35cd696bd1e55 100644 --- a/test/parallel/test-stream-pipeline-http2.js +++ b/test/parallel/test-stream-pipeline-http2.js @@ -7,11 +7,11 @@ const { Readable, pipeline } = require('stream'); const http2 = require('http2'); { - const server = http2.createServer((req, res) => { + const server = http2.createServer(common.mustCallAtLeast((req, res) => { pipeline(req, res, common.mustCall()); - }); + })); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const url = `http://localhost:${server.address().port}`; const client = http2.connect(url); const req = client.request({ ':method': 'POST' }); @@ -32,5 +32,5 @@ const http2 = require('http2'); cnt--; if (cnt === 0) rs.destroy(); }); - }); + })); } diff --git a/test/parallel/test-stream-pipeline-listeners.js b/test/parallel/test-stream-pipeline-listeners.js index 81e287b77c7589..456ff1d1124250 100644 --- a/test/parallel/test-stream-pipeline-listeners.js +++ b/test/parallel/test-stream-pipeline-listeners.js @@ -24,10 +24,10 @@ pipeline(a, b, common.mustCall((error) => { assert(a.listenerCount('error') > 0); assert.strictEqual(b.listenerCount('error'), 0); - setTimeout(() => { + setTimeout(common.mustCall(() => { assert.strictEqual(b.listenerCount('error'), 0); b.destroy(new Error('no way')); - }, 100); + }), 100); })); // Async generators @@ -47,10 +47,10 @@ const d = pipeline( assert(c.listenerCount('error') > 0); assert.strictEqual(d.listenerCount('error'), 0); - setTimeout(() => { + setTimeout(common.mustCall(() => { assert.strictEqual(b.listenerCount('error'), 0); d.destroy(new Error('no way')); - }, 100); + }), 100); }) ); @@ -69,8 +69,8 @@ pipeline(e, f, common.mustCall((error) => { assert(e.listenerCount('error') > 0); assert(f.listenerCount('error') > 0); - setTimeout(() => { + setTimeout(common.mustCall(() => { assert(f.listenerCount('error') > 0); f.destroy(new Error('no way')); - }, 100); + }), 100); })); diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index 2bbdabe9d347b1..6220bc15365361 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -170,13 +170,13 @@ tmpdir.refresh(); pipeline(rs, res, () => {}); }); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const req = http.request({ port: server.address().port }); req.end(); - req.on('response', (res) => { + req.on('response', common.mustCall((res) => { const buf = []; res.on('data', (data) => buf.push(data)); res.on('end', common.mustCall(() => { @@ -186,12 +186,12 @@ tmpdir.refresh(); ); server.close(); })); - }); - }); + })); + })); } { - const server = http.createServer((req, res) => { + const server = http.createServer(common.mustCallAtLeast((req, res) => { let sent = false; const rs = new Readable({ read() { @@ -208,7 +208,7 @@ tmpdir.refresh(); }); pipeline(rs, res, () => {}); - }); + })); server.listen(0, () => { const req = http.request({ @@ -226,7 +226,7 @@ tmpdir.refresh(); } { - const server = http.createServer((req, res) => { + const server = http.createServer(common.mustCallAtLeast((req, res) => { let sent = 0; const rs = new Readable({ read() { @@ -241,7 +241,7 @@ tmpdir.refresh(); }); pipeline(rs, res, () => {}); - }); + })); let cnt = 10; @@ -253,27 +253,27 @@ tmpdir.refresh(); } }); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const req = http.request({ port: server.address().port }); req.end(); - req.on('response', (res) => { + req.on('response', common.mustCall((res) => { pipeline(res, badSink, common.mustCall((err) => { assert.deepStrictEqual(err, new Error('kaboom')); server.close(); })); - }); - }); + })); + })); } { - const server = http.createServer((req, res) => { + const server = http.createServer(common.mustCallAtLeast((req, res) => { pipeline(req, res, common.mustSucceed()); - }); + })); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const req = http.request({ port: server.address().port }); @@ -299,11 +299,11 @@ tmpdir.refresh(); if (cnt === 0) rs.destroy(); }); }); - }); + })); } { - const makeTransform = () => { + const makeTransform = common.mustCallAtLeast(() => { const tr = new Transform({ transform(data, enc, cb) { cb(null, data); @@ -312,7 +312,7 @@ tmpdir.refresh(); tr.on('close', common.mustCall()); return tr; - }; + }); const rs = new Readable({ read() { @@ -375,10 +375,10 @@ tmpdir.refresh(); }); const ws = new Writable({ - write(data, enc, cb) { + write: common.mustCallAtLeast((data, enc, cb) => { assert.deepStrictEqual(data, expected.shift()); cb(); - } + }), }); let finished = false; @@ -581,8 +581,8 @@ tmpdir.refresh(); const server = http.Server(function(req, res) { res.write('asd'); }); - server.listen(0, function() { - http.get({ port: this.address().port }, (res) => { + server.listen(0, common.mustCall(function() { + http.get({ port: this.address().port }, common.mustCall((res) => { const stream = new PassThrough(); stream.on('error', common.mustCall()); @@ -597,8 +597,8 @@ tmpdir.refresh(); ); stream.destroy(new Error('oh no')); - }).on('error', common.mustNotCall()); - }); + })).on('error', common.mustNotCall()); + })); } { @@ -1004,9 +1004,9 @@ tmpdir.refresh(); cb(); } }); - pipeline(r, w, (err) => { + pipeline(r, w, common.mustCall((err) => { assert.strictEqual(err, undefined); - }); + })); r.push('asd'); r.push(null); r.emit('close'); @@ -1084,14 +1084,13 @@ tmpdir.refresh(); { const server = http.createServer((req, res) => { req.socket.on('error', common.mustNotCall()); - pipeline(req, new PassThrough(), (err) => { - assert.ifError(err); + pipeline(req, new PassThrough(), common.mustSucceed(() => { res.end(); server.close(); - }); + })); }); - server.listen(0, () => { + server.listen(0, common.mustCall(() => { const req = http.request({ method: 'PUT', port: server.address().port @@ -1099,7 +1098,7 @@ tmpdir.refresh(); req.end('asd123'); req.on('response', common.mustCall()); req.on('error', common.mustNotCall()); - }); + })); } { @@ -1210,10 +1209,10 @@ tmpdir.refresh(); d.push(null); }), final: common.mustCall((cb) => { - setTimeout(() => { + setTimeout(common.mustCall(() => { assert.strictEqual(d.destroyed, false); cb(); - }, 1000); + }), 1000); }), destroy: common.mustNotCall() }); @@ -1254,10 +1253,10 @@ tmpdir.refresh(); d.push(null); }), final: common.mustCall((cb) => { - setTimeout(() => { + setTimeout(common.mustCall(() => { assert.strictEqual(d.destroyed, false); cb(); - }, 1000); + }), 1000); }), // `destroy()` won't be invoked by pipeline since // the writable side has not completed when @@ -1691,11 +1690,11 @@ tmpdir.refresh(); }, }); - pipeline(src, dst, (err) => { + pipeline(src, dst, common.mustCall((err) => { assert.strictEqual(src.closed, true); assert.strictEqual(dst.closed, true); assert.strictEqual(err.message, 'problem'); - }); + })); src.destroy(new Error('problem')); } @@ -1712,7 +1711,7 @@ tmpdir.refresh(); passThroughs.push(new PassThrough()); } - pipeline(src, ...passThroughs, dst, (err) => { + pipeline(src, ...passThroughs, dst, common.mustCall((err) => { assert.strictEqual(src.closed, true); assert.strictEqual(dst.closed, true); assert.strictEqual(err.message, 'problem'); @@ -1720,7 +1719,7 @@ tmpdir.refresh(); for (let i = 0; i < passThroughs.length; i++) { assert.strictEqual(passThroughs[i].closed, true); } - }); + })); src.destroy(new Error('problem')); } diff --git a/test/parallel/test-stream-readable-aborted.js b/test/parallel/test-stream-readable-aborted.js index 9badffc51fc424..0796e1901c7ce4 100644 --- a/test/parallel/test-stream-readable-aborted.js +++ b/test/parallel/test-stream-readable-aborted.js @@ -49,9 +49,9 @@ const { Readable, Duplex } = require('stream'); assert.strictEqual(readable.readableAborted, false); readable.destroy(); assert.strictEqual(readable.readableAborted, false); - queueMicrotask(() => { + queueMicrotask(common.mustCall(() => { assert.strictEqual(readable.readableAborted, false); - }); + })); })); readable.resume(); } diff --git a/test/parallel/test-stream-readable-async-iterators.js b/test/parallel/test-stream-readable-async-iterators.js index beece038772a34..8081b35191a140 100644 --- a/test/parallel/test-stream-readable-async-iterators.js +++ b/test/parallel/test-stream-readable-async-iterators.js @@ -181,18 +181,14 @@ async function tests() { resolved.forEach(common.mustCall( (item, i) => assert.strictEqual(item.value, 'hello-' + i), max)); - errors.slice(0, 1).forEach((promise) => { - promise.catch(common.mustCall((err) => { - assert.strictEqual(err.message, 'kaboom'); - })); - }); + assert.rejects(errors[0], { message: 'kaboom' }).then(common.mustCall()); - errors.slice(1).forEach((promise) => { + errors.slice(1).forEach(common.mustCallAtLeast((promise) => { promise.then(common.mustCall(({ done, value }) => { assert.strictEqual(done, true); assert.strictEqual(value, undefined); })); - }); + })); readable.destroy(new Error('kaboom')); } @@ -643,9 +639,9 @@ async function tests() { this.push('asd'); this.push(null); } - }).on('end', () => { + }).on('end', common.mustCall(() => { assert.strictEqual(r.destroyed, false); - }); + })); for await (const chunk of r) { } // eslint-disable-line no-unused-vars, no-empty assert.strictEqual(r.destroyed, true); @@ -703,15 +699,11 @@ async function tests() { }); r.destroy(); - r.on('close', () => { + r.on('close', common.mustCall(() => { const it = r[Symbol.asyncIterator](); const next = it.next(); - next - .then(common.mustNotCall()) - .catch(common.mustCall((err) => { - assert.strictEqual(err.code, 'ERR_STREAM_PREMATURE_CLOSE'); - })); - }); + assert.rejects(next, { code: 'ERR_STREAM_PREMATURE_CLOSE' }).then(common.mustCall()); + })); } { @@ -812,7 +804,7 @@ async function tests() { response.write('never ends'); }); - server.listen(() => { + server.listen(common.mustCall(() => { _req = http.request(`http://localhost:${server.address().port}`) .on('response', common.mustCall(async (res) => { setTimeout(() => { @@ -834,7 +826,7 @@ async function tests() { })) .on('error', common.mustCall()) .end(); - }); + })); } { @@ -853,12 +845,12 @@ async function tests() { } const str = JSON.stringify({ asd: true }); - const server = http.createServer(async (request, response) => { + const server = http.createServer(common.mustCallAtLeast(async (request, response) => { const body = await getParsedBody(request); response.statusCode = 200; assert.strictEqual(JSON.stringify(body), str); response.end(JSON.stringify(body)); - }).listen(() => { + })).listen(common.mustCall(() => { http .request({ method: 'POST', @@ -866,15 +858,15 @@ async function tests() { port: server.address().port, }) .end(str) - .on('response', async (res) => { + .on('response', common.mustCall(async (res) => { let body = ''; for await (const chunk of res) { body += chunk; } assert.strictEqual(body, str); server.close(); - }); - }); + })); + })); } // To avoid missing some tests if a promise does not resolve diff --git a/test/parallel/test-stream-readable-didRead.js b/test/parallel/test-stream-readable-didRead.js index 878340ba190786..46e8ac6b2986af 100644 --- a/test/parallel/test-stream-readable-didRead.js +++ b/test/parallel/test-stream-readable-didRead.js @@ -30,12 +30,12 @@ function check(readable, data, fn) { } readable.on('close', common.mustCall()); fn(); - setImmediate(() => { + setImmediate(common.mustCall(() => { assert.strictEqual(readable.readableDidRead, data > 0); if (data > 0) { assert.strictEqual(isDisturbed(readable), true); } - }); + })); } { diff --git a/test/parallel/test-stream-readable-ended.js b/test/parallel/test-stream-readable-ended.js index bdd714c9554b81..8f6eed464a4e27 100644 --- a/test/parallel/test-stream-readable-ended.js +++ b/test/parallel/test-stream-readable-ended.js @@ -14,14 +14,14 @@ const assert = require('assert'); { const readable = new Readable(); - readable._read = () => { + readable._read = common.mustCall(() => { // The state ended should start in false. assert.strictEqual(readable.readableEnded, false); readable.push('asd'); assert.strictEqual(readable.readableEnded, false); readable.push(null); assert.strictEqual(readable.readableEnded, false); - }; + }); readable.on('end', common.mustCall(() => { assert.strictEqual(readable.readableEnded, true); diff --git a/test/parallel/test-stream-readable-event.js b/test/parallel/test-stream-readable-event.js index 4f2383508aa61c..dc62b5e566b39c 100644 --- a/test/parallel/test-stream-readable-event.js +++ b/test/parallel/test-stream-readable-event.js @@ -37,11 +37,11 @@ const Readable = require('stream').Readable; // This triggers a 'readable' event, which is lost. r.push(Buffer.from('blerg')); - setTimeout(function() { + setTimeout(common.mustCall(() => { // We're testing what we think we are assert(!r._readableState.reading); r.on('readable', common.mustCall()); - }, 1); + }), 1); } { @@ -57,11 +57,11 @@ const Readable = require('stream').Readable; // This triggers a 'readable' event, which is lost. r.push(Buffer.from('bl')); - setTimeout(function() { + setTimeout(common.mustCall(() => { // Assert we're testing what we think we are assert(r._readableState.reading); r.on('readable', common.mustCall()); - }, 1); + }), 1); } { @@ -77,11 +77,11 @@ const Readable = require('stream').Readable; r.push(Buffer.from('blerg')); r.push(null); - setTimeout(function() { + setTimeout(common.mustCall(() => { // Assert we're testing what we think we are assert(!r._readableState.reading); r.on('readable', common.mustCall()); - }, 1); + }), 1); } { diff --git a/test/parallel/test-stream-readable-hwm-0-no-flow-data.js b/test/parallel/test-stream-readable-hwm-0-no-flow-data.js index 5f0186d720dd63..bdf99d14cc7409 100644 --- a/test/parallel/test-stream-readable-hwm-0-no-flow-data.js +++ b/test/parallel/test-stream-readable-hwm-0-no-flow-data.js @@ -49,7 +49,7 @@ assert.strictEqual(r.readableFlowing, false); // // We use setImmediate here to give the stream enough time to emit all the // events it's about to emit. -setImmediate(() => { +setImmediate(common.mustCall(() => { // Only the _read, push, readable calls have happened. No data must be // emitted yet. @@ -71,7 +71,7 @@ setImmediate(() => { // Using setImmediate again to give the stream enough time to emit all the // events it wants to emit. assert.strictEqual(r.read(), null); - setImmediate(() => { + setImmediate(common.mustCall(() => { // There's a new 'readable' event after the data has been pushed. // The 'end' event will be emitted only after a 'read()'. @@ -100,5 +100,5 @@ setImmediate(() => { ['_read:a', 'push:a', 'readable', 'data:a', '_read:null', 'push:null', 'readable', 'end']); }); - }); -}); + })); +})); diff --git a/test/parallel/test-stream-readable-strategy-option.js b/test/parallel/test-stream-readable-strategy-option.js index a32e70ef2155ea..255e570fdc4c60 100644 --- a/test/parallel/test-stream-readable-strategy-option.js +++ b/test/parallel/test-stream-readable-strategy-option.js @@ -2,7 +2,6 @@ const common = require('../common'); const { Readable } = require('stream'); const assert = require('assert'); -const { strictEqual } = require('assert'); { // Strategy 2 @@ -53,13 +52,13 @@ const { strictEqual } = require('assert'); const stringStream = new ReadableStream( { - start(controller) { + start: common.mustCall((controller) => { // Check if the strategy is being assigned on the init of the ReadableStream - strictEqual(controller.desiredSize, desireSizeExpected); + assert.strictEqual(controller.desiredSize, desireSizeExpected); controller.enqueue('a'); controller.enqueue('b'); controller.close(); - }, + }), }, new CountQueuingStrategy({ highWaterMark: desireSizeExpected }) ); @@ -69,7 +68,7 @@ const { strictEqual } = require('assert'); reader.read().then(common.mustCall()); reader.read().then(common.mustCall()); reader.read().then(({ value, done }) => { - strictEqual(value, undefined); - strictEqual(done, true); + assert.strictEqual(value, undefined); + assert.strictEqual(done, true); }); } diff --git a/test/parallel/test-stream-reduce.js b/test/parallel/test-stream-reduce.js index 42c734305fd559..99029f6f8310d5 100644 --- a/test/parallel/test-stream-reduce.js +++ b/test/parallel/test-stream-reduce.js @@ -103,13 +103,13 @@ function sum(p, c) { // Support for AbortSignal - deep const stream = Readable.from([1, 2, 3]); assert.rejects(async () => { - await stream.reduce(async (p, c, { signal }) => { + await stream.reduce(common.mustCallAtLeast(async (p, c, { signal }) => { signal.addEventListener('abort', common.mustCall(), { once: true }); if (c === 3) { await new Promise(() => {}); // Explicitly do not pass signal here } return Promise.resolve(); - }, 0, { signal: AbortSignal.abort() }); + }, 0), 0, { signal: AbortSignal.abort() }); }, { name: 'AbortError', }).then(common.mustCall(() => { diff --git a/test/parallel/test-stream-transform-final.js b/test/parallel/test-stream-transform-final.js index e0b2b7e40f7610..739324884915ba 100644 --- a/test/parallel/test-stream-transform-final.js +++ b/test/parallel/test-stream-transform-final.js @@ -70,12 +70,12 @@ const t = new stream.Transform({ state++; // finalCallback part 1 assert.strictEqual(state, 10); - setTimeout(function() { + setTimeout(common.mustCall(() => { state++; // finalCallback part 2 assert.strictEqual(state, 11); done(); - }, 100); + }), 100); }, 1), flush: common.mustCall(function(done) { state++; diff --git a/test/parallel/test-stream-transform-flush-data.js b/test/parallel/test-stream-transform-flush-data.js index 51e2c8bc5254e3..38880fcbd826db 100644 --- a/test/parallel/test-stream-transform-flush-data.js +++ b/test/parallel/test-stream-transform-flush-data.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const Transform = require('stream').Transform; @@ -23,6 +23,6 @@ const t = new Transform({ }); t.end(Buffer.from('blerg')); -t.on('data', (data) => { +t.on('data', common.mustCall((data) => { assert.strictEqual(data.toString(), expected); -}); +})); diff --git a/test/parallel/test-stream-unpipe-event.js b/test/parallel/test-stream-unpipe-event.js index 46cc8e8cb0ae9e..3c2e67d29a92ee 100644 --- a/test/parallel/test-stream-unpipe-event.js +++ b/test/parallel/test-stream-unpipe-event.js @@ -22,9 +22,9 @@ class NeverEndReadable extends Readable { dest.on('pipe', common.mustCall()); dest.on('unpipe', common.mustCall()); src.pipe(dest); - setImmediate(() => { + setImmediate(common.mustCall(() => { assert.strictEqual(src._readableState.pipes.length, 0); - }); + })); } { @@ -33,9 +33,9 @@ class NeverEndReadable extends Readable { dest.on('pipe', common.mustCall()); dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); src.pipe(dest); - setImmediate(() => { + setImmediate(common.mustCall(() => { assert.strictEqual(src._readableState.pipes.length, 1); - }); + })); } { @@ -45,9 +45,9 @@ class NeverEndReadable extends Readable { dest.on('unpipe', common.mustCall()); src.pipe(dest); src.unpipe(dest); - setImmediate(() => { + setImmediate(common.mustCall(() => { assert.strictEqual(src._readableState.pipes.length, 0); - }); + })); } { @@ -56,9 +56,9 @@ class NeverEndReadable extends Readable { dest.on('pipe', common.mustCall()); dest.on('unpipe', common.mustCall()); src.pipe(dest, { end: false }); - setImmediate(() => { + setImmediate(common.mustCall(() => { assert.strictEqual(src._readableState.pipes.length, 0); - }); + })); } { @@ -67,9 +67,9 @@ class NeverEndReadable extends Readable { dest.on('pipe', common.mustCall()); dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); src.pipe(dest, { end: false }); - setImmediate(() => { + setImmediate(common.mustCall(() => { assert.strictEqual(src._readableState.pipes.length, 1); - }); + })); } { @@ -79,7 +79,7 @@ class NeverEndReadable extends Readable { dest.on('unpipe', common.mustCall()); src.pipe(dest, { end: false }); src.unpipe(dest); - setImmediate(() => { + setImmediate(common.mustCall(() => { assert.strictEqual(src._readableState.pipes.length, 0); - }); + })); } diff --git a/test/parallel/test-stream-unshift-empty-chunk.js b/test/parallel/test-stream-unshift-empty-chunk.js index e8136a68e9e6aa..5575d9857454d2 100644 --- a/test/parallel/test-stream-unshift-empty-chunk.js +++ b/test/parallel/test-stream-unshift-empty-chunk.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); // This test verifies that stream.unshift(Buffer.alloc(0)) or @@ -74,7 +74,7 @@ const expect = 'xxxxxxxxxx', 'yyyyy' ]; -r.on('end', () => { +r.on('end', common.mustCall(() => { assert.deepStrictEqual(seen, expect); console.log('ok'); -}); +})); diff --git a/test/parallel/test-stream-unshift-read-race.js b/test/parallel/test-stream-unshift-read-race.js index fe110ea285521e..aeb18282ad72ee 100644 --- a/test/parallel/test-stream-unshift-read-race.js +++ b/test/parallel/test-stream-unshift-read-race.js @@ -43,7 +43,7 @@ for (let i = 0; i < data.length; i++) { let pos = 0; let pushedNull = false; -r._read = function(n) { +r._read = common.mustCallAtLeast(function(n) { assert(!pushedNull, '_read after null push'); // Every third chunk is fast @@ -65,7 +65,7 @@ r._read = function(n) { }, 1); } } -}; +}); function pushError() { r.unshift(Buffer.allocUnsafe(1)); diff --git a/test/parallel/test-stream-wrap.js b/test/parallel/test-stream-wrap.js index 670c05fe3f0307..5d6a60f71d67e8 100644 --- a/test/parallel/test-stream-wrap.js +++ b/test/parallel/test-stream-wrap.js @@ -19,10 +19,10 @@ function testShutdown(callback) { const wrap = new StreamWrap(stream); const req = new ShutdownWrap(); - req.oncomplete = function(code) { + req.oncomplete = common.mustCall(function(code) { assert(code < 0); callback(); - }; + }); req.handle = wrap._handle; // Close the handle to simulate diff --git a/test/parallel/test-stream-writable-change-default-encoding.js b/test/parallel/test-stream-writable-change-default-encoding.js index 94a892567c1b21..dafa16580e8e4f 100644 --- a/test/parallel/test-stream-writable-change-default-encoding.js +++ b/test/parallel/test-stream-writable-change-default-encoding.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 stream = require('stream'); @@ -38,17 +38,17 @@ class MyWritable extends stream.Writable { } (function defaultCondingIsUtf8() { - const m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert.strictEqual(enc, 'utf8'); - }, { decodeStrings: false }); + }), { decodeStrings: false }); m.write('foo'); m.end(); }()); (function changeDefaultEncodingToAscii() { - const m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert.strictEqual(enc, 'ascii'); - }, { decodeStrings: false }); + }), { decodeStrings: false }); m.setDefaultEncoding('ascii'); m.write('bar'); m.end(); @@ -69,9 +69,9 @@ assert.throws(() => { }); (function checkVariableCaseEncoding() { - const m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert.strictEqual(enc, 'ascii'); - }, { decodeStrings: false }); + }), { decodeStrings: false }); m.setDefaultEncoding('AsCii'); m.write('bar'); m.end(); diff --git a/test/parallel/test-stream-writable-decoded-encoding.js b/test/parallel/test-stream-writable-decoded-encoding.js index e3caa9928fda8c..6f63c5e6872312 100644 --- a/test/parallel/test-stream-writable-decoded-encoding.js +++ b/test/parallel/test-stream-writable-decoded-encoding.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 stream = require('stream'); @@ -38,21 +38,21 @@ class MyWritable extends stream.Writable { } { - const m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert(isBuffer); assert.strictEqual(type, 'object'); assert.strictEqual(enc, 'buffer'); - }, { decodeStrings: true }); + }), { decodeStrings: true }); m.write('some-text', 'utf8'); m.end(); } { - const m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert(!isBuffer); assert.strictEqual(type, 'string'); assert.strictEqual(enc, 'utf8'); - }, { decodeStrings: false }); + }), { decodeStrings: false }); m.write('some-text', 'utf8'); m.end(); } @@ -69,11 +69,11 @@ class MyWritable extends stream.Writable { } { - const w = new MyWritable(function(isBuffer, type, enc) { + const w = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert(!isBuffer); assert.strictEqual(type, 'string'); assert.strictEqual(enc, 'hex'); - }, { + }), { defaultEncoding: 'hex', decodeStrings: false }); @@ -82,11 +82,11 @@ class MyWritable extends stream.Writable { } { - const w = new MyWritable(function(isBuffer, type, enc) { + const w = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert(!isBuffer); assert.strictEqual(type, 'string'); assert.strictEqual(enc, 'utf8'); - }, { + }), { defaultEncoding: null, decodeStrings: false }); @@ -95,11 +95,11 @@ class MyWritable extends stream.Writable { } { - const m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(common.mustCall((isBuffer, type, enc) => { assert.strictEqual(type, 'object'); assert.strictEqual(enc, 'utf8'); - }, { defaultEncoding: 'hex', - objectMode: true }); + }), { defaultEncoding: 'hex', + objectMode: true }); m.write({ foo: 'bar' }, 'utf8'); m.end(); } diff --git a/test/parallel/test-stream-writable-destroy.js b/test/parallel/test-stream-writable-destroy.js index 99981a20345fdc..31e9ac40664fdf 100644 --- a/test/parallel/test-stream-writable-destroy.js +++ b/test/parallel/test-stream-writable-destroy.js @@ -52,10 +52,10 @@ const assert = require('assert'); write(chunk, enc, cb) { cb(); } }); - write._destroy = function(err, cb) { + write._destroy = common.mustCall(function(err, cb) { assert.strictEqual(err, expected); cb(err); - }; + }); const expected = new Error('kaboom'); diff --git a/test/parallel/test-stream-writable-ended-state.js b/test/parallel/test-stream-writable-ended-state.js index 2c40c62a9ee9a5..dbd94f1aa80966 100644 --- a/test/parallel/test-stream-writable-ended-state.js +++ b/test/parallel/test-stream-writable-ended-state.js @@ -7,12 +7,12 @@ const stream = require('stream'); const writable = new stream.Writable(); -writable._write = (chunk, encoding, cb) => { +writable._write = common.mustCall((chunk, encoding, cb) => { assert.strictEqual(writable._writableState.ended, false); assert.strictEqual(writable._writableState.writable, undefined); assert.strictEqual(writable.writableEnded, false); cb(); -}; +}); assert.strictEqual(writable._writableState.ended, false); assert.strictEqual(writable._writableState.writable, undefined); diff --git a/test/parallel/test-stream-writable-finished-state.js b/test/parallel/test-stream-writable-finished-state.js index b42137ed0b5d6b..b58e155696350b 100644 --- a/test/parallel/test-stream-writable-finished-state.js +++ b/test/parallel/test-stream-writable-finished-state.js @@ -7,11 +7,11 @@ const stream = require('stream'); const writable = new stream.Writable(); -writable._write = (chunk, encoding, cb) => { +writable._write = common.mustCall((chunk, encoding, cb) => { // The state finished should start in false. assert.strictEqual(writable._writableState.finished, false); cb(); -}; +}); writable.on('finish', common.mustCall(() => { assert.strictEqual(writable._writableState.finished, true); diff --git a/test/parallel/test-stream-writable-finished.js b/test/parallel/test-stream-writable-finished.js index 933a80a2f94930..9871d9daa85732 100644 --- a/test/parallel/test-stream-writable-finished.js +++ b/test/parallel/test-stream-writable-finished.js @@ -14,11 +14,11 @@ const assert = require('assert'); { const writable = new Writable(); - writable._write = (chunk, encoding, cb) => { + writable._write = common.mustCall((chunk, encoding, cb) => { // The state finished should start in false. assert.strictEqual(writable.writableFinished, false); cb(); - }; + }); writable.on('finish', common.mustCall(() => { assert.strictEqual(writable.writableFinished, true); diff --git a/test/parallel/test-stream-writable-null.js b/test/parallel/test-stream-writable-null.js index 99419f1cf9a066..44c1b130a2af86 100644 --- a/test/parallel/test-stream-writable-null.js +++ b/test/parallel/test-stream-writable-null.js @@ -9,6 +9,7 @@ class MyWritable extends stream.Writable { super({ autoDestroy: false, ...options }); } _write(chunk, encoding, callback) { + // eslint-disable-next-line node-core/must-call-assert assert.notStrictEqual(chunk, null); callback(); } @@ -40,8 +41,6 @@ class MyWritable extends stream.Writable { } { // Should not throw. - const m = new MyWritable({ objectMode: true }).on('error', (e) => { - assert.ifError(e || new Error('should not get here')); - }); + const m = new MyWritable({ objectMode: true }).on('error', common.mustNotCall()); m.write(false, assert.ifError); } diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index 5a42411c6f3a93..b4de798e434b5e 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -51,11 +51,10 @@ function test(decode, uncork, multi, next) { function cnt(msg) { expectCount++; const expect = expectCount; - return function(er) { - assert.ifError(er); + return common.mustSucceed(() => { counter++; assert.strictEqual(counter, expect); - }; + }); } const w = new stream.Writable({ decodeStrings: decode }); @@ -112,12 +111,12 @@ function test(decode, uncork, multi, next) { w.end(cnt('end')); - w.on('finish', function() { + w.on('finish', common.mustCall(() => { // Make sure finish comes after all the write cb cnt('finish')(); assert.deepStrictEqual(actualChunks, expectChunks); next(); - }); + })); } { diff --git a/test/parallel/test-stream2-base64-single-char-read-end.js b/test/parallel/test-stream2-base64-single-char-read-end.js index 2e1eb15f9fd010..8643e63bc0f7ef 100644 --- a/test/parallel/test-stream2-base64-single-char-read-end.js +++ b/test/parallel/test-stream2-base64-single-char-read-end.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const { Readable: R, Writable: W } = require('stream'); const assert = require('assert'); @@ -44,10 +44,10 @@ dst._write = function(chunk, enc, cb) { cb(); }; -src.on('end', function() { +src.on('end', common.mustCall(() => { assert.strictEqual(String(Buffer.concat(accum)), 'MQ=='); clearTimeout(timeout); -}); +})); src.pipe(dst); diff --git a/test/parallel/test-stream2-basic.js b/test/parallel/test-stream2-basic.js index 2670deda537c51..f51009241da56e 100644 --- a/test/parallel/test-stream2-basic.js +++ b/test/parallel/test-stream2-basic.js @@ -167,7 +167,7 @@ class TestWriter extends EE { const w = [ new TestWriter(), new TestWriter() ]; let writes = SPLIT; - w[0].on('write', function() { + w[0].on('write', common.mustCallAtLeast(() => { if (--writes === 0) { r.unpipe(); assert.deepStrictEqual(r._readableState.pipes, []); @@ -175,7 +175,7 @@ class TestWriter extends EE { r.pipe(w[1]); assert.deepStrictEqual(r._readableState.pipes, [w[1]]); } - }); + })); let ended = 0; @@ -281,14 +281,14 @@ class TestWriter extends EE { r.push(null); const w1 = new R(); - w1.write = function(chunk) { + w1.write = common.mustCall(function(chunk) { assert.strictEqual(chunk[0], 'one'); w1.emit('close'); process.nextTick(function() { r.pipe(w2); r.pipe(w3); }); - }; + }); w1.end = common.mustNotCall(); r.pipe(w1); @@ -296,7 +296,7 @@ class TestWriter extends EE { const expected = ['two', 'two', 'three', 'three', 'four', 'four']; const w2 = new R(); - w2.write = function(chunk) { + w2.write = common.mustCallAtLeast(function(chunk) { assert.strictEqual(chunk[0], expected.shift()); assert.strictEqual(counter, 0); @@ -312,11 +312,11 @@ class TestWriter extends EE { }, 10); return false; - }; + }); w2.end = common.mustCall(); const w3 = new R(); - w3.write = function(chunk) { + w3.write = common.mustCallAtLeast(function(chunk) { assert.strictEqual(chunk[0], expected.shift()); assert.strictEqual(counter, 1); @@ -332,7 +332,7 @@ class TestWriter extends EE { }, 50); return false; - }; + }); w3.end = common.mustCall(function() { assert.strictEqual(counter, 2); assert.strictEqual(expected.length, 0); @@ -354,11 +354,11 @@ class TestWriter extends EE { assert.strictEqual(v, null); const w = new R(); - w.write = function(buffer) { + w.write = common.mustCall(function(buffer) { written = true; assert.strictEqual(ended, false); assert.strictEqual(buffer.toString(), 'foo'); - }; + }); w.end = common.mustCall(function() { ended = true; diff --git a/test/parallel/test-stream2-compatibility.js b/test/parallel/test-stream2-compatibility.js index d760db8b32271c..b58cd54f80ff8e 100644 --- a/test/parallel/test-stream2-compatibility.js +++ b/test/parallel/test-stream2-compatibility.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const { Readable: R, Writable: W } = require('stream'); const assert = require('assert'); @@ -43,11 +43,11 @@ class TestReader extends R { } const reader = new TestReader(); -setImmediate(function() { +setImmediate(common.mustCall(() => { assert.strictEqual(ondataCalled, 1); console.log('ok'); reader.push(null); -}); +})); class TestWriter extends W { constructor() { diff --git a/test/parallel/test-stream2-httpclient-response-end.js b/test/parallel/test-stream2-httpclient-response-end.js index 73667eb3dd2e92..1a9df08a3078f3 100644 --- a/test/parallel/test-stream2-httpclient-response-end.js +++ b/test/parallel/test-stream2-httpclient-response-end.js @@ -6,8 +6,8 @@ const msg = 'Hello'; const server = http.createServer(function(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(msg); -}).listen(0, function() { - http.get({ port: this.address().port }, function(res) { +}).listen(0, common.mustCall(function() { + http.get({ port: this.address().port }, common.mustCall((res) => { let data = ''; res.on('readable', common.mustCall(function() { console.log('readable event'); @@ -21,5 +21,5 @@ const server = http.createServer(function(req, res) { assert.strictEqual(msg, data); server.close(); })); - }); -}); + })); +})); diff --git a/test/parallel/test-stream2-objects.js b/test/parallel/test-stream2-objects.js index b7ad074628133d..59b28e4a931c4e 100644 --- a/test/parallel/test-stream2-objects.js +++ b/test/parallel/test-stream2-objects.js @@ -216,10 +216,10 @@ function fromArray(list) { // Verify that objects can be written to stream const w = new Writable({ objectMode: true }); - w._write = function(chunk, encoding, cb) { + w._write = common.mustCall(function(chunk, encoding, cb) { assert.deepStrictEqual(chunk, { foo: 'bar' }); cb(); - }; + }); w.on('finish', common.mustCall()); w.write({ foo: 'bar' }); @@ -279,14 +279,14 @@ function fromArray(list) { }); let called = false; - w._write = function(chunk, encoding, cb) { + w._write = common.mustCall(function(chunk, encoding, cb) { assert.strictEqual(chunk, 'foo'); process.nextTick(function() { called = true; cb(); }); - }; + }); w.on('finish', common.mustCall(function() { assert.strictEqual(called, true); diff --git a/test/parallel/test-stream2-push.js b/test/parallel/test-stream2-push.js index 748a77b9c496ba..c3e792ddc5d8cc 100644 --- a/test/parallel/test-stream2-push.js +++ b/test/parallel/test-stream2-push.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 { Readable, Writable } = require('stream'); @@ -130,7 +130,7 @@ function end() { source.emit('end'); assert(!reading); writer.end(stream.read()); - setImmediate(function() { + setImmediate(common.mustCall(() => { assert(ended); - }); + })); } diff --git a/test/parallel/test-stream2-readable-wrap.js b/test/parallel/test-stream2-readable-wrap.js index eebe72bc0dd8ad..7efb015ea45413 100644 --- a/test/parallel/test-stream2-readable-wrap.js +++ b/test/parallel/test-stream2-readable-wrap.js @@ -45,13 +45,13 @@ function runTest(highWaterMark, objectMode, produce) { // Make sure pause is only emitted once. let pausing = false; - r.on('pause', () => { + r.on('pause', common.mustCallAtLeast(() => { assert.strictEqual(pausing, false); pausing = true; process.nextTick(() => { pausing = false; }); - }); + })); let flowing; let chunks = 10; diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 6d233ae6b68107..215399c1d39f6a 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -140,10 +140,7 @@ for (let i = 0; i < chunks.length; i++) { 'utf-16le', undefined ]; - tw.on('finish', function() { - // Got the expected chunks - assert.deepStrictEqual(tw.buffer, chunks); - }); + tw.on('finish', common.mustNotCall()); chunks.forEach(function(chunk, i) { const enc = encodings[i % encodings.length]; @@ -159,11 +156,11 @@ for (let i = 0; i < chunks.length; i++) { decodeStrings: false }); - tw._write = function(chunk, encoding, cb) { + tw._write = common.mustCallAtLeast(function(chunk, encoding, cb) { assert.strictEqual(typeof chunk, 'string'); chunk = Buffer.from(chunk, encoding); return TestWriter.prototype._write.call(this, chunk, encoding, cb); - }; + }); const encodings = [ 'hex', @@ -179,10 +176,7 @@ for (let i = 0; i < chunks.length; i++) { 'utf-16le', undefined ]; - tw.on('finish', function() { - // Got the expected chunks - assert.deepStrictEqual(tw.buffer, chunks); - }); + tw.on('finish', common.mustNotCall()); chunks.forEach(function(chunk, i) { const enc = encodings[i % encodings.length]; @@ -194,10 +188,9 @@ for (let i = 0; i < chunks.length; i++) { { // Verify write callbacks const callbacks = chunks.map(function(chunk, i) { - return [i, function(err) { - assert.strictEqual(err, null); + return [i, common.mustSucceed(() => { callbacks._called[i] = chunk; - }]; + })]; }).reduce(function(set, x) { set[`callback-${x[0]}`] = x[1]; return set; @@ -309,10 +302,10 @@ const helloWorldBuffer = Buffer.from('hello world'); assert.strictEqual(msg.toString(), 'this is the end'); }); let gotError = false; - w.on('error', function(er) { + w.on('error', common.mustCall((er) => { gotError = true; assert.strictEqual(er.message, 'write after end'); - }); + })); w.end('this is the end'); w.end('and so is this'); process.nextTick(common.mustCall(function() { @@ -324,7 +317,7 @@ const helloWorldBuffer = Buffer.from('hello world'); // Verify stream doesn't end while writing const w = new W(); let wrote = false; - w._write = function(chunk, e, cb) { + w._write = common.mustCall(function(chunk, e, cb) { assert.strictEqual(this.writing, undefined); wrote = true; this.writing = true; @@ -332,7 +325,7 @@ const helloWorldBuffer = Buffer.from('hello world'); this.writing = false; cb(); }, 1); - }; + }); w.on('finish', common.mustCall(function() { assert.strictEqual(wrote, true); assert.strictEqual(this.writing, false); diff --git a/test/parallel/test-stream3-cork-end.js b/test/parallel/test-stream3-cork-end.js index 0cbc033a2eadc4..e19d05b2840770 100644 --- a/test/parallel/test-stream3-cork-end.js +++ b/test/parallel/test-stream3-cork-end.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const stream = require('stream'); const Writable = stream.Writable; @@ -18,7 +18,7 @@ let seenEnd = false; const w = new Writable(); // Let's arrange to store the chunks. -w._write = function(chunk, encoding, cb) { +w._write = common.mustCallAtLeast(function(chunk, encoding, cb) { // Stream end event is not seen before the last write. assert.ok(!seenEnd); // Default encoding given none was specified. @@ -26,7 +26,7 @@ w._write = function(chunk, encoding, cb) { seenChunks.push(chunk); cb(); -}; +}); // Let's record the stream end event. w.on('finish', () => { seenEnd = true; @@ -37,13 +37,13 @@ function writeChunks(remainingChunks, callback) { let writeState; if (writeChunk) { - setImmediate(() => { + setImmediate(common.mustCall(() => { writeState = w.write(writeChunk); // We were not told to stop writing. assert.ok(writeState); writeChunks(remainingChunks, callback); - }); + })); } else { callback(); } @@ -60,7 +60,7 @@ seenChunks = []; w.cork(); // Write the bufferedChunks. -writeChunks(inputChunks, () => { +writeChunks(inputChunks, common.mustCall(() => { // Should not have seen anything yet. assert.strictEqual(seenChunks.length, 0); @@ -84,8 +84,8 @@ writeChunks(inputChunks, () => { assert.ok(seen.equals(expected)); } - setImmediate(() => { + setImmediate(common.mustCall(() => { // Stream should have ended in next tick. assert.ok(seenEnd); - }); -}); + })); +})); diff --git a/test/parallel/test-stream3-cork-uncork.js b/test/parallel/test-stream3-cork-uncork.js index dfb901af419803..1328cbdaf0070a 100644 --- a/test/parallel/test-stream3-cork-uncork.js +++ b/test/parallel/test-stream3-cork-uncork.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const stream = require('stream'); const Writable = stream.Writable; @@ -18,13 +18,13 @@ let seenEnd = false; const w = new Writable(); // Let's arrange to store the chunks. -w._write = function(chunk, encoding, cb) { +w._write = common.mustCallAtLeast(function(chunk, encoding, cb) { // Default encoding given none was specified. assert.strictEqual(encoding, 'buffer'); seenChunks.push(chunk); cb(); -}; +}); // Let's record the stream end event. w.on('finish', () => { seenEnd = true; @@ -35,13 +35,13 @@ function writeChunks(remainingChunks, callback) { let writeState; if (writeChunk) { - setImmediate(() => { + setImmediate(common.mustCall(() => { writeState = w.write(writeChunk); // We were not told to stop writing. assert.ok(writeState); writeChunks(remainingChunks, callback); - }); + })); } else { callback(); } @@ -58,7 +58,7 @@ seenChunks = []; w.cork(); // Write the bufferedChunks. -writeChunks(inputChunks, () => { +writeChunks(inputChunks, common.mustCall(() => { // Should not have seen anything yet. assert.strictEqual(seenChunks.length, 0); @@ -79,8 +79,8 @@ writeChunks(inputChunks, () => { assert.ok(seen.equals(expected)); } - setImmediate(() => { + setImmediate(common.mustCall(() => { // The stream should not have been ended. assert.ok(!seenEnd); - }); -}); + })); +})); diff --git a/test/parallel/test-stream3-pause-then-read.js b/test/parallel/test-stream3-pause-then-read.js index 1a3854722052d7..b692c92762b0d8 100644 --- a/test/parallel/test-stream3-pause-then-read.js +++ b/test/parallel/test-stream3-pause-then-read.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 stream = require('stream'); @@ -108,10 +108,10 @@ function pipeLittle() { console.error('pipe a little'); const w = new Writable(); let written = 0; - w.on('finish', () => { + w.on('finish', common.mustCall(() => { assert.strictEqual(written, 200); setImmediate(read1234); - }); + })); w._write = function(chunk, encoding, cb) { written += chunk.length; if (written >= 200) { @@ -160,11 +160,11 @@ function pipe() { written += chunk.length; cb(); }; - w.on('finish', () => { + w.on('finish', common.mustCall(() => { console.error('written', written, totalPushed); assert.strictEqual(written, expectEndingData); assert.strictEqual(totalPushed, expectTotalData); console.log('ok'); - }); + })); r.pipe(w); } diff --git a/test/parallel/test-stream3-pipeline-async-iterator.js b/test/parallel/test-stream3-pipeline-async-iterator.js index ad1e4647777bcd..fb505646c59f78 100644 --- a/test/parallel/test-stream3-pipeline-async-iterator.js +++ b/test/parallel/test-stream3-pipeline-async-iterator.js @@ -21,6 +21,7 @@ const { pipeline } = require('node:stream/promises'); myCustomWritable, ); // Importing here to avoid initializing streams + // eslint-disable-next-line node-core/must-call-assert require('assert').deepStrictEqual(messages, ['Hello', 'World']); })() .then(require('../common').mustCall());