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

cli: relative path fix again, now with windows #1673

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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
1 change: 1 addition & 0 deletions cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const feature = [
'--format rerun:@rerun.txt',
'--format usage:usage.txt',
'--format message:messages.ndjson',
'--format html:html-formatter.html',
'--publish-quiet',
].join(' ')

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
8 changes: 3 additions & 5 deletions src/pickle_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,20 @@ 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.resolve(cwd, match[1])
const uri = path.normalize(match[1])
const linesExpression = match[2]
if (doesHaveValue(linesExpression)) {
if (doesNotHaveValue(mapping[uri])) {
Expand All @@ -92,7 +89,8 @@ export class PickleLineFilter {
}

matchesAnyLine({ gherkinDocument, pickle }: IMatchesAnyLineRequest): boolean {
const linesToMatch = this.featureUriToLinesMapping[pickle.uri]
const uri = path.normalize(pickle.uri)
const linesToMatch = this.featureUriToLinesMapping[uri]
if (doesHaveValue(linesToMatch)) {
const gherkinScenarioLocationMap = getGherkinScenarioLocationMap(
gherkinDocument
Expand Down
Loading