Skip to content

Commit

Permalink
Revert "cli: have gherkin emit uris relative to the cwd (#1672)"
Browse files Browse the repository at this point in the history
This reverts commit 5a21c22.
  • Loading branch information
davidjgoss committed May 27, 2021
1 parent 5a21c22 commit 8a54a1b
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 12 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ 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: 5 additions & 1 deletion src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -68,7 +69,10 @@ export async function parseGherkinMessageStream({
if (doesHaveValue(envelope.parseError)) {
reject(
new Error(
`Parse error in '${envelope.parseError.source.uri}': ${envelope.parseError.message}`
`Parse error in '${path.relative(
cwd,
envelope.parseError.source.uri
)}': ${envelope.parseError.message}`
)
)
}
Expand Down
1 change: 0 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ 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: 'a.feature',
uri: 'project/a.feature',
},
]
const supportCodeLibrary = getBaseSupportCodeLibrary()
Expand Down
3 changes: 2 additions & 1 deletion src/formatter/helpers/test_case_attempt_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 @@ -137,7 +138,7 @@ export function parseTestCaseAttempt({
gherkinDocument
)
const pickleStepMap = getPickleStepMap(pickle)
const relativePickleUri = pickle.uri
const relativePickleUri = path.relative(cwd, pickle.uri)
const parsedTestCase: IParsedTestCase = {
attempt: testCaseAttempt.attempt,
name: pickle.name,
Expand Down
3 changes: 2 additions & 1 deletion src/formatter/helpers/usage_helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 @@ -72,7 +73,7 @@ function buildMapping({
const match: IUsageMatch = {
line: gherkinStep.location.line,
text: pickleStep.text,
uri: testCaseAttempt.pickle.uri,
uri: path.relative(cwd, testCaseAttempt.pickle.uri),
}
const { duration, status } = testCaseAttempt.stepResults[testStep.id]
if (!unexecutedStatuses.includes(status) && doesHaveValue(duration)) {
Expand Down
3 changes: 2 additions & 1 deletion src/formatter/json_formatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -135,7 +136,7 @@ export default class JsonFormatter extends Formatter {
this.eventDataCollector.getTestCaseAttempts(),
(testCaseAttempt: ITestCaseAttempt) => {
if (!testCaseAttempt.worstTestStepResult.willBeRetried) {
const uri = testCaseAttempt.pickle.uri
const uri = path.relative(this.cwd, testCaseAttempt.pickle.uri)
if (doesNotHaveValue(groupedTestCaseAttempts[uri])) {
groupedTestCaseAttempts[uri] = []
}
Expand Down
3 changes: 2 additions & 1 deletion src/formatter/rerun_formatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash'
import Formatter, { IFormatterOptions } from './'
import path from 'path'
import { getGherkinScenarioLocationMap } from './helpers/gherkin_document_parser'
import {
doesHaveValue,
Expand Down Expand Up @@ -36,7 +37,7 @@ export default class RerunFormatter extends Formatter {
if (
worstTestStepResult.status !== messages.TestStepResultStatus.PASSED
) {
const relativeUri = pickle.uri
const relativeUri = path.relative(this.cwd, pickle.uri)
const line = getGherkinScenarioLocationMap(gherkinDocument)[
_.last(pickle.astNodeIds)
].line
Expand Down
3 changes: 2 additions & 1 deletion src/pickle_filter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 @@ -72,7 +73,7 @@ export class PickleLineFilter {
featurePaths.forEach((featurePath) => {
const match = FEATURE_LINENUM_REGEXP.exec(featurePath)
if (doesHaveValue(match)) {
const uri = match[1]
const uri = path.resolve(cwd, 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: 'features/b.feature',
uri: path.resolve(cwd, 'features/b.feature'),
})

// Act
Expand Down

0 comments on commit 8a54a1b

Please sign in to comment.