summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-env.js
blob: ad41f978e21768cd211afdc1679886f94c937823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const common = require('../common');
const assert = require('assert');

const spawn = require('child_process').spawn;

const env = {
  'HELLO': 'WORLD'
};
Object.setPrototypeOf(env, {
  'FOO': 'BAR'
});

let child;
if (common.isWindows) {
  child = spawn('cmd.exe', ['/c', 'set'], {env: env});
} else {
  child = spawn('/usr/bin/env', [], {env: env});
}


let response = '';

child.stdout.setEncoding('utf8');

child.stdout.on('data', function(chunk) {
  console.log('stdout: ' + chunk);
  response += chunk;
});

process.on('exit', function() {
  assert.ok(response.indexOf('HELLO=WORLD') >= 0);
  assert.ok(response.indexOf('FOO=BAR') >= 0);
});