Skip to content

Commit

Permalink
fix(cli): allow targetting same file multiple times (#1708)
Browse files Browse the repository at this point in the history
* 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 <david@davidgoss.co>
  • Loading branch information
nicojs and davidjgoss committed Jun 26, 2021
1 parent 5b301ef commit 17b4391
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions features/target_specific_scenarios_by_line.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<args>`
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 |
1 change: 1 addition & 0 deletions src/cli/configuration_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default class ConfigurationBuilder {

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

Expand Down
18 changes: 18 additions & 0 deletions src/cli/configuration_builder_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 17b4391

Please sign in to comment.