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.

PR-URL: nodejs#14822
Refs: nodejs#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]>
  • Loading branch information
BethGriggs committed Feb 21, 2018
1 parent 9509820 commit 916d981
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 916d981

Please sign in to comment.