diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index d020768aed..e574e1fbd2 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -196,7 +196,7 @@ exports.singleRun = (mocha, {files = [], exit = false} = {}) => { mocha.files = files; const runner = mocha.run(exit ? exitMocha : exitMochaLater); - process.on('SIGINT', () => { + process.once('SIGINT', () => { debug('aborting runner'); runner.abort(); @@ -204,6 +204,7 @@ exports.singleRun = (mocha, {files = [], exit = false} = {}) => { // 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')); }); }; diff --git a/lib/stats-collector.js b/lib/stats-collector.js index 1c1491ca81..0afa10f1cd 100644 --- a/lib/stats-collector.js +++ b/lib/stats-collector.js @@ -1,8 +1,15 @@ 'use strict'; +/** + * Provides a factory function for a {@link StatsCollector} object. + * @private + * @module + */ + /** * Test statistics collector. * + * @private * @typedef {Object} StatsCollector * @property {number} suites - integer count of suites run. * @property {number} tests - integer count of tests run. @@ -15,14 +22,16 @@ */ /** - * Provides stats such as test duration, - * number of tests passed / failed etc. + * Provides stats such as test duration, number of tests passed / failed etc., by listening for events emitted by `runner`. * - * @public - * @memberof Mocha - * @param {Runner} runner + * @private + * @param {Runner} runner - Runner instance + * @throws {TypeError} If falsy `runner` */ function createStatsCollector(runner) { + /** + * @type StatsCollector + */ var stats = { suites: 0, tests: 0,