Skip to content

Commit d2499ca

Browse files
gibfahnMylesBorins
authored andcommitted
test: remove envPlus, use Object.assign everywhere
PR-URL: #14845 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 a83b6e6 commit d2499ca

15 files changed

+38
-39
lines changed

test/parallel/test-benchmark-crypto.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const argv = ['--set', 'algo=sha256',
2727
'--set', 'writes=1',
2828
'crypto'];
2929

30-
const env = Object.assign({}, process.env,
31-
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
32-
const child = fork(runjs, argv, { env });
30+
const child = fork(runjs, argv, { env: Object.assign({}, process.env, {
31+
NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }) });
32+
3333
child.on('exit', (code, signal) => {
3434
assert.strictEqual(code, 0);
3535
assert.strictEqual(signal, null);

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ Object.setPrototypeOf(env, {
3434

3535
let child;
3636
if (common.isWindows) {
37-
child = spawn('cmd.exe', ['/c', 'set'], {env: env});
37+
child = spawn('cmd.exe', ['/c', 'set'],
38+
Object.assign({}, process.env, { env: env }));
3839
} else {
39-
child = spawn('/usr/bin/env', [], {env: env});
40+
child = spawn('/usr/bin/env', [],
41+
Object.assign({}, process.env, { env: env }));
4042
}
4143

4244

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function after(err, stdout, stderr) {
4444
if (!common.isWindows) {
4545
child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after);
4646
} else {
47-
child = exec('set', { env: { 'HELLO': 'WORLD' } }, after);
47+
child = exec('set',
48+
{ env: Object.assign({}, process.env, { 'HELLO': 'WORLD' }) },
49+
after);
4850
}
4951

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

test/parallel/test-cli-node-options.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ disallow('--');
2929
disallow('--no_warnings'); // Node options don't allow '_' instead of '-'.
3030

3131
function disallow(opt) {
32-
const options = {env: {NODE_OPTIONS: opt}};
32+
const options = { env: Object.assign({}, process.env,
33+
{ NODE_OPTIONS: opt }) };
3334
exec(process.execPath, options, common.mustCall(function(err) {
3435
const message = err.message.split(/\r?\n/)[1];
3536
const expect = `${process.execPath}: ${opt} is not allowed in NODE_OPTIONS`;
@@ -71,7 +72,7 @@ function expect(opt, want) {
7172
const printB = require.resolve('../fixtures/printB.js');
7273
const argv = [printB];
7374
const opts = {
74-
env: {NODE_OPTIONS: opt},
75+
env: Object.assign({}, process.env, { NODE_OPTIONS: opt }),
7576
maxBuffer: 1000000000,
7677
};
7778
exec(process.execPath, argv, opts, common.mustCall(function(err, stdout) {

test/parallel/test-crypto-fips.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ function sharedOpenSSL() {
2626
return process.config.variables.node_shared_openssl;
2727
}
2828

29-
function addToEnv(newVar, value) {
30-
const envCopy = {};
31-
for (const e in process.env) {
32-
envCopy[e] = process.env[e];
33-
}
34-
envCopy[newVar] = value;
35-
return envCopy;
36-
}
37-
3829
function testHelper(stream, args, expectedOutput, cmd, env) {
3930
const fullArgs = args.concat(['-e', `console.log(${cmd})`]);
4031
const child = spawnSync(process.execPath, fullArgs, {
@@ -72,7 +63,7 @@ testHelper(
7263
[],
7364
FIPS_DISABLED,
7465
'require("crypto").fips',
75-
addToEnv('OPENSSL_CONF', ''));
66+
Object.assign({}, process.env, { 'OPENSSL_CONF': '' }));
7667

7768
// --enable-fips should turn FIPS mode on
7869
testHelper(
@@ -117,23 +108,23 @@ if (!sharedOpenSSL()) {
117108
[],
118109
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
119110
'require("crypto").fips',
120-
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
111+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));
121112

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

131122
testHelper(
132123
'stdout',
133124
[`--openssl-config=${CNF_FIPS_OFF}`],
134125
FIPS_DISABLED,
135126
'require("crypto").fips',
136-
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
127+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));
137128

138129
// --enable-fips should take precedence over OpenSSL config file
139130
testHelper(
@@ -149,7 +140,7 @@ testHelper(
149140
['--enable-fips'],
150141
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
151142
'require("crypto").fips',
152-
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
143+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
153144

154145
// --force-fips should take precedence over OpenSSL config file
155146
testHelper(
@@ -165,7 +156,7 @@ testHelper(
165156
['--force-fips'],
166157
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
167158
'require("crypto").fips',
168-
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
159+
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
169160

170161
// setFipsCrypto should be able to turn FIPS mode on
171162
testHelper(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const fixtures = require('../common/fixtures');
3333
function test(env, cb) {
3434
const filename = fixtures.path('test-fs-readfile-error.js');
3535
const execPath = `"${process.execPath}" "${filename}"`;
36-
const options = { env: Object.assign(process.env, env) };
36+
const options = { env: Object.assign({}, process.env, env) };
3737
exec(execPath, options, common.mustCall((err, stdout, stderr) => {
3838
assert(err);
3939
assert.strictEqual(stdout, '');

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
'use strict';
2323
require('../common');
2424
const http = require('http');
25-
const util = require('util');
2625
const fork = require('child_process').fork;
2726

2827
if (process.env.NODE_TEST_FORK_PORT) {
@@ -45,7 +44,9 @@ if (process.env.NODE_TEST_FORK_PORT) {
4544
});
4645
server.listen(0, function() {
4746
fork(__filename, {
48-
env: util._extend(process.env, {NODE_TEST_FORK_PORT: this.address().port})
47+
env: Object.assign({}, process.env, {
48+
NODE_TEST_FORK_PORT: this.address().port
49+
})
4950
});
5051
});
5152
}

test/parallel/test-icu-data-dir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const expected =
1717
}
1818

1919
{
20-
const env = { NODE_ICU_DATA: '/' };
20+
const env = Object.assign({}, process.env, { NODE_ICU_DATA: '/' });
2121
const child = spawnSync(process.execPath, ['-e', '0'], { env });
2222
assert(child.stderr.toString().includes(expected));
2323
}

test/parallel/test-inspector-open.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const url = require('url');
1313
if (process.env.BE_CHILD)
1414
return beChild();
1515

16-
const child = fork(__filename, {env: {BE_CHILD: 1}});
16+
const child = fork(__filename,
17+
{ env: Object.assign({}, process.env, { BE_CHILD: 1 }) });
1718

1819
child.once('message', common.mustCall((msg) => {
1920
assert.strictEqual(msg.cmd, 'started');

test/parallel/test-npm-install.js

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

3535
fs.writeFileSync(pkgPath, pkgContent);
3636

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

4344
exec(`${process.execPath} ${npmPath} install`, {
4445
cwd: installDir,

test/parallel/test-pending-deprecation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ switch (process.argv[2]) {
3737

3838
// Test the NODE_PENDING_DEPRECATION environment var.
3939
fork(__filename, ['env'], {
40-
env: {NODE_PENDING_DEPRECATION: 1},
40+
env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }),
4141
silent: true
4242
}).on('exit', common.mustCall((code) => {
4343
assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION'));

test/parallel/test-process-redirect-warnings-env.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ common.refreshTmpDir();
1616
const warnmod = require.resolve(`${common.fixturesDir}/warnings.js`);
1717
const warnpath = path.join(common.tmpDir, 'warnings.txt');
1818

19-
fork(warnmod, {env: {NODE_REDIRECT_WARNINGS: warnpath}})
19+
fork(warnmod, { env: Object.assign({}, process.env,
20+
{ NODE_REDIRECT_WARNINGS: warnpath }) })
2021
.on('exit', common.mustCall(() => {
2122
fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => {
2223
assert.ifError(err);

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-require-symlink.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const assert = require('assert');
55
const path = require('path');
66
const fs = require('fs');
77
const { exec, spawn } = require('child_process');
8-
const util = require('util');
98
const fixtures = require('../common/fixtures');
109

1110
common.refreshTmpDir();
@@ -61,7 +60,7 @@ function test() {
6160

6261
// Also verify that symlinks works for setting preserve via env variables
6362
const childEnv = spawn(node, [linkScript], {
64-
env: util._extend(process.env, {NODE_PRESERVE_SYMLINKS: '1'})
63+
env: Object.assign({}, process.env, { NODE_PRESERVE_SYMLINKS: '1' })
6564
});
6665
childEnv.on('close', function(code, signal) {
6766
assert.strictEqual(code, 0);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('assert');
55
const { spawn } = require('child_process');
66
for (const args of [[], ['-']]) {
77
const child = spawn(process.execPath, args, {
8-
env: Object.assign(process.env, {
8+
env: Object.assign({}, process.env, {
99
NODE_DEBUG: process.argv[2]
1010
})
1111
});

0 commit comments

Comments
 (0)