diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index d020768aed..89aa7a4674 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -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')); + } }); };