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:
Lucas Woo 2018-08-21 17:09:11 +08:00 committed by George Adams
parent 09fce8562a
commit dca2f9849c
No known key found for this signature in database
GPG Key ID: 7B8D7E4421A0916D

View File

@ -26,23 +26,21 @@ const os = require('os');
const spawn = require('child_process').spawn;
const env = {
const env = Object.assign({}, process.env, {
'HELLO': 'WORLD',
'UNDEFINED': undefined,
'NULL': null,
'EMPTY': ''
};
});
Object.setPrototypeOf(env, {
'FOO': 'BAR'
});
let child;
if (common.isWindows) {
child = spawn('cmd.exe', ['/c', 'set'],
Object.assign({}, process.env, { env }));
child = spawn('cmd.exe', ['/c', 'set'], { env });
} else {
child = spawn('/usr/bin/env', [],
Object.assign({}, process.env, { env }));
child = spawn('/usr/bin/env', [], { env });
}