Skip to content
Draft
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
4 changes: 4 additions & 0 deletions test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export default [
'wasm-allocation',
'wpt',
].join(',')}}/**/*.{js,mjs,cjs}`,
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 1 }, (_, i) => String.fromCharCode(0x63 + i, 42)).join(',')
}}.{js,mjs,cjs}`,
],
rules: {
'node-core/must-call-assert': 'error',
Expand Down
40 changes: 20 additions & 20 deletions test/parallel/test-child-process-fork-abort-signal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { mustCall, mustNotCall } = require('../common');
const { strictEqual } = require('assert');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const { fork } = require('child_process');

Expand All @@ -13,11 +13,11 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
assert.strictEqual(err.name, 'AbortError');
}));
process.nextTick(() => ac.abort());
}
Expand All @@ -30,13 +30,13 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
strictEqual(err.cause.name, 'Error');
strictEqual(err.cause.message, 'boom');
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(err.cause.name, 'Error');
assert.strictEqual(err.cause.message, 'boom');
}));
process.nextTick(() => ac.abort(new Error('boom')));
}
Expand All @@ -48,11 +48,11 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
assert.strictEqual(err.name, 'AbortError');
}));
}

Expand All @@ -63,13 +63,13 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
strictEqual(err.cause.name, 'Error');
strictEqual(err.cause.message, 'boom');
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(err.cause.name, 'Error');
assert.strictEqual(err.cause.message, 'boom');
}));
}

Expand All @@ -81,11 +81,11 @@ const { fork } = require('child_process');
killSignal: 'SIGKILL',
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGKILL');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGKILL');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
assert.strictEqual(err.name, 'AbortError');
}));
}

Expand Down
14 changes: 7 additions & 7 deletions test/parallel/test-child-process-fork-timeout-kill-signal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { mustCall } = require('../common');
const { strictEqual, throws } = require('assert');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const { fork } = require('child_process');
const { getEventListeners } = require('events');
Expand All @@ -11,7 +11,7 @@ const { getEventListeners } = require('events');
const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: 5,
});
cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM')));
cp.on('exit', mustCall((code, ks) => assert.strictEqual(ks, 'SIGTERM')));
}

{
Expand All @@ -20,16 +20,16 @@ const { getEventListeners } = require('events');
timeout: 5,
killSignal: 'SIGKILL',
});
cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL')));
cp.on('exit', mustCall((code, ks) => assert.strictEqual(ks, 'SIGKILL')));
}

{
// Verify timeout verification
throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
assert.throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: 'badValue',
}), /ERR_INVALID_ARG_TYPE/);

throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
assert.throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: {},
}), /ERR_INVALID_ARG_TYPE/);
}
Expand All @@ -43,8 +43,8 @@ const { getEventListeners } = require('events');
timeout: 6,
signal,
});
strictEqual(getEventListeners(signal, 'abort').length, 1);
assert.strictEqual(getEventListeners(signal, 'abort').length, 1);
cp.on('exit', mustCall(() => {
strictEqual(getEventListeners(signal, 'abort').length, 0);
assert.strictEqual(getEventListeners(signal, 'abort').length, 0);
}));
}
36 changes: 18 additions & 18 deletions test/parallel/test-child-process-prototype-tampering.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as common from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { EOL } from 'node:os';
import { strictEqual, notStrictEqual, throws } from 'node:assert';
import assert from 'node:assert';
import cp from 'node:child_process';

// TODO(LiviaMedeiros): test on different platforms
Expand All @@ -15,17 +15,17 @@ for (const tamperedCwd of ['', '/tmp', '/not/existing/malicious/path', 42n]) {
Object.prototype.cwd = tamperedCwd;

cp.exec('pwd', common.mustSucceed((out) => {
strictEqual(`${out}`, `${expectedCWD}${EOL}`);
assert.strictEqual(`${out}`, `${expectedCWD}${EOL}`);
}));
strictEqual(`${cp.execSync('pwd')}`, `${expectedCWD}${EOL}`);
assert.strictEqual(`${cp.execSync('pwd')}`, `${expectedCWD}${EOL}`);
cp.execFile('pwd', common.mustSucceed((out) => {
strictEqual(`${out}`, `${expectedCWD}${EOL}`);
assert.strictEqual(`${out}`, `${expectedCWD}${EOL}`);
}));
strictEqual(`${cp.execFileSync('pwd')}`, `${expectedCWD}${EOL}`);
assert.strictEqual(`${cp.execFileSync('pwd')}`, `${expectedCWD}${EOL}`);
cp.spawn('pwd').stdout.on('data', common.mustCall((out) => {
strictEqual(`${out}`, `${expectedCWD}${EOL}`);
assert.strictEqual(`${out}`, `${expectedCWD}${EOL}`);
}));
strictEqual(`${cp.spawnSync('pwd').stdout}`, `${expectedCWD}${EOL}`);
assert.strictEqual(`${cp.spawnSync('pwd').stdout}`, `${expectedCWD}${EOL}`);

delete Object.prototype.cwd;
}
Expand All @@ -34,17 +34,17 @@ for (const tamperedUID of [0, 1, 999, 1000, 0n, 'gwak']) {
Object.prototype.uid = tamperedUID;

cp.exec('id -u', common.mustSucceed((out) => {
strictEqual(`${out}`, `${expectedUID}${EOL}`);
assert.strictEqual(`${out}`, `${expectedUID}${EOL}`);
}));
strictEqual(`${cp.execSync('id -u')}`, `${expectedUID}${EOL}`);
assert.strictEqual(`${cp.execSync('id -u')}`, `${expectedUID}${EOL}`);
cp.execFile('id', ['-u'], common.mustSucceed((out) => {
strictEqual(`${out}`, `${expectedUID}${EOL}`);
assert.strictEqual(`${out}`, `${expectedUID}${EOL}`);
}));
strictEqual(`${cp.execFileSync('id', ['-u'])}`, `${expectedUID}${EOL}`);
assert.strictEqual(`${cp.execFileSync('id', ['-u'])}`, `${expectedUID}${EOL}`);
cp.spawn('id', ['-u']).stdout.on('data', common.mustCall((out) => {
strictEqual(`${out}`, `${expectedUID}${EOL}`);
assert.strictEqual(`${out}`, `${expectedUID}${EOL}`);
}));
strictEqual(`${cp.spawnSync('id', ['-u']).stdout}`, `${expectedUID}${EOL}`);
assert.strictEqual(`${cp.spawnSync('id', ['-u']).stdout}`, `${expectedUID}${EOL}`);

delete Object.prototype.uid;
}
Expand All @@ -68,24 +68,24 @@ for (const shellCommandArgument of ['-L && echo "tampered"']) {
program.stdout.on('data', common.mustNotCall());

program.on('exit', common.mustCall((code) => {
notStrictEqual(code, 0);
assert.notStrictEqual(code, 0);
}));

cp.execFile(cmd, [shellCommandArgument], { cwd: expectedCWD },
common.mustCall((err) => {
notStrictEqual(err.code, 0);
assert.notStrictEqual(err.code, 0);
})
);

throws(() => {
assert.throws(() => {
cp.execFileSync(cmd, [shellCommandArgument], { cwd: expectedCWD });
}, (e) => {
notStrictEqual(e.status, 0);
assert.notStrictEqual(e.status, 0);
return true;
});

cmdExitCode = cp.spawnSync(cmd, [shellCommandArgument], { cwd: expectedCWD }).status;
notStrictEqual(cmdExitCode, 0);
assert.notStrictEqual(cmdExitCode, 0);

delete Object.prototype.shell;
}
Loading