Skip to content

Commit 140fc02

Browse files
authored
fix issues with absolute paths (#2063)
* add failing scenario * convert to relative path before adding to map * refactor test * update CHANGELOG.md
1 parent 1da05aa commit 140fc02

File tree

4 files changed

+92
-56
lines changed

4 files changed

+92
-56
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) on how to contribute to Cucumber.
99

1010
## [Unreleased]
11+
### Fixed
12+
- Fix issues with using absolute paths for features ([#2063](https://github.com/cucumber/cucumber-js/pull/2063))
1113

1214
## [8.3.1] - 2022-06-21
1315
### Fixed

Diff for: features/target_specific_scenarios_by_line.feature

+5
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ Feature: Target specific scenarios
4949
| args |
5050
| features/a.feature:2:10 |
5151
| features/a.feature:2 features/a.feature:10 |
52+
53+
Scenario: using absolute paths
54+
When I run cucumber-js with `{{{tmpDir}}}/features/a.feature:2`
55+
Then it fails
56+
And it runs the scenario "first scenario"

Diff for: src/pickle_filter.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,28 @@ export class PickleLineFilter {
5656

5757
constructor(cwd: string, featurePaths: string[] = []) {
5858
this.featureUriToLinesMapping = this.getFeatureUriToLinesMapping({
59+
cwd,
5960
featurePaths,
6061
})
6162
}
6263

6364
getFeatureUriToLinesMapping({
65+
cwd,
6466
featurePaths,
6567
}: {
68+
cwd: string
6669
featurePaths: string[]
6770
}): Record<string, number[]> {
6871
const mapping: Record<string, number[]> = {}
6972
featurePaths.forEach((featurePath) => {
7073
const match = FEATURE_LINENUM_REGEXP.exec(featurePath)
7174
if (doesHaveValue(match)) {
72-
const uri = path.normalize(match[1])
75+
let uri = match[1]
76+
if (path.isAbsolute(uri)) {
77+
uri = path.relative(cwd, uri)
78+
} else {
79+
uri = path.normalize(uri)
80+
}
7381
const linesExpression = match[2]
7482
if (doesHaveValue(linesExpression)) {
7583
if (doesNotHaveValue(mapping[uri])) {

Diff for: src/pickle_filter_spec.ts

+76-55
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { beforeEach, describe, it } from 'mocha'
22
import { expect } from 'chai'
3+
import path from 'path'
34
import PickleFilter from './pickle_filter'
45
import { parse } from '../test/gherkin_helpers'
56

@@ -37,67 +38,87 @@ describe('PickleFilter', () => {
3738
})
3839

3940
describe('line filters', () => {
40-
beforeEach(function () {
41-
pickleFilter = new PickleFilter({
42-
cwd,
41+
const variants = [
42+
{
43+
name: 'with relative paths',
4344
featurePaths: ['features/a.feature', 'features/b.feature:2:4'],
44-
names: [],
45-
tagExpression: '',
46-
})
47-
})
48-
49-
describe('pickle in feature without line specified', () => {
50-
it('returns true', async function () {
51-
// Arrange
52-
const {
53-
pickles: [pickle],
54-
gherkinDocument,
55-
} = await parse({
56-
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
57-
uri: 'features/a.feature',
45+
},
46+
{
47+
name: 'with absolute paths',
48+
featurePaths: [
49+
path.join(cwd, 'features/a.feature'),
50+
path.join(cwd, 'features/b.feature:2:4'),
51+
],
52+
},
53+
]
54+
55+
variants.forEach(({ name, featurePaths }) => {
56+
describe(name, () => {
57+
beforeEach(function () {
58+
pickleFilter = new PickleFilter({
59+
cwd,
60+
featurePaths,
61+
names: [],
62+
tagExpression: '',
63+
})
5864
})
5965

60-
// Act
61-
const result = pickleFilter.matches({ pickle, gherkinDocument })
62-
63-
// Assert
64-
expect(result).to.eql(true)
65-
})
66-
})
67-
68-
describe('pickle in feature with line specified', () => {
69-
it('returns true if pickle line matches', async function () {
70-
// Arrange
71-
const {
72-
pickles: [pickle],
73-
gherkinDocument,
74-
} = await parse({
75-
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
76-
uri: 'features/b.feature',
66+
describe('pickle in feature without line specified', () => {
67+
it('returns true', async function () {
68+
// Arrange
69+
const {
70+
pickles: [pickle],
71+
gherkinDocument,
72+
} = await parse({
73+
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
74+
uri: 'features/a.feature',
75+
})
76+
77+
// Act
78+
const result = pickleFilter.matches({ pickle, gherkinDocument })
79+
80+
// Assert
81+
expect(result).to.eql(true)
82+
})
7783
})
7884

79-
// Act
80-
const result = pickleFilter.matches({ pickle, gherkinDocument })
81-
82-
// Assert
83-
expect(result).to.eql(true)
84-
})
85-
86-
it('returns false if pickle line does not match', async function () {
87-
// Arrange
88-
const {
89-
pickles: [pickle],
90-
gherkinDocument,
91-
} = await parse({
92-
data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join('\n'),
93-
uri: 'features/b.feature',
85+
describe('pickle in feature with line specified', () => {
86+
it('returns true if pickle line matches', async function () {
87+
// Arrange
88+
const {
89+
pickles: [pickle],
90+
gherkinDocument,
91+
} = await parse({
92+
data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'),
93+
uri: 'features/b.feature',
94+
})
95+
96+
// Act
97+
const result = pickleFilter.matches({ pickle, gherkinDocument })
98+
99+
// Assert
100+
expect(result).to.eql(true)
101+
})
102+
103+
it('returns false if pickle line does not match', async function () {
104+
// Arrange
105+
const {
106+
pickles: [pickle],
107+
gherkinDocument,
108+
} = await parse({
109+
data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join(
110+
'\n'
111+
),
112+
uri: 'features/b.feature',
113+
})
114+
115+
// Act
116+
const result = pickleFilter.matches({ pickle, gherkinDocument })
117+
118+
// Assert
119+
expect(result).to.eql(false)
120+
})
94121
})
95-
96-
// Act
97-
const result = pickleFilter.matches({ pickle, gherkinDocument })
98-
99-
// Assert
100-
expect(result).to.eql(false)
101122
})
102123
})
103124
})

0 commit comments

Comments
 (0)