Skip to content

Commit

Permalink
updated SIGINT handler - call only once mochajs#3570
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayasankar-m committed Dec 14, 2018
1 parent bc37f6a commit e5d4282
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,15 @@ exports.singleRun = (mocha, {files = [], exit = false} = {}) => {
mocha.files = files;
const runner = mocha.run(exit ? exitMocha : exitMochaLater);

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'));
}
process.once('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'));
});
};

Expand Down

0 comments on commit e5d4282

Please sign in to comment.