Skip to content

Commit cf33bfa

Browse files
committed
fix more test assumptions
1 parent 233d2a3 commit cf33bfa

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
142142
`import assert from 'node:assert';
143143
await Promise.allSettled([
144144
import('nonexistent/file.mjs'),
145-
import('${fixtures.fileURL('/es-modules/file.unknown')}'),
145+
import(${JSON.stringify(fixtures.fileURL('/es-modules/file.unknown'))}),
146146
import('esmHook/badReturnVal.mjs'),
147147
import('esmHook/format.false'),
148148
import('esmHook/format.true'),
@@ -170,7 +170,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
170170
'--input-type=module',
171171
'--eval',
172172
`import assert from 'node:assert';
173-
await import('${fixtures.fileURL('/es-module-loaders/js-as-esm.js')}')
173+
await import(${JSON.stringify(fixtures.fileURL('/es-module-loaders/js-as-esm.js'))})
174174
.then((parsedModule) => {
175175
assert.strictEqual(typeof parsedModule, 'object');
176176
assert.strictEqual(parsedModule.namedExport, 'named-export');
@@ -191,7 +191,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
191191
'--input-type=module',
192192
'--eval',
193193
`import assert from 'node:assert';
194-
await import('${fixtures.fileURL('/es-modules/file.ext')}')
194+
await import(${JSON.stringify(fixtures.fileURL('/es-modules/file.ext'))})
195195
.then((parsedModule) => {
196196
assert.strictEqual(typeof parsedModule, 'object');
197197
const { default: defaultExport } = parsedModule;
@@ -258,7 +258,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
258258
'--input-type=module',
259259
'--eval',
260260
`import assert from 'node:assert';
261-
await import('${fixtures.fileURL('/es-modules/stateful.mjs')}')
261+
await import(${JSON.stringify(fixtures.fileURL('/es-modules/stateful.mjs'))})
262262
.then(({ default: count }) => {
263263
assert.strictEqual(count(), 1);
264264
});`,

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

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

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

2323
cp.exec(cmd, {
24+
env: { NODE: process.execPath, FILE: __filename },
2425
timeout: kExpiringParentTimer,
2526
}, common.mustCall((err, stdout, stderr) => {
2627
console.log('[stdout]', stdout.trim());

test/parallel/test-child-process-execfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const os = require('os');
1010

1111
const fixture = fixtures.path('exit.js');
1212
const echoFixture = fixtures.path('echo.js');
13-
const execOpts = { encoding: 'utf8', shell: true, env: { NODE: process.execPath } };
13+
const execOpts = { encoding: 'utf8', shell: true, env: { NODE: process.execPath, FIXTURE: fixture } };
1414

1515
{
1616
execFile(
@@ -46,7 +46,7 @@ const execOpts = { encoding: 'utf8', shell: true, env: { NODE: process.execPath
4646

4747
{
4848
// Verify the shell option works properly
49-
execFile('"$NODE"', [fixture, 0], execOpts, common.mustSucceed());
49+
execFile('"$NODE"', ['"$FIXTURE"', 0], execOpts, common.mustSucceed());
5050
}
5151

5252
{

test/parallel/test-child-process-promisified.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const exec = promisify(child_process.exec);
88
const execFile = promisify(child_process.execFile);
99

1010
{
11-
const promise = exec(`${process.execPath} -p 42`);
11+
const promise = exec('"$NODE" -p 42', { env: { NODE: process.execPath } });
1212

1313
assert(promise.child instanceof child_process.ChildProcess);
1414
promise.then(common.mustCall((obj) => {

test/parallel/test-fs-read-stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ if (!common.isWindows) {
198198
const filename = `${tmpdir.path}/foo.pipe`;
199199
const mkfifoResult = child_process.spawnSync('mkfifo', [filename]);
200200
if (!mkfifoResult.error) {
201-
child_process.exec(`echo "xyz foobar" > '${filename}'`);
201+
child_process.exec('echo "xyz foobar" > "$FILE"', { env: { FILE: filename } });
202202
const stream = new fs.createReadStream(filename, common.mustNotMutateObjectDeep({ end: 1 }));
203203
stream.data = '';
204204

test/parallel/test-stdout-to-file.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ const tmpFile = path.join(tmpdir.path, 'stdout.txt');
1414
tmpdir.refresh();
1515

1616
function test(size, useBuffer, cb) {
17-
const cmd = `"$NODE" "${
18-
useBuffer ? scriptBuffer : scriptString}" ${size} > "${tmpFile}"`;
17+
const cmd = `"$NODE" "$SCRIPT" ${size} > "$TMP_FILE"`;
1918

2019
try {
2120
fs.unlinkSync(tmpFile);
@@ -25,7 +24,11 @@ function test(size, useBuffer, cb) {
2524

2625
console.log(`${size} chars to ${tmpFile}...`);
2726

28-
childProcess.exec(cmd, { env: { NODE: process.execPath } }, common.mustSucceed(() => {
27+
childProcess.exec(cmd, { env: {
28+
NODE: process.execPath,
29+
SCRIPT: useBuffer ? scriptBuffer : scriptString,
30+
TMP_FILE: tmpFile,
31+
} }, common.mustSucceed(() => {
2932
console.log('done!');
3033

3134
const stat = fs.statSync(tmpFile);

0 commit comments

Comments
 (0)