Skip to content

Commit

Permalink
fix: ensure feature paths are properly deduplicated (#2258)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss authored Mar 15, 2023
1 parent 3811f81 commit c495170
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) on how to contribute to Cucumber.

## [Unreleased]
### Fixed
- Ensure feature paths are properly deduplicated ([#2258](https://github.com/cucumber/cucumber-js/pull/2258))

## [9.0.0] - 2023-02-27
### Removed
Expand Down
4 changes: 2 additions & 2 deletions src/api/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ async function expandPaths(
return expanded.flat()
})
)
return expandedPaths.flat().map((x) => path.normalize(x))
const normalized = expandedPaths.flat().map((x) => path.normalize(x))
return [...new Set(normalized)]
}

async function getUnexpandedFeaturePaths(
Expand Down Expand Up @@ -126,7 +127,6 @@ async function 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 await expandPaths(cwd, featurePaths, '.feature')
}

Expand Down
26 changes: 25 additions & 1 deletion src/api/paths_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,31 @@ describe('resolvePaths', () => {
expect(importPaths).to.eql([esmSupportCodePath])
})

it('deduplicates the .feature files before returning', async function () {
it('deduplicates features based on overlapping expressions', async function () {
// Arrange
const cwd = await buildTestWorkingDirectory()
const relativeFeaturePath = path.join('features', 'a.feature')
const featurePath = path.join(cwd, relativeFeaturePath)
await fsExtra.outputFile(featurePath, '')
// Act
const { featurePaths } = await resolvePaths(
new FakeLogger(),
cwd,
{
paths: ['features/*.feature', 'features/a.feature'],
},
{
requireModules: [],
requirePaths: [],
importPaths: [],
}
)

// Assert
expect(featurePaths).to.eql([featurePath])
})

it('deduplicates features based on multiple targets of same path', async function () {
// Arrange
const cwd = await buildTestWorkingDirectory()
const relativeFeaturePath = path.join('features', 'a.feature')
Expand Down

0 comments on commit c495170

Please sign in to comment.