-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathchild-process.test.js
More file actions
46 lines (40 loc) · 1.08 KB
/
child-process.test.js
File metadata and controls
46 lines (40 loc) · 1.08 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
/**
* @overview Contains tests for assumptions this library makes about the Node.js
* builtin module `node:child_process`.
* @license MIT
*/
import * as cp from "node:child_process";
import * as process from "node:process";
const nodeMajorVersion = process.versions.node.split(".")[0];
/**
* Test if the 'shell' value from the options prototype is used.
*
* @throws {Error} If the test fails.
*/
export function testShellInheritance() {
const command = "echo 'Hello world!'";
const options = {
shell: "this is definitely not a real shell",
};
let errOwn = false;
try {
cp.execSync(command, options);
} catch {
errOwn = true;
}
let errProto = false;
try {
Object.prototype.shell = options.shell; // eslint-disable-line no-extend-native
cp.execSync(command, {});
} catch {
errProto = true;
} finally {
delete Object.prototype.shell;
}
if (
(nodeMajorVersion >= 22 && errOwn === errProto) ||
(nodeMajorVersion < 22 && errOwn !== errProto)
) {
throw new Error(`own shell error ${errOwn}, proto shell error ${errProto}`);
}
}