From 39f3b1ee46054783ef92644415ecda0375e7512b Mon Sep 17 00:00:00 2001 From: eddieloeffen Date: Thu, 30 Nov 2017 09:59:33 +1300 Subject: [PATCH 1/2] Create new CLI option --keep-features-together Add option that passes entire feature files to a worker, rather than individual scenarios. This is useful if your feature files are written with dependencies between scenarios. --- lib/parallel_cucumber/cli/configuration.js | 6 ++++++ lib/parallel_cucumber/runtime.js | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/parallel_cucumber/cli/configuration.js b/lib/parallel_cucumber/cli/configuration.js index 23b89e2..b3bb0a3 100644 --- a/lib/parallel_cucumber/cli/configuration.js +++ b/lib/parallel_cucumber/cli/configuration.js @@ -40,6 +40,11 @@ var Configuration = function(argv) { .options('profiles.profile_name.env.env_name', { describe: 'An environment variable to set when executing Cucumber scenarios for a profile. Replace profile_name in the arg with the name of the profile. Replace env_name with the name of the environment variable' }) + + .options('keep-features-together', { + describe: 'Passes entire feature files to a worker, rather than individual scenarios. This is useful if your feature files are written with dependencies between scenarios.' + }) + .options('cucumber', { describe: 'Use a custom version of cucumber-js. Specifies either a relative path or the name of a module', default: 'cucumber' @@ -68,6 +73,7 @@ var Configuration = function(argv) { self.supportCodePaths = ensureValueIsAnArray(args['require']); self.tags = ensureValueIsAnArray(args['tags']); self.profiles = args['profiles']; + self.keepFeaturesTogether = args['keep-features-together']; self.cucumberPath = args['cucumber']; self.maxRetries = args['max-retries']; self.dryRun = args['dry-run']; diff --git a/lib/parallel_cucumber/runtime.js b/lib/parallel_cucumber/runtime.js index 79d5213..df8ec6f 100644 --- a/lib/parallel_cucumber/runtime.js +++ b/lib/parallel_cucumber/runtime.js @@ -258,7 +258,25 @@ var Runtime = function (configuration) { }); }); - callback(null, tasks); + if (options.keepFeaturesTogether) { + var tasksAsWholeFeatures = []; + var featuresSeen = []; + tasks.forEach(function (task) { + var featureFile = task.featureFilePath.split(":")[0]; + if (featuresSeen.indexOf(featureFile) > -1) { + return; + } + + featuresSeen.push(featureFile); + task.featureFilePath = featureFile; + tasksAsWholeFeatures.push(task); + }) + + callback(null, tasksAsWholeFeatures); + } else { + callback(null, tasks); + } + }; self._getFeatureFileObjects = function (featureFilePath) { From 7da28be287a3f985a079aa1bbf226d785401b100 Mon Sep 17 00:00:00 2001 From: Eddie Loeffen Date: Thu, 30 Nov 2017 10:08:43 +1300 Subject: [PATCH 2/2] Update README.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 7cd95c9..ee9cf1b 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,17 @@ You can configure multiple formats, with each format configured to output to the $ node_modules/.bin/parallel-cucumber-js -f json:./output.json -f progress ``` +### Keeping Feature Files Together + +By default, scenarios will be split up and given to workers without consideration for what feature file they belong to. +You can change this behaviour, to split up tasks as complete feature files, rather than individual scenarios by passing the `--keep-features-together` argument. + +This can be useful if you have designed your cucumber tests to be run as individual features, where the scenarios in a feature file depend on earlier scenarios in the same feature file having run on the same process already. + +``` shell +$ node_modules/.bin/parallel-cucumber-js --keep-features-toghether +``` + ### Example See https://github.com/simondean/parallel-cucumber-js-example for an example