Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit e64ee2b

Browse files
author
Julien Gilli
committed
tests: append instead of override environment
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]>
1 parent 7325fe7 commit e64ee2b

5 files changed

Lines changed: 12 additions & 7 deletions

File tree

test/simple/test-child-process-spawnsync-env.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
var common = require('../common');
2323
var assert = require('assert');
2424
var cp = require('child_process');
25+
var util = require('util');
2526

2627
if (process.argv[2] === 'child') {
2728
console.log(process.env.foo);
2829
} else {
2930
var expected = 'bar';
3031
var child = cp.spawnSync(process.execPath, [__filename, 'child'], {
31-
env: {foo: expected}
32+
env: util._extend(process.env, {foo: expected})
3233
});
3334

3435
assert.equal(child.stdout.toString().trim(), expected);

test/simple/test-fs-readfile-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ var common = require('../common');
2323
var assert = require('assert');
2424
var exec = require('child_process').exec;
2525
var path = require('path');
26+
var util = require('util');
2627

2728
var callbacks = 0;
2829

2930
function test(env, cb) {
3031
var filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js');
3132
var execPath = process.execPath + ' ' + filename;
32-
var options = { env: env || {} };
33+
var options = { env: util._extend(process.env, env || {}) };
3334
exec(execPath, options, function(err, stdout, stderr) {
3435
assert(err);
3536
assert.equal(stdout, '');

test/simple/test-net-GH-5504.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
var common = require('../common');
2323
var assert = require('assert');
24+
var util = require('util');
2425

2526
// this test only fails with CentOS 6.3 using kernel version 2.6.32
2627
// On other linuxes and darwin, the `read` call gets an ECONNRESET in
@@ -74,10 +75,10 @@ function parent() {
7475
var clientExited = false;
7576
var serverListened = false;
7677
var opt = {
77-
env: {
78+
env: util._extend(process.env, {
7879
NODE_DEBUG: 'net',
7980
NODE_COMMON_PORT: process.env.NODE_COMMON_PORT,
80-
}
81+
})
8182
};
8283

8384
process.on('exit', function() {

test/simple/test-stdin-script-child.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222
var common = require('../common');
2323
var assert = require('assert');
24+
var util = require('util');
2425

2526
var spawn = require('child_process').spawn;
2627
var child = spawn(process.execPath, [], {
27-
env: {
28+
env: util._extend(process.env, {
2829
NODE_DEBUG: process.argv[2]
29-
}
30+
})
3031
});
3132
var wanted = child.pid + '\n';
3233
var found = '';

test/simple/test-util-debug.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
var common = require('../common');
2323
var assert = require('assert');
24+
var util = require('util');
2425

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

4849
var spawn = require('child_process').spawn;
4950
var child = spawn(process.execPath, [__filename, 'child'], {
50-
env: { NODE_DEBUG: environ }
51+
env: util._extend(process.env, { NODE_DEBUG: environ })
5152
});
5253

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

0 commit comments

Comments
 (0)