forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-child-process-spawn-args.mjs
More file actions
50 lines (36 loc) · 1.33 KB
/
test-child-process-spawn-args.mjs
File metadata and controls
50 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// This test confirms that `undefined`, `null`, and `[]`
// can be used as a placeholder for the second argument (`args`) of `spawn()`.
// Previously, there was a bug where using `undefined` for the second argument
// caused the third argument (`options`) to be ignored.
// See https://github.com/nodejs/node/issues/24912.
import * as common from '../common/index.mjs';
import tmpdir from '../common/tmpdir.js';
import assert from 'node:assert';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
tmpdir.refresh();
const command = common.isWindows ? 'cd' : 'pwd';
const options = { cwd: tmpdir.path };
if (common.isWindows) {
// This test is not the case for Windows based systems
// unless the `shell` options equals to `true`
options.shell = true;
}
const testCases = [
undefined,
null,
[],
];
const expectedResult = new Set([tmpdir.path.trim().toLowerCase()]);
const actualResults = new Set();
for (const testCase of testCases) {
const subprocess = spawn(command, testCase, options);
let accumulatedData = '';
subprocess.stdout.setEncoding('utf8');
subprocess.stdout.on('data', common.mustCall((data) => {
accumulatedData += data;
}));
await once(subprocess.stdout, 'end');
actualResults.add(accumulatedData.trim().toLowerCase());
}
assert.deepStrictEqual(actualResults, expectedResult);