Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -21,7 +21,7 @@ const server = net.createServer((serverSock) => {
process.exit(0);
}
}, 1));
})
}))
.listen(client);

function client() {
Expand Down
92 changes: 44 additions & 48 deletions test/parallel/test-socketaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
'use strict';

const common = require('../common');
const {
ok,
strictEqual,
throws,
} = require('assert');
const assert = require('assert');
const {
SocketAddress,
} = require('net');
Expand All @@ -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();
});
Expand All @@ -47,80 +43,80 @@ 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', () => {
const sa = new 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', () => {
const sa = new 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'
});
});
Expand All @@ -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', () => {
Expand All @@ -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 = [
Expand All @@ -169,7 +165,7 @@ describe('net.SocketAddress...', () => {
];

bad.forEach((i) => {
strictEqual(SocketAddress.parse(i), undefined);
assert.strictEqual(SocketAddress.parse(i), undefined);
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-spawn-cmd-named-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-sqlite-custom-functions.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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'
);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-stdin-pipe-resume.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand All @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-stdio-pipe-stderr.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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]
Expand All @@ -33,4 +33,4 @@ stream.on('open', () => {
stream.end();
fs.unlinkSync(stderrOutputPath);
fs.unlinkSync(fakeModulePath);
});
}));
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');

if (process.argv[2] === 'child')
Expand All @@ -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');
});
}));
}
4 changes: 2 additions & 2 deletions test/parallel/test-strace-openat-openssl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-big-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -71,4 +71,4 @@ r.once('readable', () => {

chunk = r.read();
assert.strictEqual(chunk, null);
});
}));
8 changes: 4 additions & 4 deletions test/parallel/test-stream-compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}));
}

{
Expand Down Expand Up @@ -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);
});
}));
}

{
Expand Down
Loading
Loading