Skip to content
This repository has been archived by the owner on Apr 22, 2023. 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'
environement instead of appending to it. This would break on test
environments where some custom environment variables are needed to make
node work properly.

Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-by: Trevor Norris <[email protected]>
  • Loading branch information
Julien Gilli committed Jan 13, 2015
1 parent 7325fe7 commit e64ee2b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion test/simple/test-child-process-spawnsync-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
var common = require('../common');
var assert = require('assert');
var cp = require('child_process');
var util = require('util');

if (process.argv[2] === 'child') {
console.log(process.env.foo);
} else {
var expected = 'bar';
var child = cp.spawnSync(process.execPath, [__filename, 'child'], {
env: {foo: expected}
env: util._extend(process.env, {foo: expected})
});

assert.equal(child.stdout.toString().trim(), expected);
Expand Down
3 changes: 2 additions & 1 deletion test/simple/test-fs-readfile-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ var common = require('../common');
var assert = require('assert');
var exec = require('child_process').exec;
var path = require('path');
var util = require('util');

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: util._extend(process.env, env || {}) };
exec(execPath, options, function(err, stdout, stderr) {
assert(err);
assert.equal(stdout, '');
Expand Down
5 changes: 3 additions & 2 deletions test/simple/test-net-GH-5504.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

var common = require('../common');
var assert = require('assert');
var util = require('util');

// this test only fails with CentOS 6.3 using kernel version 2.6.32
// On other linuxes and darwin, the `read` call gets an ECONNRESET in
Expand Down Expand Up @@ -74,10 +75,10 @@ function parent() {
var clientExited = false;
var serverListened = false;
var opt = {
env: {
env: util._extend(process.env, {
NODE_DEBUG: 'net',
NODE_COMMON_PORT: process.env.NODE_COMMON_PORT,
}
})
};

process.on('exit', function() {
Expand Down
5 changes: 3 additions & 2 deletions test/simple/test-stdin-script-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

var common = require('../common');
var assert = require('assert');
var util = require('util');

var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [], {
env: {
env: util._extend(process.env, {
NODE_DEBUG: process.argv[2]
}
})
});
var wanted = child.pid + '\n';
var found = '';
Expand Down
3 changes: 2 additions & 1 deletion test/simple/test-util-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

var common = require('../common');
var assert = require('assert');
var util = require('util');

if (process.argv[2] === 'child')
child();
Expand All @@ -47,7 +48,7 @@ function test(environ, shouldWrite) {

var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [__filename, 'child'], {
env: { NODE_DEBUG: environ }
env: util._extend(process.env, { NODE_DEBUG: environ })
});

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

0 comments on commit e64ee2b

Please sign in to comment.