@@ -2,12 +2,16 @@ import * as assert from 'node:assert'
2
2
3
3
import {
4
4
Envelope ,
5
+ Examples ,
5
6
Feature ,
6
7
getWorstTestStepResult ,
7
8
GherkinDocument ,
8
9
Pickle ,
9
10
PickleStep ,
11
+ Rule ,
12
+ Scenario ,
10
13
Step ,
14
+ TableRow ,
11
15
TestCase ,
12
16
TestCaseFinished ,
13
17
TestCaseStarted ,
@@ -20,10 +24,22 @@ import {
20
24
} from '@cucumber/messages'
21
25
import { ArrayMultimap } from '@teppeis/multimaps'
22
26
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
+
23
38
export class ExtendedQuery {
24
39
private testRunStarted : TestRunStarted
25
40
private testRunFinished : TestRunFinished
26
41
private testCaseStarted : Array < TestCaseStarted > = [ ]
42
+ private readonly lineageById : Map < string , Lineage > = new Map ( )
27
43
private readonly stepById : Map < string , Step > = new Map ( )
28
44
private readonly pickleById : Map < string , Pickle > = new Map ( )
29
45
private readonly pickleStepById : Map < string , PickleStep > = new Map ( )
@@ -62,31 +78,72 @@ export class ExtendedQuery {
62
78
63
79
private updateGherkinDocument ( gherkinDocument : GherkinDocument ) {
64
80
if ( gherkinDocument . feature ) {
65
- this . updateFeature ( gherkinDocument . feature )
81
+ this . updateFeature ( gherkinDocument . feature , {
82
+ gherkinDocument,
83
+ } )
66
84
}
67
85
}
68
86
69
- private updateFeature ( feature : Feature ) {
87
+ private updateFeature ( feature : Feature , lineage : Lineage ) {
70
88
feature . children . forEach ( ( featureChild ) => {
71
89
if ( featureChild . background ) {
72
90
this . updateSteps ( featureChild . background . steps )
73
91
}
74
92
if ( featureChild . scenario ) {
75
- this . updateSteps ( featureChild . scenario . steps )
93
+ this . updateScenario ( featureChild . scenario , {
94
+ ...lineage ,
95
+ feature,
96
+ } )
76
97
}
77
98
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,
85
116
} )
86
117
}
87
118
} )
88
119
}
89
120
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
+
90
147
private updateSteps ( steps : ReadonlyArray < Step > ) {
91
148
steps . forEach ( ( step ) => this . stepById . set ( step . id , step ) )
92
149
}
@@ -125,6 +182,12 @@ export class ExtendedQuery {
125
182
)
126
183
}
127
184
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
+
128
191
findStepBy ( pickleStep : PickleStep ) {
129
192
const [ astNodeId ] = pickleStep . astNodeIds
130
193
assert . ok ( 'Expected PickleStep to have an astNodeId' )
0 commit comments