From 916d981ec63c9eafc1ef37513c001e43e919cbcf Mon Sep 17 00:00:00 2001 From: Beth Griggs Date: Mon, 14 Aug 2017 12:12:49 +0100 Subject: [PATCH] test: preserve env in test cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/14822 Refs: https://github.com/nodejs/node/pull/13390 Reviewed-By: Colin Ihrig Reviewed-By: Refael Ackermann Reviewed-By: Michael Dawson Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- test/parallel/test-env-var-no-warnings.js | 3 ++- test/parallel/test-tls-env-bad-extra-ca.js | 6 +++--- test/parallel/test-tls-env-extra-ca.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-env-var-no-warnings.js b/test/parallel/test-env-var-no-warnings.js index f829443888bc07..ff0421c46858ff 100644 --- a/test/parallel/test-env-var-no-warnings.js +++ b/test/parallel/test-env-var-no-warnings.js @@ -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) => { diff --git a/test/parallel/test-tls-env-bad-extra-ca.js b/test/parallel/test-tls-env-bad-extra-ca.js index 493b659778b2f2..f7e9341ad00757 100644 --- a/test/parallel/test-tls-env-bad-extra-ca.js +++ b/test/parallel/test-tls-env-bad-extra-ca.js @@ -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, diff --git a/test/parallel/test-tls-env-extra-ca.js b/test/parallel/test-tls-env-extra-ca.js index 5f011f33382ac6..4dd12a78b6387c 100644 --- a/test/parallel/test-tls-env-extra-ca.js +++ b/test/parallel/test-tls-env-extra-ca.js @@ -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');