Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel feature: disable parallel automatically/ add command line option #4428

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/run-option-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const TYPES = (exports.types = {
'parallel',
'recursive',
'sort',
'watch'
'watch',
'parallelForce'
],
number: ['retries', 'jobs'],
string: [
Expand Down
4 changes: 4 additions & 0 deletions lib/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
1 change: 1 addition & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down