@@ -141,6 +141,7 @@ class PrettyFormatter extends Formatter {
141
141
const result = this . eventDataCollector . getTestCaseAttempt ( testCase . testCaseStartedId ) ;
142
142
const tc = this . testCases [ testCase . testCaseStartedId ] ;
143
143
tc . testSteps . forEach ( step => {
144
+ step . gherkinLocation = this . stepGherkinLocation ( step , result ) ;
144
145
step . logs = result . stepAttachments [ step . id ] ?. filter ( attachment => attachment . mediaType === 'text/x.cucumber.log+plain' ) ?? [ ] ;
145
146
} ) ;
146
147
this . updateRunStatus ( tc ) ;
@@ -156,7 +157,7 @@ class PrettyFormatter extends Formatter {
156
157
157
158
drawStep ( step ) {
158
159
let line = this . indent + chalk . bold ( this . statusIcons [ step . testStepResult . status ] ) + ' ' + step . stepText ;
159
- line += ` ${ chalk . gray ( step . location ) } ` ;
160
+ line += ` ${ chalk . gray ( step . gherkinLocation ) } ${ chalk . gray ( step . location ) } ` ;
160
161
if ( step . argument && step . argument . dataTable ) {
161
162
line += `\n${ this . drawDataTable ( step . argument . dataTable ) } `
162
163
}
@@ -199,7 +200,23 @@ class PrettyFormatter extends Formatter {
199
200
hookKeyword ( steps , testStep ) {
200
201
const hook = this . stepDefinitions [ testStep . hookId ] ;
201
202
if ( hook . name ) return hook . name
202
- return steps . every ( element => element . stepText === undefined || element . stepText === 'Before' ) ? 'Before' : 'After'
203
+ const hookIndex = steps . findIndex ( element => element . hookId === testStep . hookId ) ;
204
+ return steps . slice ( 0 , hookIndex ) . some ( element => element . pickleStepId ) ? 'After' : 'Before'
205
+ }
206
+
207
+ stepGherkinLocation ( step , scenario ) {
208
+ if ( step . pickleStepId ) {
209
+ const [ scenarioPickleId ] = scenario . pickle . astNodeIds ;
210
+ const pickle = scenario . pickle . steps . find ( e => e . id === step . pickleStepId ) ;
211
+ const [ astNodeId ] = pickle . astNodeIds ;
212
+ const children = scenario . gherkinDocument . feature . children ;
213
+ const scenarioSource = children . find ( child => child . scenario ?. id === scenarioPickleId ) ;
214
+ const backgroundSource = children . find ( child => child . background ) ;
215
+ const stepsSources = [ ] . concat ( scenarioSource ?. scenario ?. steps ) . concat ( backgroundSource ?. background ?. steps ) . filter ( x => x ) ;
216
+ const stepSource = stepsSources . find ( s => s . id === astNodeId ) ;
217
+ return stepSource ? `${ scenario . gherkinDocument . uri } :${ stepSource . location . line } ` : '' ;
218
+ }
219
+ return '' ;
203
220
}
204
221
205
222
}
0 commit comments