Skip to content

Commit 17b4391

Browse files
nicojsdavidjgoss
andauthored
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 <[email protected]>
1 parent 5b301ef commit 17b4391

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
1919

2020
### Fixed
2121

22+
* Prevent duplicate scenario execution where the same feature is targeted in multiple line expressions ([#1706](https://github.com/cucumber/cucumber-js/issues/1706))
2223
* Fixed reports banner to point to [new docs](https://cucumber.io/docs/cucumber/environment-variables/) about environment variables
2324

2425
## [7.3.0] (2021-06-17)

features/target_specific_scenarios_by_line.feature

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ Feature: Target specific scenarios
3737
Then it fails
3838
And it runs the scenario "second scenario - X"
3939

40-
Scenario: run multiple scenarios
41-
When I run cucumber-js with `features/a.feature:2:10`
40+
Scenario Outline: run multiple scenarios
41+
When I run cucumber-js with `<args>`
4242
Then it fails
4343
And it runs the scenarios:
4444
| NAME |
4545
| first scenario |
4646
| second scenario - X |
47+
48+
Examples:
49+
| args |
50+
| features/a.feature:2:10 |
51+
| features/a.feature:2 features/a.feature:10 |

src/cli/configuration_builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export default class ConfigurationBuilder {
143143

144144
async expandFeaturePaths(featurePaths: string[]): Promise<string[]> {
145145
featurePaths = featurePaths.map((p) => p.replace(/(:\d+)*$/g, '')) // Strip line numbers
146+
featurePaths = [...new Set(featurePaths)] // Deduplicate the feature files
146147
return this.expandPaths(featurePaths, '.feature')
147148
}
148149

src/cli/configuration_builder_spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ describe('Configuration', () => {
8585
expect(supportCodePaths).to.eql([supportCodePath])
8686
})
8787

88+
it('deduplicates the .feature files before returning', async function () {
89+
// Arrange
90+
const cwd = await buildTestWorkingDirectory()
91+
const relativeFeaturePath = path.join('features', 'a.feature')
92+
const featurePath = path.join(cwd, relativeFeaturePath)
93+
await fsExtra.outputFile(featurePath, '')
94+
const argv = baseArgv.concat([
95+
`${relativeFeaturePath}:3`,
96+
`${relativeFeaturePath}:4`,
97+
])
98+
99+
// Act
100+
const { featurePaths } = await ConfigurationBuilder.build({ argv, cwd })
101+
102+
// Assert
103+
expect(featurePaths).to.eql([featurePath])
104+
})
105+
88106
it('returns the appropriate .md and support code paths', async function () {
89107
// Arrange
90108
const cwd = await buildTestWorkingDirectory()

0 commit comments

Comments
 (0)