diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 017d914f4d..c46e0d16fe 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -200,11 +200,12 @@ exports.runMocha = async (mocha, options) => { extension = [], ignore = [], file = [], - parallel = false, recursive = false, sort = false, - spec = [] + spec = [], + parallelForce = false } = options; + let {parallel} = options; const fileCollectParams = { ignore, @@ -215,6 +216,14 @@ exports.runMocha = async (mocha, options) => { spec }; + const files = collectFiles(fileCollectParams); + if (files.length === 1) { + if (parallel && !parallelForce) { + mocha.parallelMode(false); + parallel = false; + } + } + let run; if (watch) { run = parallel ? watchParallelRun : watchRun; diff --git a/lib/cli/run-option-metadata.js b/lib/cli/run-option-metadata.js index 33cd15ae08..ceb9eda621 100644 --- a/lib/cli/run-option-metadata.js +++ b/lib/cli/run-option-metadata.js @@ -45,7 +45,8 @@ const TYPES = (exports.types = { 'parallel', 'recursive', 'sort', - 'watch' + 'watch', + 'parallelForce' ], number: ['retries', 'jobs'], string: [ diff --git a/lib/cli/run.js b/lib/cli/run.js index 6582a4e2c5..49c2a2231c 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -260,6 +260,10 @@ exports.builder = yargs => requiresArg: true, coerce: list, default: defaults['watch-ignore'] + }, + parallelForce: { + description: 'Force Mocha to quit after tests complete', + group: GROUPS.RULES } }) .positional('spec', { diff --git a/lib/mocha.js b/lib/mocha.js index 350df62dbc..4bd9a874b7 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -123,6 +123,7 @@ exports.Test = require('./test'); * @param {number|string} [options.timeout] - Timeout threshold value. * @param {string} [options.ui] - Interface name. * @param {boolean} [options.parallel] - Run jobs in parallel + * @param {boolean} [options.parallelForce] - Run jobs in parallel * @param {number} [options.jobs] - Max number of worker processes for parallel runs * @param {MochaRootHookObject} [options.rootHooks] - Hooks to bootstrap the root * suite with