Skip to content

Commit 34e86f9

Browse files
committed
test: rewrite test-child-process-spawn-args
- Use ESM for top-level await - Avoid concurrent child processes in the test - Use `events.once` instead of Promise wrapper - Assert directly on sets PR-URL: #58546 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent f72ce2e commit 34e86f9

2 files changed

Lines changed: 50 additions & 55 deletions

File tree

‎test/parallel/test-child-process-spawn-args.js‎

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This test confirms that `undefined`, `null`, and `[]`
2+
// can be used as a placeholder for the second argument (`args`) of `spawn()`.
3+
// Previously, there was a bug where using `undefined` for the second argument
4+
// caused the third argument (`options`) to be ignored.
5+
// See https://github.com/nodejs/node/issues/24912.
6+
7+
import*ascommonfrom'../common/index.mjs';
8+
importtmpdirfrom'../common/tmpdir.js';
9+
10+
importassertfrom'node:assert';
11+
import{spawn}from'node:child_process';
12+
import{once}from'node:events';
13+
14+
tmpdir.refresh();
15+
16+
constcommand=common.isWindows ? 'cd' : 'pwd';
17+
constoptions={cwd: tmpdir.path};
18+
19+
if(common.isWindows){
20+
// This test is not the case for Windows based systems
21+
// unless the `shell` options equals to `true`
22+
options.shell=true;
23+
}
24+
25+
consttestCases=[
26+
undefined,
27+
null,
28+
[],
29+
];
30+
31+
constexpectedResult=newSet([tmpdir.path.trim().toLowerCase()]);
32+
33+
constactualResults=newSet();
34+
35+
for(consttestCaseoftestCases){
36+
constsubprocess=spawn(command,testCase,options);
37+
38+
letaccumulatedData='';
39+
40+
subprocess.stdout.setEncoding('utf8');
41+
subprocess.stdout.on('data',common.mustCall((data)=>{
42+
accumulatedData+=data;
43+
}));
44+
45+
awaitonce(subprocess.stdout,'end');
46+
47+
actualResults.add(accumulatedData.trim().toLowerCase());
48+
}
49+
50+
assert.deepStrictEqual(actualResults,expectedResult);

0 commit comments

Comments
 (0)