Skip to content

Commit

Permalink
cli: have gherkin emit uris relative to the cwd (#1672)
Browse files Browse the repository at this point in the history
* 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 <1000+aslakhellesoy@users.noreply.github.com>
  • Loading branch information
davidjgoss and aslakhellesoy authored May 27, 2021
1 parent 7861abf commit 5a21c22
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO

### Fixed

* All messages now emitted with project-relative `uri`s
([#1534](https://github.com/cucumber/cucumber-js/issues/1534)
[#1672](https://github.com/cucumber/cucumber-js/pull/1672))
* Json formatter now works with tagged examples
([#1621](https://github.com/cucumber/cucumber-js/issues/1621)
[#1651](https://github.com/cucumber/cucumber-js/pull/1651))
Expand Down
6 changes: 1 addition & 5 deletions src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _ from 'lodash'
import ArgvParser from './argv_parser'
import ProfileLoader from './profile_loader'
import shuffle from 'knuth-shuffle-seeded'
import path from 'path'
import { EventEmitter } from 'events'
import PickleFilter from '../pickle_filter'
import { EventDataCollector } from '../formatter/helpers'
Expand Down Expand Up @@ -69,10 +68,7 @@ export async function parseGherkinMessageStream({
if (doesHaveValue(envelope.parseError)) {
reject(
new Error(
`Parse error in '${path.relative(
cwd,
envelope.parseError.source.uri
)}': ${envelope.parseError.message}`
`Parse error in '${envelope.parseError.source.uri}': ${envelope.parseError.message}`
)
)
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export default class Cli {
{
defaultDialect: configuration.featureDefaultLanguage,
newId,
relativeTo: this.cwd,
}
)
const pickleIds = await parseGherkinMessageStream({
Expand Down
2 changes: 1 addition & 1 deletion src/formatter/helpers/issue_helpers_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function testFormatIssue(sourceData: string): Promise<string> {
const sources = [
{
data: sourceData,
uri: 'project/a.feature',
uri: 'a.feature',
},
]
const supportCodeLibrary = getBaseSupportCodeLibrary()
Expand Down
3 changes: 1 addition & 2 deletions src/formatter/helpers/test_case_attempt_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getGherkinStepMap,
} from './gherkin_document_parser'
import { getPickleStepMap, getStepKeyword } from './pickle_parser'
import path from 'path'
import * as messages from '@cucumber/messages'
import { ITestCaseAttempt } from './event_data_collector'
import StepDefinitionSnippetBuilder from '../step_definition_snippet_builder'
Expand Down Expand Up @@ -138,7 +137,7 @@ export function parseTestCaseAttempt({
gherkinDocument
)
const pickleStepMap = getPickleStepMap(pickle)
const relativePickleUri = path.relative(cwd, pickle.uri)
const relativePickleUri = pickle.uri
const parsedTestCase: IParsedTestCase = {
attempt: testCaseAttempt.attempt,
name: pickle.name,
Expand Down
3 changes: 1 addition & 2 deletions src/formatter/helpers/usage_helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import _ from 'lodash'
import { getPickleStepMap } from '../pickle_parser'
import path from 'path'
import { getGherkinStepMap } from '../gherkin_document_parser'
import * as messages from '@cucumber/messages'
import StepDefinition from '../../../models/step_definition'
Expand Down Expand Up @@ -73,7 +72,7 @@ function buildMapping({
const match: IUsageMatch = {
line: gherkinStep.location.line,
text: pickleStep.text,
uri: path.relative(cwd, testCaseAttempt.pickle.uri),
uri: testCaseAttempt.pickle.uri,
}
const { duration, status } = testCaseAttempt.stepResults[testStep.id]
if (!unexecutedStatuses.includes(status) && doesHaveValue(duration)) {
Expand Down
3 changes: 1 addition & 2 deletions src/formatter/json_formatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash'
import Formatter, { IFormatterOptions } from './'
import { formatLocation, GherkinDocumentParser, PickleParser } from './helpers'
import path from 'path'
import * as messages from '@cucumber/messages'
import {
getGherkinExampleRuleMap,
Expand Down Expand Up @@ -136,7 +135,7 @@ export default class JsonFormatter extends Formatter {
this.eventDataCollector.getTestCaseAttempts(),
(testCaseAttempt: ITestCaseAttempt) => {
if (!testCaseAttempt.worstTestStepResult.willBeRetried) {
const uri = path.relative(this.cwd, testCaseAttempt.pickle.uri)
const uri = testCaseAttempt.pickle.uri
if (doesNotHaveValue(groupedTestCaseAttempts[uri])) {
groupedTestCaseAttempts[uri] = []
}
Expand Down
3 changes: 1 addition & 2 deletions src/formatter/rerun_formatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import _ from 'lodash'
import Formatter, { IFormatterOptions } from './'
import path from 'path'
import { getGherkinScenarioLocationMap } from './helpers/gherkin_document_parser'
import {
doesHaveValue,
Expand Down Expand Up @@ -37,7 +36,7 @@ export default class RerunFormatter extends Formatter {
if (
worstTestStepResult.status !== messages.TestStepResultStatus.PASSED
) {
const relativeUri = path.relative(this.cwd, pickle.uri)
const relativeUri = pickle.uri
const line = getGherkinScenarioLocationMap(gherkinDocument)[
_.last(pickle.astNodeIds)
].line
Expand Down
3 changes: 1 addition & 2 deletions src/pickle_filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash'
import path from 'path'
import parse from '@cucumber/tag-expressions'
import { getGherkinScenarioLocationMap } from './formatter/helpers/gherkin_document_parser'
import { doesHaveValue, doesNotHaveValue } from './value_checker'
Expand Down Expand Up @@ -73,7 +72,7 @@ export class PickleLineFilter {
featurePaths.forEach((featurePath) => {
const match = FEATURE_LINENUM_REGEXP.exec(featurePath)
if (doesHaveValue(match)) {
const uri = path.resolve(cwd, match[1])
const uri = match[1]
const linesExpression = match[2]
if (doesHaveValue(linesExpression)) {
if (doesNotHaveValue(mapping[uri])) {
Expand Down
2 changes: 1 addition & 1 deletion src/pickle_filter_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('PickleFilter', () => {
gherkinDocument,
} = await parse({
data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join('\n'),
uri: path.resolve(cwd, 'features/b.feature'),
uri: 'features/b.feature',
})

// Act
Expand Down

0 comments on commit 5a21c22

Please sign in to comment.