From 17b43911898e50b5077619005223f716c995c877 Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Sat, 26 Jun 2021 17:37:15 +0200 Subject: [PATCH] fix(cli): allow targetting same file multiple times (#1708) * fix(cli): allow targetting same file multiple times * Add example to "run multiple scenarios" scenario outline * Update CHANGELOG.md * Deduplicate deduplicate message Co-authored-by: David Goss --- CHANGELOG.md | 1 + .../target_specific_scenarios_by_line.feature | 9 +++++++-- src/cli/configuration_builder.ts | 1 + src/cli/configuration_builder_spec.ts | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b534c2508..8aa03a038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO ### Fixed +* Prevent duplicate scenario execution where the same feature is targeted in multiple line expressions ([#1706](https://github.com/cucumber/cucumber-js/issues/1706)) * Fixed reports banner to point to [new docs](https://cucumber.io/docs/cucumber/environment-variables/) about environment variables ## [7.3.0] (2021-06-17) diff --git a/features/target_specific_scenarios_by_line.feature b/features/target_specific_scenarios_by_line.feature index ae0945edf..8a7870f36 100644 --- a/features/target_specific_scenarios_by_line.feature +++ b/features/target_specific_scenarios_by_line.feature @@ -37,10 +37,15 @@ Feature: Target specific scenarios Then it fails And it runs the scenario "second scenario - X" - Scenario: run multiple scenarios - When I run cucumber-js with `features/a.feature:2:10` + Scenario Outline: run multiple scenarios + When I run cucumber-js with `` Then it fails And it runs the scenarios: | NAME | | first scenario | | second scenario - X | + + Examples: + | args | + | features/a.feature:2:10 | + | features/a.feature:2 features/a.feature:10 | diff --git a/src/cli/configuration_builder.ts b/src/cli/configuration_builder.ts index bdb40c5bd..7aa89dbf5 100644 --- a/src/cli/configuration_builder.ts +++ b/src/cli/configuration_builder.ts @@ -143,6 +143,7 @@ export default class ConfigurationBuilder { async expandFeaturePaths(featurePaths: string[]): Promise { featurePaths = featurePaths.map((p) => p.replace(/(:\d+)*$/g, '')) // Strip line numbers + featurePaths = [...new Set(featurePaths)] // Deduplicate the feature files return this.expandPaths(featurePaths, '.feature') } diff --git a/src/cli/configuration_builder_spec.ts b/src/cli/configuration_builder_spec.ts index c8628a58a..5d1d2c6b5 100644 --- a/src/cli/configuration_builder_spec.ts +++ b/src/cli/configuration_builder_spec.ts @@ -85,6 +85,24 @@ describe('Configuration', () => { expect(supportCodePaths).to.eql([supportCodePath]) }) + it('deduplicates the .feature files before returning', async function () { + // Arrange + const cwd = await buildTestWorkingDirectory() + const relativeFeaturePath = path.join('features', 'a.feature') + const featurePath = path.join(cwd, relativeFeaturePath) + await fsExtra.outputFile(featurePath, '') + const argv = baseArgv.concat([ + `${relativeFeaturePath}:3`, + `${relativeFeaturePath}:4`, + ]) + + // Act + const { featurePaths } = await ConfigurationBuilder.build({ argv, cwd }) + + // Assert + expect(featurePaths).to.eql([featurePath]) + }) + it('returns the appropriate .md and support code paths', async function () { // Arrange const cwd = await buildTestWorkingDirectory()