Skip to content

Commit 8b341e9

Browse files
committed
fix more tests
1 parent 068f22f commit 8b341e9

35 files changed

+246
-242
lines changed

test/common/assertSnapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function replaceWindowsLineEndings(str) {
1717
}
1818

1919
function replaceWindowsPaths(str) {
20-
return str.replaceAll(path.win32.sep, path.posix.sep);
20+
return common.isWindows ? str.replaceAll(path.win32.sep, path.posix.sep) : str;
2121
}
2222

2323
function transform(...args) {

test/common/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ function childShouldThrowAndAbort() {
244244
// continuous testing and developers' machines
245245
testCmd += 'ulimit -c 0 && ';
246246
}
247-
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception `;
248-
testCmd += `"${process.argv[1]}" child`;
249-
const child = exec(testCmd);
247+
testCmd += '"$NODE" --abort-on-uncaught-exception ';
248+
testCmd += '"$FILE" child';
249+
const child = exec(testCmd, { env: { NODE: process.argv[0], FILE: process.argv[1] } });
250250
child.on('exit', function onExit(exitCode, signal) {
251251
const errMsg = 'Test should have aborted ' +
252252
`but instead exited with exit code ${exitCode}` +

test/common/inspector-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ class InspectorSession {
255255
const callFrame = message.params.callFrames[0];
256256
const location = callFrame.location;
257257
const scriptPath = this._scriptsIdsByUrl.get(location.scriptId);
258-
assert.strictEqual(scriptPath.toString(),
259-
expectedScriptPath.toString(),
258+
assert.strictEqual(decodeURIComponent(scriptPath),
259+
decodeURIComponent(expectedScriptPath),
260260
`${scriptPath} !== ${expectedScriptPath}`);
261261
assert.strictEqual(location.lineNumber, line);
262262
return true;

test/es-module/test-esm-loader-spawn-promisified.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
2828
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
2929
'--input-type=module',
3030
'--eval',
31-
`import '${fixtures.fileURL('/es-modules/file.unknown')}'`,
31+
`import ${JSON.stringify(fixtures.fileURL('/es-modules/file.unknown'))}`,
3232
]);
3333

3434
assert.match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);

test/parallel/test-child-process-bad-stdio.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ ChildProcess.prototype.spawn = function() {
2727
};
2828

2929
function createChild(options, callback) {
30-
const cmd = `"${process.execPath}" "${__filename}" child`;
30+
const cmd = '"$NODE" "$FILE" child';
31+
options = { ...options, env: { ...options.env, NODE: process.execPath, FILE: __filename } };
3132

3233
return cp.exec(cmd, options, common.mustCall(callback));
3334
}

test/parallel/test-child-process-exec-encoding.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ if (process.argv[2] === 'child') {
1313
const expectedStdout = `${stdoutData}\n`;
1414
const expectedStderr = `${stderrData}\n`;
1515
function run(options, callback) {
16-
const cmd = `"${process.execPath}" "${__filename}" child`;
16+
const cmd = '"$NODE" "$FILE" child';
17+
options = { ...options, env: { ...options.env, NODE: process.execPath, FILE: __filename } };
1718

1819
cp.exec(cmd, options, common.mustSucceed((stdout, stderr) => {
1920
callback(stdout, stderr);

test/parallel/test-child-process-exec-maxbuf.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ function runChecks(err, stdio, streamName, expected) {
1010
assert.deepStrictEqual(stdio[streamName], expected);
1111
}
1212

13+
const env = { NODE: process.execPath };
14+
1315
// default value
1416
{
1517
const cmd =
16-
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024))"`;
18+
'"$NODE" -e "console.log(\'a\'.repeat(1024 * 1024))"';
1719

18-
cp.exec(cmd, common.mustCall((err) => {
20+
cp.exec(cmd, { env }, common.mustCall((err) => {
1921
assert(err instanceof RangeError);
2022
assert.strictEqual(err.message, 'stdout maxBuffer length exceeded');
2123
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
@@ -25,17 +27,17 @@ function runChecks(err, stdio, streamName, expected) {
2527
// default value
2628
{
2729
const cmd =
28-
`${process.execPath} -e "console.log('a'.repeat(1024 * 1024 - 1))"`;
30+
'"$NODE" -e "console.log(\'a\'.repeat(1024 * 1024 - 1))"';
2931

30-
cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
32+
cp.exec(cmd, { env }, common.mustSucceed((stdout, stderr) => {
3133
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
3234
assert.strictEqual(stderr, '');
3335
}));
3436
}
3537

3638
{
37-
const cmd = `"${process.execPath}" -e "console.log('hello world');"`;
38-
const options = { maxBuffer: Infinity };
39+
const cmd = '"$NODE" -e "console.log(\'hello world\');"';
40+
const options = { env, maxBuffer: Infinity };
3941

4042
cp.exec(cmd, options, common.mustSucceed((stdout, stderr) => {
4143
assert.strictEqual(stdout.trim(), 'hello world');
@@ -58,10 +60,11 @@ function runChecks(err, stdio, streamName, expected) {
5860
// default value
5961
{
6062
const cmd =
61-
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024))"`;
63+
'"$NODE" -e "console.log(\'a\'.repeat(1024 * 1024))"';
6264

6365
cp.exec(
6466
cmd,
67+
{ env },
6568
common.mustCall((err, stdout, stderr) => {
6669
runChecks(
6770
err,
@@ -76,9 +79,9 @@ function runChecks(err, stdio, streamName, expected) {
7679
// default value
7780
{
7881
const cmd =
79-
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024 - 1))"`;
82+
'"$NODE" -e "console.log(\'a\'.repeat(1024 * 1024 - 1))"';
8083

81-
cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
84+
cp.exec(cmd, { env }, common.mustSucceed((stdout, stderr) => {
8285
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
8386
assert.strictEqual(stderr, '');
8487
}));
@@ -87,35 +90,35 @@ function runChecks(err, stdio, streamName, expected) {
8790
const unicode = '中文测试'; // length = 4, byte length = 12
8891

8992
{
90-
const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`;
93+
const cmd = `"$NODE" -e "console.log('${unicode}');"`;
9194

9295
cp.exec(
9396
cmd,
94-
{ maxBuffer: 10 },
97+
{ env, maxBuffer: 10 },
9598
common.mustCall((err, stdout, stderr) => {
9699
runChecks(err, { stdout, stderr }, 'stdout', '中文测试\n');
97100
})
98101
);
99102
}
100103

101104
{
102-
const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`;
105+
const cmd = `"$NODE" -e "console.error('${unicode}');"`;
103106

104107
cp.exec(
105108
cmd,
106-
{ maxBuffer: 3 },
109+
{ env, maxBuffer: 3 },
107110
common.mustCall((err, stdout, stderr) => {
108111
runChecks(err, { stdout, stderr }, 'stderr', '中文测');
109112
})
110113
);
111114
}
112115

113116
{
114-
const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`;
117+
const cmd = `"$NODE" -e "console.log('${unicode}');"`;
115118

116119
const child = cp.exec(
117120
cmd,
118-
{ encoding: null, maxBuffer: 10 },
121+
{ encoding: null, env, maxBuffer: 10 },
119122
common.mustCall((err, stdout, stderr) => {
120123
runChecks(err, { stdout, stderr }, 'stdout', '中文测试\n');
121124
})
@@ -125,11 +128,11 @@ const unicode = '中文测试'; // length = 4, byte length = 12
125128
}
126129

127130
{
128-
const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`;
131+
const cmd = `"$NODE" -e "console.error('${unicode}');"`;
129132

130133
const child = cp.exec(
131134
cmd,
132-
{ encoding: null, maxBuffer: 3 },
135+
{ encoding: null, env, maxBuffer: 3 },
133136
common.mustCall((err, stdout, stderr) => {
134137
runChecks(err, { stdout, stderr }, 'stderr', '中文测');
135138
})
@@ -139,11 +142,11 @@ const unicode = '中文测试'; // length = 4, byte length = 12
139142
}
140143

141144
{
142-
const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`;
145+
const cmd = `"$NODE" -e "console.error('${unicode}');"`;
143146

144147
cp.exec(
145148
cmd,
146-
{ encoding: null, maxBuffer: 5 },
149+
{ encoding: null, env, maxBuffer: 5 },
147150
common.mustCall((err, stdout, stderr) => {
148151
const buf = Buffer.from(unicode).slice(0, 5);
149152
runChecks(err, { stdout, stderr }, 'stderr', buf);

test/parallel/test-child-process-exec-std-encoding.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ if (process.argv[2] === 'child') {
1212
console.log(stdoutData);
1313
console.error(stderrData);
1414
} else {
15-
const cmd = `"${process.execPath}" "${__filename}" child`;
16-
const child = cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
15+
const cmd = '"$NODE" "$FILE" child';
16+
const env = { NODE: process.execPath, FILE: __filename };
17+
const child = cp.exec(cmd, { env }, common.mustSucceed((stdout, stderr) => {
1718
assert.strictEqual(stdout, expectedStdout);
1819
assert.strictEqual(stderr, expectedStderr);
1920
}));

test/parallel/test-child-process-exec-timeout-kill.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ if (process.argv[2] === 'child') {
1818
return;
1919
}
2020

21-
const cmd = `"${process.execPath}" "${__filename}" child`;
21+
const cmd = '"$NODE" "$FILE" child';
2222

2323
// Test with a different kill signal.
2424
cp.exec(cmd, {
25+
env: { NODE: process.execPath, FILE: __filename },
2526
timeout: kExpiringParentTimer,
2627
killSignal: 'SIGKILL'
2728
}, common.mustCall((err, stdout, stderr) => {

test/parallel/test-child-process-exec-timeout-not-expired.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ if (process.argv[2] === 'child') {
2222
return;
2323
}
2424

25-
const cmd = `"${process.execPath}" "${__filename}" child`;
25+
const cmd = '"$NODE" "$FILE" child';
2626

2727
cp.exec(cmd, {
28+
env: { NODE: process.execPath, FILE: __filename },
2829
timeout: kTimeoutNotSupposedToExpire
2930
}, common.mustSucceed((stdout, stderr) => {
3031
assert.strictEqual(stdout.trim(), 'child stdout');

0 commit comments

Comments
 (0)