mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
test: ensure assertions are reached on more tests
PR-URL: https://github.com/nodejs/node/pull/60760 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
59 files changed
+354
-380
No files matched your search
@@ -204,7 +204,7 @@ export default [
|
||||
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
|
||||
},n*,${
|
||||
// 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: {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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'
|
||||
);
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}));
|
||||
@@ -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');
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}));
|
||||
@@ -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);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -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/);
|
||||
}
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -132,10 +132,10 @@ const { setTimeout } = require('timers/promises');
|
||||
name: 'AbortError',
|
||||
}).then(common.mustCall());
|
||||
|
||||
setImmediate(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
ac.abort();
|
||||
assert.strictEqual(calls, 2);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -104,10 +104,10 @@ const { once } = require('events');
|
||||
name: 'AbortError',
|
||||
}).then(common.mustCall());
|
||||
|
||||
setImmediate(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
ac.abort();
|
||||
assert.strictEqual(calls, 2);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -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);
|
||||
}));
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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']);
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}));
|
||||
@@ -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);
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -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');
|
||||
});
|
||||
}));
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}));
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user