From 430c31a3a6cbca6efe7c4201db40891888d1604e Mon Sep 17 00:00:00 2001 From: David Goss Date: Thu, 27 May 2021 14:25:17 +0100 Subject: [PATCH 1/4] generate html report on runs --- cucumber.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cucumber.js b/cucumber.js index 639d7601a..9a2445594 100644 --- a/cucumber.js +++ b/cucumber.js @@ -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(' ') From 92dc7781d2847f907eec0b99f3b7d578fcf5af2b Mon Sep 17 00:00:00 2001 From: David Goss Date: Thu, 27 May 2021 14:26:11 +0100 Subject: [PATCH 2/4] reinstate original change This reverts commit 8a54a1b383bfe63d89365eec3988528bb3e0d8f0. --- CHANGELOG.md | 3 +++ src/cli/helpers.ts | 6 +----- src/cli/index.ts | 1 + src/formatter/helpers/issue_helpers_spec.ts | 2 +- src/formatter/helpers/test_case_attempt_parser.ts | 3 +-- src/formatter/helpers/usage_helpers/index.ts | 3 +-- src/formatter/json_formatter.ts | 3 +-- src/formatter/rerun_formatter.ts | 3 +-- src/pickle_filter.ts | 3 +-- src/pickle_filter_spec.ts | 2 +- 10 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a27349d..40d719c3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/cli/helpers.ts b/src/cli/helpers.ts index bbed9af13..a66d88f02 100644 --- a/src/cli/helpers.ts +++ b/src/cli/helpers.ts @@ -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' @@ -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}` ) ) } diff --git a/src/cli/index.ts b/src/cli/index.ts index 9db169ad4..3c2d5fe96 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -205,6 +205,7 @@ export default class Cli { { defaultDialect: configuration.featureDefaultLanguage, newId, + relativeTo: this.cwd, } ) const pickleIds = await parseGherkinMessageStream({ diff --git a/src/formatter/helpers/issue_helpers_spec.ts b/src/formatter/helpers/issue_helpers_spec.ts index ddae29f74..1a63a3f71 100644 --- a/src/formatter/helpers/issue_helpers_spec.ts +++ b/src/formatter/helpers/issue_helpers_spec.ts @@ -11,7 +11,7 @@ async function testFormatIssue(sourceData: string): Promise { const sources = [ { data: sourceData, - uri: 'project/a.feature', + uri: 'a.feature', }, ] const supportCodeLibrary = getBaseSupportCodeLibrary() diff --git a/src/formatter/helpers/test_case_attempt_parser.ts b/src/formatter/helpers/test_case_attempt_parser.ts index 4181a7034..82920d490 100644 --- a/src/formatter/helpers/test_case_attempt_parser.ts +++ b/src/formatter/helpers/test_case_attempt_parser.ts @@ -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' @@ -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, diff --git a/src/formatter/helpers/usage_helpers/index.ts b/src/formatter/helpers/usage_helpers/index.ts index a5fa528e6..6c53ed54a 100644 --- a/src/formatter/helpers/usage_helpers/index.ts +++ b/src/formatter/helpers/usage_helpers/index.ts @@ -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' @@ -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)) { diff --git a/src/formatter/json_formatter.ts b/src/formatter/json_formatter.ts index 628cdcf78..a0d31837b 100644 --- a/src/formatter/json_formatter.ts +++ b/src/formatter/json_formatter.ts @@ -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, @@ -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] = [] } diff --git a/src/formatter/rerun_formatter.ts b/src/formatter/rerun_formatter.ts index 49c65b8ed..6b5c53310 100644 --- a/src/formatter/rerun_formatter.ts +++ b/src/formatter/rerun_formatter.ts @@ -1,6 +1,5 @@ import _ from 'lodash' import Formatter, { IFormatterOptions } from './' -import path from 'path' import { getGherkinScenarioLocationMap } from './helpers/gherkin_document_parser' import { doesHaveValue, @@ -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 diff --git a/src/pickle_filter.ts b/src/pickle_filter.ts index fcf774ebe..a03745d22 100644 --- a/src/pickle_filter.ts +++ b/src/pickle_filter.ts @@ -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' @@ -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])) { diff --git a/src/pickle_filter_spec.ts b/src/pickle_filter_spec.ts index 392283514..0c5b70523 100644 --- a/src/pickle_filter_spec.ts +++ b/src/pickle_filter_spec.ts @@ -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 From fe64bf1a99c5ba4d7c0953c989ddcee6e1fa4838 Mon Sep 17 00:00:00 2001 From: David Goss Date: Thu, 27 May 2021 14:30:16 +0100 Subject: [PATCH 3/4] update test --- src/pickle_filter_spec.ts | 50 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/pickle_filter_spec.ts b/src/pickle_filter_spec.ts index 0c5b70523..784242043 100644 --- a/src/pickle_filter_spec.ts +++ b/src/pickle_filter_spec.ts @@ -26,7 +26,7 @@ describe('PickleFilter', () => { gherkinDocument, } = await parse({ data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -55,7 +55,7 @@ describe('PickleFilter', () => { gherkinDocument, } = await parse({ data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -74,7 +74,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 @@ -125,7 +125,7 @@ describe('PickleFilter', () => { 'Scenario: nameA descriptionA', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -147,7 +147,7 @@ describe('PickleFilter', () => { 'Example: nameA descriptionA', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -168,7 +168,7 @@ describe('PickleFilter', () => { 'Scenario: nameB descriptionB', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -200,7 +200,7 @@ describe('PickleFilter', () => { 'Scenario: startA descriptionA endA', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -232,7 +232,7 @@ describe('PickleFilter', () => { 'Scenario: nameA descriptionA', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -253,7 +253,7 @@ describe('PickleFilter', () => { 'Scenario: nameB descriptionB', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -274,7 +274,7 @@ describe('PickleFilter', () => { 'Scenario: nameC descriptionC', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -306,7 +306,7 @@ describe('PickleFilter', () => { data: ['Feature: a', '@tagA', 'Scenario: a', 'Given a step'].join( '\n' ), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -323,7 +323,7 @@ describe('PickleFilter', () => { gherkinDocument, } = await parse({ data: ['Feature: a', 'Scenario: a', 'Given a step'].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -353,7 +353,7 @@ describe('PickleFilter', () => { data: ['Feature: a', '@tagA', 'Scenario: a', 'Given a step'].join( '\n' ), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -370,7 +370,7 @@ describe('PickleFilter', () => { gherkinDocument, } = await parse({ data: ['Feature: a', 'Scenario: a', 'Given a step'].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -403,7 +403,7 @@ describe('PickleFilter', () => { 'Scenario: a', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -422,7 +422,7 @@ describe('PickleFilter', () => { data: ['Feature: a', '@tagA', 'Scenario: a', 'Given a step'].join( '\n' ), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -441,7 +441,7 @@ describe('PickleFilter', () => { data: ['Feature: a', '@tagB', 'Scenario: a', 'Given a step'].join( '\n' ), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -458,7 +458,7 @@ describe('PickleFilter', () => { gherkinDocument, } = await parse({ data: ['Feature: a', 'Scenario: a', 'Given a step'].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -491,7 +491,7 @@ describe('PickleFilter', () => { 'Scenario: a', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -510,7 +510,7 @@ describe('PickleFilter', () => { data: ['Feature: a', '@tagA', 'Scenario: a', 'Given a step'].join( '\n' ), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -529,7 +529,7 @@ describe('PickleFilter', () => { data: ['Feature: a', '@tagB', 'Scenario: a', 'Given a step'].join( '\n' ), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -546,7 +546,7 @@ describe('PickleFilter', () => { gherkinDocument, } = await parse({ data: ['Feature: a', 'Scenario: a', 'Given a step'].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act @@ -580,7 +580,7 @@ describe('PickleFilter', () => { 'Scenario: nameA descriptionA', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/b.feature'), + uri: 'features/b.feature', }) // Act @@ -602,7 +602,7 @@ describe('PickleFilter', () => { 'Scenario: nameA descriptionA', 'Given a step', ].join('\n'), - uri: path.resolve(cwd, 'features/b.feature'), + uri: 'features/b.feature', }) // Act @@ -619,7 +619,7 @@ describe('PickleFilter', () => { gherkinDocument, } = await parse({ data: ['Feature: a', 'Scenario: a', 'Given a step'].join('\n'), - uri: path.resolve(cwd, 'features/a.feature'), + uri: 'features/a.feature', }) // Act From 2c7f0f6cbe868ec1c1028656ed5174411839827d Mon Sep 17 00:00:00 2001 From: David Goss Date: Thu, 27 May 2021 14:50:22 +0100 Subject: [PATCH 4/4] fix pickle filter for windows --- src/pickle_filter.ts | 9 ++++----- src/pickle_filter_spec.ts | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pickle_filter.ts b/src/pickle_filter.ts index a03745d22..0b4436937 100644 --- a/src/pickle_filter.ts +++ b/src/pickle_filter.ts @@ -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' @@ -56,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 { const mapping: Record = {} featurePaths.forEach((featurePath) => { const match = FEATURE_LINENUM_REGEXP.exec(featurePath) if (doesHaveValue(match)) { - const uri = match[1] + const uri = path.normalize(match[1]) const linesExpression = match[2] if (doesHaveValue(linesExpression)) { if (doesNotHaveValue(mapping[uri])) { @@ -91,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 diff --git a/src/pickle_filter_spec.ts b/src/pickle_filter_spec.ts index 784242043..23529cd7a 100644 --- a/src/pickle_filter_spec.ts +++ b/src/pickle_filter_spec.ts @@ -1,7 +1,6 @@ import { beforeEach, describe, it } from 'mocha' import { expect } from 'chai' import PickleFilter from './pickle_filter' -import path from 'path' import { parse } from '../test/gherkin_helpers' describe('PickleFilter', () => { @@ -84,7 +83,7 @@ describe('PickleFilter', () => { expect(result).to.eql(true) }) - it('returns true if pickle line does not match', async function () { + it('returns false if pickle line does not match', async function () { // Arrange const { pickles: [pickle],