Skip to content

Commit

Permalink
test: preserve env in test cases
Browse files Browse the repository at this point in the history
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.

Backport-PR-URL: #18883
PR-URL: #14822
Refs: #13390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BethGriggs authored and MylesBorins committed Feb 27, 2018
1 parent d333ba5 commit fdf73b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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
6 changes: 3 additions & 3 deletions test/parallel/test-tls-env-bad-extra-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ if (process.env.CHILD) {
return tls.createServer({});
}

const env = {
const env = Object.assign({}, process.env, {
CHILD: 'yes',
NODE_EXTRA_CA_CERTS: `${fixtures.fixturesDir}/no-such-file-exists`
};
NODE_EXTRA_CA_CERTS: `${fixtures.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

0 comments on commit fdf73b1

Please sign in to comment.