Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues with absolute paths #2063

Merged
merged 7 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
- Fix issues with using absolute paths for features ([#2063](https://github.com/cucumber/cucumber-js/pull/2063))

## [8.3.1] - 2022-06-21
### Fixed
Expand Down
5 changes: 5 additions & 0 deletions features/target_specific_scenarios_by_line.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ Feature: Target specific scenarios
| args |
| features/a.feature:2:10 |
| features/a.feature:2 features/a.feature:10 |

Scenario: using absolute paths
When I run cucumber-js with `{{{tmpDir}}}/features/a.feature:2`
Then it fails
And it runs the scenario "first scenario"
10 changes: 9 additions & 1 deletion src/pickle_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,28 @@ export class PickleLineFilter {

constructor(cwd: string, featurePaths: string[] = []) {
this.featureUriToLinesMapping = this.getFeatureUriToLinesMapping({
cwd,
featurePaths,
})
}

getFeatureUriToLinesMapping({
cwd,
featurePaths,
}: {
cwd: string
featurePaths: string[]
}): Record<string, number[]> {
const mapping: Record<string, number[]> = {}
featurePaths.forEach((featurePath) => {
const match = FEATURE_LINENUM_REGEXP.exec(featurePath)
if (doesHaveValue(match)) {
const uri = path.normalize(match[1])
let uri = match[1]
if (path.isAbsolute(uri)) {
uri = path.relative(cwd, uri)
} else {
uri = path.normalize(uri)
}
const linesExpression = match[2]
if (doesHaveValue(linesExpression)) {
if (doesNotHaveValue(mapping[uri])) {
Expand Down
131 changes: 76 additions & 55 deletions src/pickle_filter_spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { beforeEach, describe, it } from 'mocha'
import { expect } from 'chai'
import path from 'path'
import PickleFilter from './pickle_filter'
import { parse } from '../test/gherkin_helpers'

Expand Down Expand Up @@ -37,67 +38,87 @@ describe('PickleFilter', () => {
})

describe('line filters', () => {
beforeEach(function () {
pickleFilter = new PickleFilter({
cwd,
const variants = [
{
name: 'with relative paths',
featurePaths: ['features/a.feature', 'features/b.feature:2:4'],
names: [],
tagExpression: '',
})
})

describe('pickle in feature without line specified', () => {
it('returns true', async function () {
// Arrange
const {
pickles: [pickle],
gherkinDocument,
} = await parse({
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
uri: 'features/a.feature',
},
{
name: 'with absolute paths',
featurePaths: [
path.join(cwd, 'features/a.feature'),
path.join(cwd, 'features/b.feature:2:4'),
],
},
]

variants.forEach(({ name, featurePaths }) => {
describe(name, () => {
beforeEach(function () {
pickleFilter = new PickleFilter({
cwd,
featurePaths,
names: [],
tagExpression: '',
})
})

// Act
const result = pickleFilter.matches({ pickle, gherkinDocument })

// Assert
expect(result).to.eql(true)
})
})

describe('pickle in feature with line specified', () => {
it('returns true if pickle line matches', async function () {
// Arrange
const {
pickles: [pickle],
gherkinDocument,
} = await parse({
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
uri: 'features/b.feature',
describe('pickle in feature without line specified', () => {
it('returns true', async function () {
// Arrange
const {
pickles: [pickle],
gherkinDocument,
} = await parse({
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
uri: 'features/a.feature',
})

// Act
const result = pickleFilter.matches({ pickle, gherkinDocument })

// Assert
expect(result).to.eql(true)
})
})

// Act
const result = pickleFilter.matches({ pickle, gherkinDocument })

// Assert
expect(result).to.eql(true)
})

it('returns false if pickle line does not match', async function () {
// Arrange
const {
pickles: [pickle],
gherkinDocument,
} = await parse({
data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join('\n'),
uri: 'features/b.feature',
describe('pickle in feature with line specified', () => {
it('returns true if pickle line matches', async function () {
// Arrange
const {
pickles: [pickle],
gherkinDocument,
} = await parse({
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
uri: 'features/b.feature',
})

// Act
const result = pickleFilter.matches({ pickle, gherkinDocument })

// Assert
expect(result).to.eql(true)
})

it('returns false if pickle line does not match', async function () {
// Arrange
const {
pickles: [pickle],
gherkinDocument,
} = await parse({
data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join(
'\n'
),
uri: 'features/b.feature',
})

// Act
const result = pickleFilter.matches({ pickle, gherkinDocument })

// Assert
expect(result).to.eql(false)
})
})

// Act
const result = pickleFilter.matches({ pickle, gherkinDocument })

// Assert
expect(result).to.eql(false)
})
})
})
Expand Down