From 6159b2e68add2dc7da4099099d79a859c1ce47d1 Mon Sep 17 00:00:00 2001 From: stoicchild Date: Sat, 29 Aug 2020 20:16:18 +0900 Subject: [PATCH 1/4] parallel feature: added automation feature --- lib/cli/run-helpers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 017d914f4d..46714a1e35 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -195,7 +195,7 @@ const parallelRun = async (mocha, options, fileCollectParams) => { * @returns {Promise} */ exports.runMocha = async (mocha, options) => { - const { + let { watch = false, extension = [], ignore = [], @@ -215,6 +215,14 @@ exports.runMocha = async (mocha, options) => { spec }; + const files = collectFiles(fileCollectParams); + if(files.length===1) { + if(options.parallel && !options.parallelForce) { + mocha.parallelMode(false); + parallel=false; + } + } + let run; if (watch) { run = parallel ? watchParallelRun : watchRun; From 11570ed42a25e08b72736fca3acd7190b32482ae Mon Sep 17 00:00:00 2001 From: stoicchild Date: Sat, 29 Aug 2020 21:46:11 +0900 Subject: [PATCH 2/4] cli option added: force parallel in running a single file --- lib/cli/run-helpers.js | 3 ++- lib/cli/run-option-metadata.js | 3 ++- lib/cli/run.js | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 46714a1e35..1291d06a34 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -203,7 +203,8 @@ exports.runMocha = async (mocha, options) => { parallel = false, recursive = false, sort = false, - spec = [] + spec = [], + parallelForce = false } = options; const fileCollectParams = { 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..941637e11f 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', { From f5c9375597089410173a3846f497e5adc4c30aa6 Mon Sep 17 00:00:00 2001 From: stoicchild Date: Sun, 30 Aug 2020 15:38:20 +0900 Subject: [PATCH 3/4] fixed lint error --- lib/cli/run-helpers.js | 7 +++---- lib/cli/run.js | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 1291d06a34..6c76851b22 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -217,13 +217,12 @@ exports.runMocha = async (mocha, options) => { }; const files = collectFiles(fileCollectParams); - if(files.length===1) { - if(options.parallel && !options.parallelForce) { + if (files.length === 1) { + if (parallel && !parallelForce) { mocha.parallelMode(false); - parallel=false; + parallel = false; } } - let run; if (watch) { run = parallel ? watchParallelRun : watchRun; diff --git a/lib/cli/run.js b/lib/cli/run.js index 941637e11f..49c2a2231c 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -263,7 +263,7 @@ exports.builder = yargs => }, parallelForce: { description: 'Force Mocha to quit after tests complete', - group: GROUPS.RULES, + group: GROUPS.RULES } }) .positional('spec', { From 0eb8e8347d493a5b5a8bf9dcc7b89b41558340e1 Mon Sep 17 00:00:00 2001 From: stoicchild Date: Sun, 30 Aug 2020 23:20:47 +0900 Subject: [PATCH 4/4] fixed variable in runMocha --- lib/cli/run-helpers.js | 5 +++-- lib/mocha.js | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 6c76851b22..c46e0d16fe 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -195,17 +195,17 @@ const parallelRun = async (mocha, options, fileCollectParams) => { * @returns {Promise} */ exports.runMocha = async (mocha, options) => { - let { + const { watch = false, extension = [], ignore = [], file = [], - parallel = false, recursive = false, sort = false, spec = [], parallelForce = false } = options; + let {parallel} = options; const fileCollectParams = { ignore, @@ -223,6 +223,7 @@ exports.runMocha = async (mocha, options) => { parallel = false; } } + let run; if (watch) { run = parallel ? watchParallelRun : watchRun; 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