Skip to content

Commit

Permalink
modified SIGINT handling mochajs#3570
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayasankar-m committed Dec 8, 2018
1 parent 4cc711f commit 0667368
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});

0 comments on commit 0667368

Please sign in to comment.