mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
test: remove envPlus, use Object.assign everywhere
PR-URL: https://github.com/nodejs/node/pull/14845 Backport-PR-URL: https://github.com/nodejs/node/pull/15557 Fixes: https://github.com/nodejs/node/issues/14823 Refs: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
abf6355936
commit
2c8fe9748c
10 files changed
+28
-30
No files matched your search
@@ -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 }));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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, {
|
||||
@@ -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(
|
||||
@@ -114,7 +105,7 @@ 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(
|
||||
@@ -122,7 +113,7 @@ if (!sharedOpenSSL()) {
|
||||
[`--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(
|
||||
@@ -130,7 +121,7 @@ testHelper(
|
||||
[`--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(
|
||||
@@ -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(
|
||||
@@ -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(
|
||||
|
||||
@@ -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, '');
|
||||
|
||||
@@ -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) {
|
||||
@@ -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
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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]
|
||||
})
|
||||
});
|
||||
|
||||
@@ -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'
|
||||
})
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user