10BC0 test: ensure assertions are reachable in `test/sequential` by aduh95 · Pull Request #60412 · nodejs/node · GitHub
[go: up one dir, main page]

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
1 change: 1 addition & 0 deletions test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export default [
'pummel',
'report',
'sea',
'sequential',
'sqlite',
'system-ca',
'test426',
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-child-process-execsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ const args = [
assert.strictEqual(typeof err.pid, 'number');
spawnSyncKeys
.filter((key) => key !== 'pid')
.forEach((key) => {
.forEach(common.mustCallAtLeast((key) => {
assert.deepStrictEqual(err[key], spawnSyncResult[key]);
});
}));
return true;
});
}
Expand Down
16 changes: 8 additions & 8 deletions test/sequential/test-child-process-pass-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const N = 80;
let messageCallbackCount = 0;

function forkWorker() {
const messageCallback = (msg, handle) => {
const messageCallback = common.mustCall((msg, handle) => {
messageCallbackCount++;
assert.strictEqual(msg, 'handle');
assert.ok(handle);
Expand All @@ -32,11 +32,11 @@ function forkWorker() {
recvData += data;
}));

handle.on('end', () => {
handle.on('end', common.mustCall(() => {
assert.strictEqual(recvData, 'hello');
worker.kill();
});
};
}));
});

const worker = fork(__filename, ['child']);
worker.on('error', (err) => {
Expand Down Expand Up @@ -70,13 +70,13 @@ if (process.argv[2] !== 'child') {
// thus no work to do, and will exit immediately, preventing process leaks.
process.on('message', common.mustCall());

const server = net.createServer((c) => {
process.once('message', (msg) => {
const server = net.createServer(common.mustCall((c) => {
process.once('message', common.mustCall((msg) => {
assert.strictEqual(msg, 'got');
c.end('hello');
});
}));
socketConnected();
}).unref();
})).unref();
server.listen(0, common.localhostIPv4, () => {
const { port } = server.address();
socket = net.connect(port, common.localhostIPv4, socketConnected).unref();
Expand Down
5 changes: 2 additions & 3 deletions test/sequential/test-cluster-send-handle-large-payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ if (cluster.isPrimary) {
server.listen(0, common.mustCall(() => {
const port = server.address().port;
const socket = new net.Socket();
socket.connect(port, (err) => {
assert.ifError(err);
socket.connect(port, common.mustSucceed(() => {
worker.send({ payload }, socket);
});
}));
}));
} else {
process.on('message', common.mustCall(({ payload: received }, handle) => {
Expand Down
8 changes: 2 additions & 6 deletions test/sequential/test-debugger-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { spawn } = require('child_process');

const script = fixtures.path('debugger', 'alive.js');

const runTest = async () => {
(async () => {
const target = spawn(process.execPath, [script]);
const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false });

Expand All @@ -24,12 +24,8 @@ const runTest = async () => {
cli.output,
/> 3 {3}\+\+x;/,
'marks the 3rd line');
} catch (error) {
assert.ifError(error);
} finally {
await cli.quit();
target.kill();
}
};

runTest().then(common.mustCall());
})().then(common.mustCall());
32 changes: 13 additions & 19 deletions test/sequential/test-deprecation-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const execFile = require('child_process').execFile;
Expand All @@ -40,49 +40,43 @@ const normal = [depmod];
const noDep = ['--no-deprecation', depmod];
const traceDep = ['--trace-deprecation', depmod];

execFile(node, normal, function(er, stdout, stderr) {
execFile(node, normal, common.mustSucceed((stdout, stderr) => {
console.error('normal: show deprecation warning');
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert.match(stderr, /this function is deprecated/);
console.log('normal ok');
});
}));

execFile(node, noDep, function(er, stdout, stderr) {
execFile(node, noDep, common.mustSucceed((stdout, stderr) => {
console.error('--no-deprecation: silence deprecations');
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert.strictEqual(stderr.trim(), 'This is deprecated');
console.log('silent ok');
});
}));

execFile(node, traceDep, function(er, stdout, stderr) {
execFile(node, traceDep, common.mustSucceed((stdout, stderr) => {
console.error('--trace-deprecation: show stack');
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
const stack = stderr.trim().split('\n');
// Just check the top and bottom.
assert.match(stack[1], /this function is deprecated/);
assert.match(stack[0], /This is deprecated/);
console.log('trace ok');
});
}));

execFile(node, [depUserlandFunction], function(er, stdout, stderr) {
execFile(node, [depUserlandFunction], common.mustSucceed((stdout, stderr) => {
console.error('normal: testing deprecated userland function');
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert.match(stderr, /deprecatedFunction is deprecated/);
console.error('normal: ok');
});
}));

execFile(node, [depUserlandClass], function(er, stdout, stderr) {
assert.strictEqual(er, null);
execFile(node, [depUserlandClass], common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '');
assert.match(stderr, /deprecatedClass is deprecated/);
});
}));

execFile(node, [depUserlandSubClass], function(er, stdout, stderr) {
assert.strictEqual(er, null);
execFile(node, [depUserlandSubClass], common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '');
assert.match(stderr, /deprecatedClass is deprecated/);
});
}));
8 changes: 4 additions & 4 deletions test/sequential/test-dgram-pingpong.js
9E88
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ function pingPongTest(port, host) {
throw e;
});

server.on('listening', function() {
server.on('listening', common.mustCall(() => {
console.log(`server listening on ${port}`);

const client = dgram.createSocket('udp4');

client.on('message', function(msg) {
client.on('message', common.mustCall((msg) => {
assert.strictEqual(msg.toString('ascii'), 'PONG');

client.close();
server.close();
});
}));

client.on('error', function(e) {
throw e;
Expand All @@ -37,7 +37,7 @@ function pingPongTest(port, host) {
}

clientSend();
});
}));
server.bind(port, host);
return server;
}
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-fs-readdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ function assertDirents(dirents) {
assert.strictEqual(dirents.length, expected.length);
dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1));
assert.deepStrictEqual(
dirents.map((dirent) => {
dirents.map(common.mustCallAtLeast((dirent) => {
assert(dirent instanceof fs.Dirent);
assert.notStrictEqual(dirent.name, undefined);
return getDirentPath(dirent);
}),
})),
expected
);
}
Expand Down
6 changes: 1 addition & 5 deletions test/sequential/test-heapdump-flag-custom-dir.js