From 066736827be632371979cb8c8e8aabc74192b291 Mon Sep 17 00:00:00 2001 From: jayasankar Date: Sat, 8 Dec 2018 22:51:52 +0530 Subject: [PATCH] modified SIGINT handling #3570 --- bin/_mocha | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/bin/_mocha b/bin/_mocha index 742c5d70d5..15d8c8faf8 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -642,11 +642,19 @@ if (program.watch) { runner = mocha.run(program.exit ? exit : exitLater); } -process.on('SIGINT', () => { - runner.abort(); - - // This is a hack: - // Instead of `process.exit(130)`, set runner.failures to 130 (exit code for SIGINT) - // The amount of failures will be emitted as error code later - runner.failures = 130; +process.on('SIGINT', function forceStop() { + if (forceStop.notCalled === undefined) { + runner.abort(); + + // This is a hack: + // Instead of `process.exit(130)`, set runner.failures to 130 (exit code for SIGINT) + // The amount of failures will be emitted as error code later + runner.failures = 130; + forceStop.notCalled = false; + // invoke SIGINT after 2 seconds + setImmediate(() => setTimeout(() => process.emit('SIGINT'), 2000)); + } else { + console.log(' forcefully killing process : ' + process.pid); + process.kill(process.pid, 'SIGINT'); + } });