Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Refs: #13390
  • Loading branch information
BethGriggs committed Aug 14, 2017
commit 21d36ac84cfa167f18895a70a31b494f8ae77008
5 changes: 3 additions & 2 deletions test/parallel/test-benchmark-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const argv = ['--set', 'algo=sha256',
'--set', 'v=crypto',
'--set', 'writes=1',
'crypto'];

const child = fork(runjs, argv, { env: { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 } });
const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
const child = fork(runjs, argv, { env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-benchmark-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const argv = ['--set', 'type=depth',
'--set', 'thousands=0.001',
'timers'];

const child = fork(runjs, argv, { env: { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 } });
const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(runjs, argv, { env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-env-var-no-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const cp = require('child_process');
if (process.argv[2] === 'child') {
process.emitWarning('foo');
} else {
function test(env) {
function test(newEnv) {
const env = Object.assign({}, process.env, newEnv);
const cmd = `"${process.execPath}" "${__filename}" child`;

cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-env-bad-extra-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ if (process.env.CHILD) {
return tls.createServer({});
}

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

const opts = {
env: env,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-env-extra-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const server = tls.createServer(options, common.mustCall(function(s) {
s.end('bye');
server.close();
})).listen(0, common.mustCall(function() {
const env = {
const env = Object.assign({}, process.env, {
CHILD: 'yes',
PORT: this.address().port,
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca1-cert.pem')
};
});

fork(__filename, { env: env }).on('exit', common.mustCall(function(status) {
assert.strictEqual(status, 0, 'client did not succeed in connecting');
Expand Down
23 changes: 16 additions & 7 deletions test/sequential/test-benchmark-child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ const path = require('path');

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

const child = fork(runjs, ['--set', 'dur=0',
'--set', 'n=1',
'--set', 'len=1',
'--set', 'params=1',
'--set', 'methodName=execSync',
'child_process'],
{ env: { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 } });
const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(
runjs,
[
'--set', 'dur=0',
'--set', 'n=1',
'--set', 'len=1',
'--set', 'params=1',
'--set', 'methodName=execSync',
'child_process'
],
{ env }
);

child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down
4 changes: 3 additions & 1 deletion test/sequential/test-benchmark-net.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ const path = require('path');

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

const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
const child = fork(runjs,
['--set', 'dur=0',
'--set', 'len=1024',
'--set', 'type=buf',
'net'],
{ env: { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 } });
{ env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down