Skip to content

Commit 5a21c22

Browse files
cli: have gherkin emit uris relative to the cwd (#1672)
* pass relativeTo to gherkin-streams * fix json formatter * remove more usages of relative * another one * another one * last one * lint * fix this test * fix this test * add changelog Co-authored-by: Aslak Hellesøy <[email protected]>
1 parent 7861abf commit 5a21c22

10 files changed

+12
-17
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
2424

2525
### Fixed
2626

27+
* All messages now emitted with project-relative `uri`s
28+
([#1534](https://github.com/cucumber/cucumber-js/issues/1534)
29+
[#1672](https://github.com/cucumber/cucumber-js/pull/1672))
2730
* Json formatter now works with tagged examples
2831
([#1621](https://github.com/cucumber/cucumber-js/issues/1621)
2932
[#1651](https://github.com/cucumber/cucumber-js/pull/1651))

src/cli/helpers.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash'
22
import ArgvParser from './argv_parser'
33
import ProfileLoader from './profile_loader'
44
import shuffle from 'knuth-shuffle-seeded'
5-
import path from 'path'
65
import { EventEmitter } from 'events'
76
import PickleFilter from '../pickle_filter'
87
import { EventDataCollector } from '../formatter/helpers'
@@ -69,10 +68,7 @@ export async function parseGherkinMessageStream({
6968
if (doesHaveValue(envelope.parseError)) {
7069
reject(
7170
new Error(
72-
`Parse error in '${path.relative(
73-
cwd,
74-
envelope.parseError.source.uri
75-
)}': ${envelope.parseError.message}`
71+
`Parse error in '${envelope.parseError.source.uri}': ${envelope.parseError.message}`
7672
)
7773
)
7874
}

src/cli/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export default class Cli {
205205
{
206206
defaultDialect: configuration.featureDefaultLanguage,
207207
newId,
208+
relativeTo: this.cwd,
208209
}
209210
)
210211
const pickleIds = await parseGherkinMessageStream({

src/formatter/helpers/issue_helpers_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function testFormatIssue(sourceData: string): Promise<string> {
1111
const sources = [
1212
{
1313
data: sourceData,
14-
uri: 'project/a.feature',
14+
uri: 'a.feature',
1515
},
1616
]
1717
const supportCodeLibrary = getBaseSupportCodeLibrary()

src/formatter/helpers/test_case_attempt_parser.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
getGherkinStepMap,
66
} from './gherkin_document_parser'
77
import { getPickleStepMap, getStepKeyword } from './pickle_parser'
8-
import path from 'path'
98
import * as messages from '@cucumber/messages'
109
import { ITestCaseAttempt } from './event_data_collector'
1110
import StepDefinitionSnippetBuilder from '../step_definition_snippet_builder'
@@ -138,7 +137,7 @@ export function parseTestCaseAttempt({
138137
gherkinDocument
139138
)
140139
const pickleStepMap = getPickleStepMap(pickle)
141-
const relativePickleUri = path.relative(cwd, pickle.uri)
140+
const relativePickleUri = pickle.uri
142141
const parsedTestCase: IParsedTestCase = {
143142
attempt: testCaseAttempt.attempt,
144143
name: pickle.name,

src/formatter/helpers/usage_helpers/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import _ from 'lodash'
22
import { getPickleStepMap } from '../pickle_parser'
3-
import path from 'path'
43
import { getGherkinStepMap } from '../gherkin_document_parser'
54
import * as messages from '@cucumber/messages'
65
import StepDefinition from '../../../models/step_definition'
@@ -73,7 +72,7 @@ function buildMapping({
7372
const match: IUsageMatch = {
7473
line: gherkinStep.location.line,
7574
text: pickleStep.text,
76-
uri: path.relative(cwd, testCaseAttempt.pickle.uri),
75+
uri: testCaseAttempt.pickle.uri,
7776
}
7877
const { duration, status } = testCaseAttempt.stepResults[testStep.id]
7978
if (!unexecutedStatuses.includes(status) && doesHaveValue(duration)) {

src/formatter/json_formatter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import _ from 'lodash'
22
import Formatter, { IFormatterOptions } from './'
33
import { formatLocation, GherkinDocumentParser, PickleParser } from './helpers'
4-
import path from 'path'
54
import * as messages from '@cucumber/messages'
65
import {
76
getGherkinExampleRuleMap,
@@ -136,7 +135,7 @@ export default class JsonFormatter extends Formatter {
136135
this.eventDataCollector.getTestCaseAttempts(),
137136
(testCaseAttempt: ITestCaseAttempt) => {
138137
if (!testCaseAttempt.worstTestStepResult.willBeRetried) {
139-
const uri = path.relative(this.cwd, testCaseAttempt.pickle.uri)
138+
const uri = testCaseAttempt.pickle.uri
140139
if (doesNotHaveValue(groupedTestCaseAttempts[uri])) {
141140
groupedTestCaseAttempts[uri] = []
142141
}

src/formatter/rerun_formatter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import _ from 'lodash'
22
import Formatter, { IFormatterOptions } from './'
3-
import path from 'path'
43
import { getGherkinScenarioLocationMap } from './helpers/gherkin_document_parser'
54
import {
65
doesHaveValue,
@@ -37,7 +36,7 @@ export default class RerunFormatter extends Formatter {
3736
if (
3837
worstTestStepResult.status !== messages.TestStepResultStatus.PASSED
3938
) {
40-
const relativeUri = path.relative(this.cwd, pickle.uri)
39+
const relativeUri = pickle.uri
4140
const line = getGherkinScenarioLocationMap(gherkinDocument)[
4241
_.last(pickle.astNodeIds)
4342
].line

src/pickle_filter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import _ from 'lodash'
2-
import path from 'path'
32
import parse from '@cucumber/tag-expressions'
43
import { getGherkinScenarioLocationMap } from './formatter/helpers/gherkin_document_parser'
54
import { doesHaveValue, doesNotHaveValue } from './value_checker'
@@ -73,7 +72,7 @@ export class PickleLineFilter {
7372
featurePaths.forEach((featurePath) => {
7473
const match = FEATURE_LINENUM_REGEXP.exec(featurePath)
7574
if (doesHaveValue(match)) {
76-
const uri = path.resolve(cwd, match[1])
75+
const uri = match[1]
7776
const linesExpression = match[2]
7877
if (doesHaveValue(linesExpression)) {
7978
if (doesNotHaveValue(mapping[uri])) {

src/pickle_filter_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('PickleFilter', () => {
9191
gherkinDocument,
9292
} = await parse({
9393
data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join('\n'),
94-
uri: path.resolve(cwd, 'features/b.feature'),
94+
uri: 'features/b.feature',
9595
})
9696

9797
// Act

0 commit comments

Comments
 (0)