1'use strict'; 2const { platformTimeout, mustCall } = require('../common'); 3const childProcess = require('child_process'); 4const assert = require('assert'); 5 6if (process.env.CHILD === 'true') { 7 main(); 8} else { 9 // Use inherited stdio child process to prevent test tools from determining 10 // the case as crashed from SIGINT 11 const cp = childProcess.spawn( 12 process.execPath, 13 ['--trace-sigint', __filename], 14 { 15 env: { ...process.env, CHILD: 'true' }, 16 stdio: ['inherit', 'inherit', 'inherit', 'ipc'] 17 }); 18 cp.on('message', mustCall(() => { 19 setTimeout(() => cp.kill('SIGINT'), platformTimeout(100)); 20 })); 21 cp.on('exit', mustCall((code, signal) => { 22 assert.strictEqual(signal, 'SIGINT'); 23 assert.strictEqual(code, null); 24 })); 25} 26 27function main() { 28 // Deactivate colors even if the tty does support colors. 29 process.env.NODE_DISABLE_COLORS = '1'; 30 process.channel.ref(); // Keep event loop alive until the signal is received. 31 process.send('ready'); 32} 33