Skip to content

Commit

Permalink
modified to reraise SIGINT signal once mochajs#3570
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayasankar-m committed Dec 12, 2018
1 parent bfa6177 commit 83530c4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +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();

// 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;
setImmediate(() => process.kill(process.pid, 'SIGINT'));
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;
// Reraising the signal
setImmediate(() => process.kill(process.pid, 'SIGINT'));
}
});
};

Expand Down

0 comments on commit 83530c4

Please sign in to comment.