Skip to content

Commit

Permalink
test: remove envPlus, use Object.assign everywhere
Browse files Browse the repository at this point in the history
PR-URL: #14845
Backport-PR-URL: #15557
Fixes: #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>
  • Loading branch information
gibfahn authored and MylesBorins committed Sep 26, 2017
1 parent abf6355 commit 2c8fe97
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 30 deletions.
7 changes: 5 additions & 2 deletions test/parallel/test-child-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ Object.setPrototypeOf(env, {

let child;
if (common.isWindows) {
child = spawn('cmd.exe', ['/c', 'set'], {env: env});
child = spawn('cmd.exe', ['/c', 'set'],
Object.assign({}, process.env, { env: env }));
} else {
child = spawn('/usr/bin/env', [], {env: env});
child = spawn('/usr/bin/env', [], { env: env });
child = spawn('/usr/bin/env', [],
Object.assign({}, process.env, { env: env }));
}


Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-child-process-exec-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function after(err, stdout, stderr) {
if (!common.isWindows) {
child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after);
} else {
child = exec('set', { env: { 'HELLO': 'WORLD' } }, after);
child = exec('set',
{ env: Object.assign({}, process.env, { 'HELLO': 'WORLD' }) },
after);
}

child.stdout.setEncoding('utf8');
Expand Down
21 changes: 6 additions & 15 deletions test/parallel/test-crypto-fips.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ function sharedOpenSSL() {
return process.config.variables.node_shared_openssl;
}

function addToEnv(newVar, value) {
const envCopy = {};
for (const e in process.env) {
envCopy[e] = process.env[e];
}
envCopy[newVar] = value;
return envCopy;
}

function testHelper(stream, args, expectedOutput, cmd, env) {
const fullArgs = args.concat(['-e', `console.log(${cmd})`]);
const child = spawnSync(process.execPath, fullArgs, {
Expand Down Expand Up @@ -69,7 +60,7 @@ testHelper(
[],
FIPS_DISABLED,
'require("crypto").fips',
addToEnv('OPENSSL_CONF', ''));
Object.assign({}, process.env, { 'OPENSSL_CONF': '' }));

// --enable-fips should turn FIPS mode on
testHelper(
Expand Down Expand Up @@ -114,23 +105,23 @@ if (!sharedOpenSSL()) {
[],
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
'require("crypto").fips',
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));

// --openssl-config option should override OPENSSL_CONF
testHelper(
'stdout',
[`--openssl-config=${CNF_FIPS_ON}`],
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
'require("crypto").fips',
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
}

testHelper(
'stdout',
[`--openssl-config=${CNF_FIPS_OFF}`],
FIPS_DISABLED,
'require("crypto").fips',
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));

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

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

// setFipsCrypto should be able to turn FIPS mode on
testHelper(
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfile-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const path = require('path');
function test(env, cb) {
const filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js');
const execPath = `"${process.execPath}" "${filename}"`;
const options = { env: Object.assign(process.env, env) };
const options = { env: Object.assign({}, process.env, env) };
exec(execPath, options, common.mustCall((err, stdout, stderr) => {
assert(err);
assert.strictEqual(stdout, '');
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-http-server-stale-close.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
require('../common');
const http = require('http');
const util = require('util');
const fork = require('child_process').fork;

if (process.env.NODE_TEST_FORK_PORT) {
Expand All @@ -24,7 +23,9 @@ if (process.env.NODE_TEST_FORK_PORT) {
});
server.listen(0, function() {
fork(__filename, {
env: util._extend(process.env, {NODE_TEST_FORK_PORT: this.address().port})
env: Object.assign({}, process.env, {
NODE_TEST_FORK_PORT: this.address().port
})
});
});
}
11 changes: 6 additions & 5 deletions test/parallel/test-npm-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ const pkgPath = path.join(installDir, 'package.json');

fs.writeFileSync(pkgPath, pkgContent);

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

exec(`${process.execPath} ${npmPath} install`, {
cwd: installDir,
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-envvars.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const tests = [
];

function run(test) {
const env = test.env;
const env = Object.assign({}, process.env, test.env);
const expected = test.expected;
const opts = {
terminal: true,
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stdin-script-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert');

const spawn = require('child_process').spawn;
const child = spawn(process.execPath, [], {
env: Object.assign(process.env, {
env: Object.assign({}, process.env, {
NODE_DEBUG: process.argv[2]
})
});
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-net-GH-5504.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function parent() {
const node = process.execPath;

const s = spawn(node, [__filename, 'server'], {
env: Object.assign(process.env, {
env: Object.assign({}, process.env, {
NODE_DEBUG: 'net'
})
});
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-util-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function test(environ, shouldWrite) {

const spawn = require('child_process').spawn;
const child = spawn(process.execPath, [__filename, 'child'], {
env: Object.assign(process.env, { NODE_DEBUG: environ })
env: Object.assign({}, process.env, { NODE_DEBUG: environ })
});

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

0 comments on commit 2c8fe97

Please sign in to comment.