test: properly extend process.env in child_process
PR-URL: https://github.com/nodejs/node/pull/22430 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: George Adams <george.adams@uk.ibm.com>
This commit is contained in:
parent
09fce8562a
commit
dca2f9849c
@ -26,23 +26,21 @@ const os = require('os');
|
|||||||
|
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
|
|
||||||
const env = {
|
const env = Object.assign({}, process.env, {
|
||||||
'HELLO': 'WORLD',
|
'HELLO': 'WORLD',
|
||||||
'UNDEFINED': undefined,
|
'UNDEFINED': undefined,
|
||||||
'NULL': null,
|
'NULL': null,
|
||||||
'EMPTY': ''
|
'EMPTY': ''
|
||||||
};
|
});
|
||||||
Object.setPrototypeOf(env, {
|
Object.setPrototypeOf(env, {
|
||||||
'FOO': 'BAR'
|
'FOO': 'BAR'
|
||||||
});
|
});
|
||||||
|
|
||||||
let child;
|
let child;
|
||||||
if (common.isWindows) {
|
if (common.isWindows) {
|
||||||
child = spawn('cmd.exe', ['/c', 'set'],
|
child = spawn('cmd.exe', ['/c', 'set'], { env });
|
||||||
Object.assign({}, process.env, { env }));
|
|
||||||
} else {
|
} else {
|
||||||
child = spawn('/usr/bin/env', [],
|
child = spawn('/usr/bin/env', [], { env });
|
||||||
Object.assign({}, process.env, { env }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user