Skip to content

Commit

Permalink
Updated SIGINT handler based on comment from mochajs#3570
Browse files Browse the repository at this point in the history
Signed-off-by: jayasankar <jayasankar.m@gmail.com>
  • Loading branch information
Jayasankar-m committed Dec 12, 2018
1 parent 8750ef8 commit 956dc59
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,19 @@ exports.singleRun = (mocha, {files = [], exit = false} = {}) => {
mocha.files = files;
const runner = mocha.run(exit ? exitMocha : exitMochaLater);

process.on('SIGINT', () => {
debug('aborting runner');
runner.abort();
process.on('SIGINT', function forceStop() {
if (forceStop.lock === undefined) {
forceStop.lock = true;
debug('aborting runner');
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;
// 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;
// Reraising the signal
setImmediate(() => process.kill(process.pid, 'SIGINT'));
}
});
};

Expand Down

0 comments on commit 956dc59

Please sign in to comment.