Skip to content

Commit 2c8fe97

Browse files
gibfahnMylesBorins
authored andcommitted
test: remove envPlus, use Object.assign everywhere
PR-URL: #14845 Backport-PR-URL: #15557Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent abf6355 commit 2c8fe97

10 files changed

Lines changed: 28 additions & 30 deletions

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ Object.setPrototypeOf(env, {
1313

1414
letchild;
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‎

Lines changed: 3 additions & 1 deletion
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‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ function sharedOpenSSL() {
2323
returnprocess.config.variables.node_shared_openssl;
2424
}
2525

26-
functionaddToEnv(newVar,value){
27-
constenvCopy={};
28-
for(consteinprocess.env){
29-
envCopy[e]=process.env[e];
30-
}
31-
envCopy[newVar]=value;
32-
returnenvCopy;
33-
}
34-
3526
functiontestHelper(stream,args,expectedOutput,cmd,env){
3627
constfullArgs=args.concat(['-e',`console.log(${cmd})`]);
3728
constchild=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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const path = require('path');
1212
functiontest(env,cb){
1313
constfilename=path.join(common.fixturesDir,'test-fs-readfile-error.js');
1414
constexecPath=`"${process.execPath}" "${filename}"`;
15-
constoptions={env: Object.assign(process.env,env)};
15+
constoptions={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‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
require('../common');
33
consthttp=require('http');
4-
constutil=require('util');
54
constfork=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‎

Lines changed: 6 additions & 5 deletions
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-
constenv=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+
constenv=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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const tests = [
3636
];
3737

3838
functionrun(test){
39-
constenv=test.env;
39+
constenv=Object.assign({},process.env,test.env);
4040
constexpected=test.expected;
4141
constopts={
4242
terminal: true,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44

55
constspawn=require('child_process').spawn;
66
constchild=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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function parent() {
4949
constnode=process.execPath;
5050

5151
consts=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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function test(environ, shouldWrite) {
2626

2727
constspawn=require('child_process').spawn;
2828
constchild=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)