Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
tests: append instead of override environment
Browse files Browse the repository at this point in the history
Some tests that rely on some environment variables being passed to child
processes would fail because they reset the child processes'
environment instead of appending to it. This would break on test
environments where some custom environment variables are needed to make
node work properly.

PORT-FROM: joyent/node @ e64ee2b3f7b4067101b0291f1add842353cd6865
This port is modified to move the function into common.js per
nodejs/node#25 (comment)

PR-URL: nodejs/node#43
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
jasnell authored and Fishrock123 committed Jun 18, 2015
1 parent 33943da commit e11fe0c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var assert = require('assert');
var os = require('os');
var child_process = require('child_process');
var util = require('util');

exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
Expand Down Expand Up @@ -119,7 +120,6 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
});
});

var util = require('util');
for (var i in util) exports[i] = util[i];
//for (var i in exports) global[i] = exports[i];

Expand Down Expand Up @@ -408,3 +408,7 @@ exports.fileExists = function(pathname) {
return false;
}
};

exports.extendEnv = function(env) {
return util._extend(process.env, env);
};
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawnsync-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (process.argv[2] === 'child') {
} else {
var expected = 'bar';
var child = cp.spawnSync(process.execPath, [__filename, 'child'], {
env: {foo: expected}
env: common.extendEnv({foo: expected})
});

assert.equal(child.stdout.toString().trim(), expected);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfile-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var callbacks = 0;
function test(env, cb) {
var filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js');
var execPath = '"' + process.execPath + '" "' + filename + '"';
var options = { env: env || {} };
var options = { env: common.extendEnv(env || {}) };
exec(execPath, options, function(err, stdout, stderr) {
assert(err);
assert.equal(stdout, '');
Expand Down
8 changes: 3 additions & 5 deletions test/sequential/test-net-GH-5504.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ function parent() {
var clientExited = false;
var serverListened = false;
var opt = {
env: {
NODE_DEBUG: 'net',
NODE_COMMON_PORT: process.env.NODE_COMMON_PORT,
}
env: common.extendEnv({
NODE_DEBUG: 'net'
})
};

process.on('exit', function() {
Expand Down Expand Up @@ -105,4 +104,3 @@ function parent() {
});
}
}

4 changes: 2 additions & 2 deletions test/sequential/test-stdin-script-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ var assert = require('assert');

var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [], {
env: {
env: common.extendEnv({
NODE_DEBUG: process.argv[2]
}
})
});
var wanted = child.pid + '\n';
var found = '';
Expand Down
4 changes: 3 additions & 1 deletion test/sequential/test-util-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function test(environ, shouldWrite) {
// env variable is passed to the child to make the test pass.
// this is fixed in the next version of lttng (2.7+), so we can
// remove it at sometime in the future.
env: { NODE_DEBUG: environ, HOME: process.env.HOME }
env: common.extendEnv({
NODE_DEBUG: environ
})
});

expectErr = expectErr.split('%PID%').join(child.pid);
Expand Down

0 comments on commit e11fe0c

Please sign in to comment.