1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const cp = require('child_process'); 5const stdoutData = 'foo'; 6const stderrData = 'bar'; 7const expectedStdout = `${stdoutData}\n`; 8const expectedStderr = `${stderrData}\n`; 9 10if (process.argv[2] === 'child') { 11 // The following console calls are part of the test. 12 console.log(stdoutData); 13 console.error(stderrData); 14} else { 15 const cmd = `"${process.execPath}" "${__filename}" child`; 16 const child = cp.exec(cmd, common.mustSucceed((stdout, stderr) => { 17 assert.strictEqual(stdout, expectedStdout); 18 assert.strictEqual(stderr, expectedStderr); 19 })); 20 child.stdout.setEncoding('utf-8'); 21 child.stderr.setEncoding('utf-8'); 22} 23