1'use strict'; 2 3const { mustCall } = require('../common'); 4const childProcess = require('child_process'); 5const assert = require('assert'); 6 7if (process.env.CHILD === 'true') { 8 main(); 9} else { 10 // Use inherited stdio child process to prevent test tools from determining 11 // the case as crashed from SIGINT 12 const cp = childProcess.spawn( 13 process.execPath, 14 ['--trace-sigint', __filename], 15 { 16 env: { ...process.env, CHILD: 'true' }, 17 stdio: 'inherit' 18 }); 19 cp.on('exit', mustCall((code, signal) => { 20 assert.strictEqual(signal, null); 21 assert.strictEqual(code, 0); 22 })); 23} 24 25function main() { 26 // Deactivate colors even if the tty does support colors. 27 process.env.NODE_DISABLE_COLORS = '1'; 28 29 const noop = mustCall(() => { 30 process.exit(0); 31 }); 32 process.on('SIGINT', noop); 33 // Try testing re-add 'SIGINT' listeners 34 process.removeListener('SIGINT', noop); 35 process.on('SIGINT', noop); 36 37 process.kill(process.pid, 'SIGINT'); 38 setTimeout(() => { assert.fail('unreachable path'); }, 10 * 1000); 39} 40