Skip to content

Commit efae310

Browse files
committed
instrument lineage and use feature name
1 parent c5f69c2 commit efae310

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

javascript/src/ExtendedQuery.ts

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import * as assert from 'node:assert'
22

33
import {
44
Envelope,
5+
Examples,
56
Feature,
67
getWorstTestStepResult,
78
GherkinDocument,
89
Pickle,
910
PickleStep,
11+
Rule,
12+
Scenario,
1013
Step,
14+
TableRow,
1115
TestCase,
1216
TestCaseFinished,
1317
TestCaseStarted,
@@ -20,10 +24,22 @@ import {
2024
} from '@cucumber/messages'
2125
import { ArrayMultimap } from '@teppeis/multimaps'
2226

27+
export interface Lineage {
28+
gherkinDocument?: GherkinDocument
29+
feature?: Feature
30+
rule?: Rule
31+
scenario?: Scenario
32+
examples?: Examples
33+
examplesIndex?: number
34+
example?: TableRow
35+
exampleIndex?: number
36+
}
37+
2338
export class ExtendedQuery {
2439
private testRunStarted: TestRunStarted
2540
private testRunFinished: TestRunFinished
2641
private testCaseStarted: Array<TestCaseStarted> = []
42+
private readonly lineageById: Map<string, Lineage> = new Map()
2743
private readonly stepById: Map<string, Step> = new Map()
2844
private readonly pickleById: Map<string, Pickle> = new Map()
2945
private readonly pickleStepById: Map<string, PickleStep> = new Map()
@@ -62,31 +78,72 @@ export class ExtendedQuery {
6278

6379
private updateGherkinDocument(gherkinDocument: GherkinDocument) {
6480
if (gherkinDocument.feature) {
65-
this.updateFeature(gherkinDocument.feature)
81+
this.updateFeature(gherkinDocument.feature, {
82+
gherkinDocument,
83+
})
6684
}
6785
}
6886

69-
private updateFeature(feature: Feature) {
87+
private updateFeature(feature: Feature, lineage: Lineage) {
7088
feature.children.forEach((featureChild) => {
7189
if (featureChild.background) {
7290
this.updateSteps(featureChild.background.steps)
7391
}
7492
if (featureChild.scenario) {
75-
this.updateSteps(featureChild.scenario.steps)
93+
this.updateScenario(featureChild.scenario, {
94+
...lineage,
95+
feature,
96+
})
7697
}
7798
if (featureChild.rule) {
78-
featureChild.rule.children.forEach((ruleChild) => {
79-
if (ruleChild.background) {
80-
this.updateSteps(ruleChild.background.steps)
81-
}
82-
if (ruleChild.scenario) {
83-
this.updateSteps(ruleChild.scenario.steps)
84-
}
99+
this.updateRule(featureChild.rule, {
100+
...lineage,
101+
feature,
102+
})
103+
}
104+
})
105+
}
106+
107+
private updateRule(rule: Rule, lineage: Lineage) {
108+
rule.children.forEach((ruleChild) => {
109+
if (ruleChild.background) {
110+
this.updateSteps(ruleChild.background.steps)
111+
}
112+
if (ruleChild.scenario) {
113+
this.updateScenario(ruleChild.scenario, {
114+
...lineage,
115+
rule,
85116
})
86117
}
87118
})
88119
}
89120

121+
private updateScenario(scenario: Scenario, lineage: Lineage) {
122+
this.lineageById.set(scenario.id, {
123+
...lineage,
124+
scenario,
125+
})
126+
scenario.examples.forEach((examples, examplesIndex) => {
127+
this.lineageById.set(examples.id, {
128+
...lineage,
129+
scenario,
130+
examples,
131+
examplesIndex,
132+
})
133+
examples.tableBody.forEach((example, exampleIndex) => {
134+
this.lineageById.set(example.id, {
135+
...lineage,
136+
scenario,
137+
examples,
138+
examplesIndex,
139+
example,
140+
exampleIndex,
141+
})
142+
})
143+
})
144+
this.updateSteps(scenario.steps)
145+
}
146+
90147
private updateSteps(steps: ReadonlyArray<Step>) {
91148
steps.forEach((step) => this.stepById.set(step.id, step))
92149
}
@@ -125,6 +182,12 @@ export class ExtendedQuery {
125182
)
126183
}
127184

185+
findLineageBy(pickle: Pickle) {
186+
const deepestAstNodeId = pickle.astNodeIds.at(-1)
187+
assert.ok(deepestAstNodeId, 'Expected Pickle to have at least one astNodeId')
188+
return this.lineageById.get(deepestAstNodeId)
189+
}
190+
128191
findStepBy(pickleStep: PickleStep) {
129192
const [astNodeId] = pickleStep.astNodeIds
130193
assert.ok('Expected PickleStep to have an astNodeId')

javascript/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ function makeTestCases(query: ExtendedQuery): ReadonlyArray<ReportTestCase> {
9292
return query.findAllTestCaseStarted().map((testCaseStarted) => {
9393
const pickle = query.findPickleBy(testCaseStarted)
9494
assert.ok(pickle, 'Expected to find Pickle by TestCaseStarted')
95+
const lineage = query.findLineageBy(pickle)
9596
return {
96-
classname: pickle.uri,
97+
classname: lineage?.feature?.name ?? pickle.uri,
9798
name: pickle.name,
9899
time: durationToSeconds(query.findTestCaseDurationBy(testCaseStarted)),
99100
failure: makeFailure(query, testCaseStarted),

0 commit comments

Comments
 (0)