From 956dc5974138729591f87d75b85fa4406644e959 Mon Sep 17 00:00:00 2001 From: jayasankar Date: Wed, 12 Dec 2018 23:36:23 +0530 Subject: [PATCH 1/2] Updated SIGINT handler based on comment from #3570 Signed-off-by: jayasankar --- lib/cli/run-helpers.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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')); + } }); }; From e5d42829533d15f8e6ec02837730335044feb155 Mon Sep 17 00:00:00 2001 From: jayasankar Date: Fri, 14 Dec 2018 06:10:25 +0530 Subject: [PATCH 2/2] updated SIGINT handler - call only once #3570 --- lib/cli/run-helpers.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 89aa7a4674..e574e1fbd2 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -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')); }); };