@@ -83,15 +83,17 @@ class CucumberHandler {
83
83
get outlineExampleIndex ( ) {
84
84
if ( this . isNewFormat ) {
85
85
const [ , exampleId ] = this . state . pickle . astNodeIds ;
86
- if (
87
- ! this . currentScenario . examples ||
88
- ! this . currentScenario . examples . length
89
- ) {
90
- return - 1 ;
86
+ const examples = this . currentScenario . examples || [ ] ;
87
+
88
+ for ( const example of examples ) {
89
+ const index = example . tableBody . findIndex (
90
+ ( item ) => item . id === exampleId
91
+ ) ;
92
+ if ( index !== - 1 ) {
93
+ return index ;
94
+ }
91
95
}
92
- return this . currentScenario . examples [ 0 ] . tableBody . findIndex (
93
- ( item ) => item . id === exampleId
94
- ) ;
96
+ return - 1 ;
95
97
}
96
98
const num = parseInt (
97
99
exampleNumber . exec ( this . currentScenario . name ) . pop ( )
@@ -113,7 +115,7 @@ class CucumberHandler {
113
115
}
114
116
115
117
const newTags = [
116
- ...currentTags . filter ( ( t ) => ! t . type && ! t . type !== 'Tag' ) ,
118
+ ...currentTags . filter ( ( t ) => ! ( t && t . type === 'Tag' ) ) ,
117
119
tag
118
120
] ;
119
121
@@ -220,29 +222,38 @@ class CucumberHandler {
220
222
}
221
223
222
224
kind . tags
223
- . filter ( function ( { name } ) {
224
- const match = tagToLabel . exec ( name ) ;
225
- if ( match ) {
226
- const [ , command , value ] = match ;
227
- // feature and suite should be overwritten to avoid duplicates
228
- if ( [ 'feature' , 'suite' ] . includes ( command ) ) {
229
- const index = currentTest . info . labels . findIndex (
230
- ( label ) => label . name === command
231
- ) ;
232
- currentTest . info . labels [ index ] = {
233
- name : command ,
234
- value : value
235
- } ;
236
- } else {
237
- // handle renaming label for testID, or just use label name
238
- currentTest . addLabel (
239
- command === 'testID' ? 'AS_ID' : command ,
240
- value
241
- ) ;
225
+ . filter (
226
+ function ( { name } ) {
227
+ const match = tagToLabel . exec ( name ) ;
228
+ if ( match ) {
229
+ const [ , command , value ] = match ;
230
+
231
+ // testID handling with outline index support
232
+ if ( command === 'testID' ) {
233
+ const ids = value . split ( '|' ) ;
234
+ const index = this . outlineExampleIndex ?? 0 ;
235
+ const id = ids [ index ] || ids [ 0 ] ;
236
+ currentTest . addLabel ( 'AS_ID' , id ) ;
237
+ } else if (
238
+ [ 'feature' , 'suite' ] . includes ( command )
239
+ ) {
240
+ // feature and suite should be overwritten to avoid duplicates
241
+ const labelIndex =
242
+ currentTest . info . labels . findIndex (
243
+ ( label ) => label . name === command
244
+ ) ;
245
+ currentTest . info . labels [ labelIndex ] = {
246
+ name : command ,
247
+ value : value
248
+ } ;
249
+ } else {
250
+ // use label name
251
+ currentTest . addLabel ( command , value ) ;
252
+ }
242
253
}
243
- }
244
- return ! match ;
245
- } )
254
+ return ! match ;
255
+ } . bind ( this ) // bind context to access this.outlineExampleIndex inside callback
256
+ )
246
257
// check for links
247
258
. filter ( function ( { name } ) {
248
259
const match = tagToLink . exec ( name ) ;
@@ -276,7 +287,7 @@ class CucumberHandler {
276
287
. forEach ( function ( { name } ) {
277
288
currentTest . addLabel ( 'tag' , name . replace ( '@' , '' ) ) ;
278
289
} ) ;
279
- }
290
+ } . bind ( this )
280
291
) ;
281
292
}
282
293
}
0 commit comments