1'use strict'; 2const common = require('../common'); 3if (common.isWindows) { 4 // No way to send CTRL_C_EVENT to processes from JS right now. 5 common.skip('platform not supported'); 6} 7if (!common.isMainThread) 8 common.skip('No signal handling available in Workers'); 9 10const assert = require('assert'); 11const spawn = require('child_process').spawn; 12 13const child = spawn(process.execPath, [ '-i' ], { 14 stdio: [null, null, 2, 'ipc'] 15}); 16 17let stdout = ''; 18child.stdout.setEncoding('utf8'); 19child.stdout.on('data', function(c) { 20 stdout += c; 21}); 22 23child.stdout.once('data', common.mustCall(() => { 24 child.on('message', common.mustCall((msg) => { 25 assert.strictEqual(msg, 'repl is busy'); 26 process.kill(child.pid, 'SIGINT'); 27 child.stdout.once('data', common.mustCall(() => { 28 // Make sure REPL still works. 29 child.stdin.end('"foobar"\n'); 30 })); 31 })); 32 33 child.stdin.write( 34 'vm.runInThisContext("process.send(\'repl is busy\'); while(true){}", ' + 35 '{ breakOnSigint: true });\n' 36 ); 37})); 38 39child.on('close', function(code) { 40 const expected = 'Script execution was interrupted by `SIGINT`'; 41 assert.ok( 42 stdout.includes(expected), 43 `Expected stdout to contain "${expected}", got ${stdout}` 44 ); 45 assert.ok( 46 stdout.includes('foobar'), 47 `Expected stdout to contain "foobar", got ${stdout}` 48 ); 49}); 50