1'use strict'; 2// Refs: https://github.com/nodejs/node/issues/947 3const common = require('../common'); 4const assert = require('assert'); 5const cp = require('child_process'); 6 7if (process.argv[2] === 'child') { 8 process.on('message', common.mustCall((msg) => { 9 assert.strictEqual(msg, 'go'); 10 // The following console.log is an integral part 11 // of the test. If this regress, this call will 12 // cause the process to exit with 1 13 console.log('logging should not cause a crash'); 14 process.disconnect(); 15 })); 16} else { 17 // Passing '--inspect', '--inspect-brk' to child.spawn enables 18 // the debugger. This test was added to help debug the fork-based 19 // test with the same name. 20 const child = cp.spawn(process.execPath, [__filename, 'child'], { 21 stdio: ['pipe', 'pipe', 'pipe', 'ipc'] 22 }); 23 24 child.on('close', common.mustCall((exitCode, signal) => { 25 assert.strictEqual(exitCode, 0); 26 assert.strictEqual(signal, null); 27 })); 28 29 child.stdout.destroy(); 30 child.send('go'); 31} 32