Skip to content

Commit 7facfaa

Browse files
BethGriggsMylesBorins
authored andcommitted
test: preserve env in test cases
Allows env vars to be passed through to child processes. This is needed for things like NODE_TEST_DIR or LD_LIBRARY_PATH if testing the shared library. PR-URL: #14822 Refs: #13390 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b40105d commit 7facfaa

7 files changed

+32
-15
lines changed

test/parallel/test-benchmark-crypto.js

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

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

test/parallel/test-benchmark-timers.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const argv = ['--set', 'type=depth',
1515
'--set', 'thousands=0.001',
1616
'timers'];
1717

18-
const child = fork(runjs, argv, {env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
18+
const env = Object.assign({}, process.env,
19+
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
20+
21+
const child = fork(runjs, argv, { env });
1922
child.on('exit', (code, signal) => {
2023
assert.strictEqual(code, 0);
2124
assert.strictEqual(signal, null);

test/parallel/test-env-var-no-warnings.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const cp = require('child_process');
66
if (process.argv[2] === 'child') {
77
process.emitWarning('foo');
88
} else {
9-
function test(env) {
9+
function test(newEnv) {
10+
const env = Object.assign({}, process.env, newEnv);
1011
const cmd = `"${process.execPath}" "${__filename}" child`;
1112

1213
cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {

test/parallel/test-tls-env-bad-extra-ca.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ if (process.env.CHILD) {
1515
return tls.createServer({});
1616
}
1717

18-
const env = {
18+
const env = Object.assign({}, process.env, {
1919
CHILD: 'yes',
2020
NODE_EXTRA_CA_CERTS: `${common.fixturesDir}/no-such-file-exists`,
21-
};
21+
});
2222

2323
const opts = {
2424
env: env,

test/parallel/test-tls-env-extra-ca.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const server = tls.createServer(options, common.mustCall(function(s) {
3232
s.end('bye');
3333
server.close();
3434
})).listen(0, common.mustCall(function() {
35-
const env = {
35+
const env = Object.assign({}, process.env, {
3636
CHILD: 'yes',
3737
PORT: this.address().port,
3838
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca1-cert.pem')
39-
};
39+
});
4040

4141
fork(__filename, {env: env}).on('exit', common.mustCall(function(status) {
4242
assert.strictEqual(status, 0, 'client did not succeed in connecting');

test/sequential/test-benchmark-child-process.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ const path = require('path');
88

99
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
1010

11-
const child = fork(runjs, ['--set', 'dur=0',
12-
'--set', 'n=1',
13-
'--set', 'len=1',
14-
'--set', 'params=1',
15-
'--set', 'methodName=execSync',
16-
'child_process'],
17-
{env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
11+
const env = Object.assign({}, process.env,
12+
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
13+
14+
const child = fork(
15+
runjs,
16+
[
17+
'--set', 'dur=0',
18+
'--set', 'n=1',
19+
'--set', 'len=1',
20+
'--set', 'params=1',
21+
'--set', 'methodName=execSync',
22+
'child_process'
23+
],
24+
{ env }
25+
);
26+
1827
child.on('exit', (code, signal) => {
1928
assert.strictEqual(code, 0);
2029
assert.strictEqual(signal, null);

test/sequential/test-benchmark-net.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ const path = require('path');
1515

1616
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
1717

18+
const env = Object.assign({}, process.env,
19+
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
1820
const child = fork(runjs,
1921
['--set', 'dur=0',
2022
'--set', 'len=1024',
2123
'--set', 'type=buf',
2224
'net'],
23-
{env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
25+
{ env });
2426
child.on('exit', (code, signal) => {
2527
assert.strictEqual(code, 0);
2628
assert.strictEqual(signal, null);

0 commit comments

Comments
 (0)