Skip to content

Commit

Permalink
modified to reraise SIGINT signal once 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 89fc967 commit 84fadfe
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/cli/run-helpers.js
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 84fadfe

Please sign in to comment.