Skip to content

Commit 2c8fe97

Browse files
gibfahnMylesBorins
authored andcommitted
test: remove envPlus, use Object.assign everywhere
PR-URL: #14845 Backport-PR-URL: #15557 Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent abf6355 commit 2c8fe97

10 files changed

+28
-30
lines changed

test/parallel/test-child-process-env.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ Object.setPrototypeOf(env, {
1313

1414
let child;
1515
if (common.isWindows) {
16-
child = spawn('cmd.exe', ['/c', 'set'], {env: env});
16+
child = spawn('cmd.exe', ['/c', 'set'],
17+
Object.assign({}, process.env, { env: env }));
1718
} else {
18-
child = spawn('/usr/bin/env', [], {env: env});
19+
child = spawn('/usr/bin/env', [], { env: env });
20+
child = spawn('/usr/bin/env', [],
21+
Object.assign({}, process.env, { env: env }));
1922
}
2023

2124

test/parallel/test-child-process-exec-env.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ function after(err, stdout, stderr) {
2323
if (!common.isWindows) {
2424
child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after);
2525
} else {
26-
child = exec('set', { env: { 'HELLO': 'WORLD' } }, after);
26+
child = exec('set',
27+
{ env: Object.assign({}, process.env, { 'HELLO': 'WORLD' }) },
28+
after);
2729
}
2830

2931
child.stdout.setEncoding('utf8');

test/parallel/test-crypto-fips.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ function sharedOpenSSL() {
2323
return process.config.variables.node_shared_openssl;
2424
}
2525

26-
function addToEnv(newVar, value) {
27-
const envCopy = {};
28-
for (const e in process.env) {
29-
envCopy[e] = process.env[e];
30-
}
31-
envCopy[newVar] = value;
32-
return envCopy;
33-
}
34-
3526
function testHelper(stream, args, expectedOutput, cmd, env) {
3627
const fullArgs = args.concat(['-e', `console.log(${cmd})`]);
3728
const child = spawnSync(process.execPath, fullArgs, {
@@ -69,7 +60,7 @@ testHelper(
6960
[],
7061
FIPS_DISABLED,
7162
'require("crypto").fips',
72-
addToEnv('OPENSSL_CONF', ''));
63+
Object.assign({}, process.env, { 'OPENSSL_CONF': '' }));
7364

7465
// --enable-fips should turn FIPS mode on
7566
testHelper(
@@ -114,23 +105,23 @@ if (!sharedOpenSSL()) {
114105
[],
115106
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
116107
'require("crypto").fips',
117-
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
108+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));
118109

119110
// --openssl-config option should override OPENSSL_CONF
120111
testHelper(
121112
'stdout',
122113
[`--openssl-config=${CNF_FIPS_ON}`],
123114
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
124115
'require("crypto").fips',
125-
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
116+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
126117
}
127118

128119
testHelper(
129120
'stdout',
130121
[`--openssl-config=${CNF_FIPS_OFF}`],
131122
FIPS_DISABLED,
132123
'require("crypto").fips',
133-
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
124+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));
134125

135126
// --enable-fips should take precedence over OpenSSL config file
136127
testHelper(
@@ -146,7 +137,7 @@ testHelper(
146137
['--enable-fips'],
147138
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
148139
'require("crypto").fips',
149-
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
140+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
150141

151142
// --force-fips should take precedence over OpenSSL config file
152143
testHelper(
@@ -162,7 +153,7 @@ testHelper(
162153
['--force-fips'],
163154
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
164155
'require("crypto").fips',
165-
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
156+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
166157

167158
// setFipsCrypto should be able to turn FIPS mode on
168159
testHelper(

test/parallel/test-fs-readfile-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const path = require('path');
1212
function test(env, cb) {
1313
const filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js');
1414
const execPath = `"${process.execPath}" "${filename}"`;
15-
const options = { env: Object.assign(process.env, env) };
15+
const options = { env: Object.assign({}, process.env, env) };
1616
exec(execPath, options, common.mustCall((err, stdout, stderr) => {
1717
assert(err);
1818
assert.strictEqual(stdout, '');

test/parallel/test-http-server-stale-close.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
require('../common');
33
const http = require('http');
4-
const util = require('util');
54
const fork = require('child_process').fork;
65

76
if (process.env.NODE_TEST_FORK_PORT) {
@@ -24,7 +23,9 @@ if (process.env.NODE_TEST_FORK_PORT) {
2423
});
2524
server.listen(0, function() {
2625
fork(__filename, {
27-
env: util._extend(process.env, {NODE_TEST_FORK_PORT: this.address().port})
26+
env: Object.assign({}, process.env, {
27+
NODE_TEST_FORK_PORT: this.address().port
28+
})
2829
});
2930
});
3031
}

test/parallel/test-npm-install.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ const pkgPath = path.join(installDir, 'package.json');
3232

3333
fs.writeFileSync(pkgPath, pkgContent);
3434

35-
const env = Object.create(process.env);
36-
env['PATH'] = path.dirname(process.execPath);
37-
env['NPM_CONFIG_PREFIX'] = path.join(npmSandbox, 'npm-prefix');
38-
env['NPM_CONFIG_TMP'] = path.join(npmSandbox, 'npm-tmp');
39-
env['HOME'] = path.join(npmSandbox, 'home');
35+
const env = Object.assign({}, process.env, {
36+
PATH: path.dirname(process.execPath),
37+
NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'),
38+
NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'),
39+
HOME: path.join(npmSandbox, 'home'),
40+
});
4041

4142
exec(`${process.execPath} ${npmPath} install`, {
4243
cwd: installDir,

test/parallel/test-repl-envvars.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const tests = [
3636
];
3737

3838
function run(test) {
39-
const env = test.env;
39+
const env = Object.assign({}, process.env, test.env);
4040
const expected = test.expected;
4141
const opts = {
4242
terminal: true,

test/parallel/test-stdin-script-child.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44

55
const spawn = require('child_process').spawn;
66
const child = spawn(process.execPath, [], {
7-
env: Object.assign(process.env, {
7+
env: Object.assign({}, process.env, {
88
NODE_DEBUG: process.argv[2]
99
})
1010
});

test/sequential/test-net-GH-5504.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function parent() {
4949
const node = process.execPath;
5050

5151
const s = spawn(node, [__filename, 'server'], {
52-
env: Object.assign(process.env, {
52+
env: Object.assign({}, process.env, {
5353
NODE_DEBUG: 'net'
5454
})
5555
});

test/sequential/test-util-debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function test(environ, shouldWrite) {
2626

2727
const spawn = require('child_process').spawn;
2828
const child = spawn(process.execPath, [__filename, 'child'], {
29-
env: Object.assign(process.env, { NODE_DEBUG: environ })
29+
env: Object.assign({}, process.env, { NODE_DEBUG: environ })
3030
});
3131

3232
expectErr = expectErr.split('%PID%').join(child.pid);

0 commit comments

Comments
 (0)