@@ -53,13 +53,16 @@ export default class Query {
53
53
private testRunStarted : TestRunStarted
54
54
private testRunFinished : TestRunFinished
55
55
private readonly testCaseStarted : Array < TestCaseStarted > = [ ]
56
+ private readonly testCaseStartedById : Map < string , TestCaseStarted > = new Map ( )
56
57
private readonly lineageById : Map < string , Lineage > = new Map ( )
57
58
private readonly stepById : Map < string , Step > = new Map ( )
58
59
private readonly pickleById : Map < string , Pickle > = new Map ( )
59
60
private readonly pickleStepById : Map < string , PickleStep > = new Map ( )
60
61
private readonly testCaseById : Map < string , TestCase > = new Map ( )
61
62
private readonly testStepById : Map < string , TestStep > = new Map ( )
62
63
private readonly testCaseFinishedByTestCaseStartedId : Map < string , TestCaseFinished > = new Map ( )
64
+ private readonly testStepStartedByTestCaseStartedId : ArrayMultimap < string , TestStepStarted > =
65
+ new ArrayMultimap ( )
63
66
private readonly testStepFinishedByTestCaseStartedId : ArrayMultimap < string , TestStepFinished > =
64
67
new ArrayMultimap ( )
65
68
private readonly attachmentsByTestCaseStartedId : ArrayMultimap < string , Attachment > =
@@ -87,6 +90,9 @@ export default class Query {
87
90
if ( envelope . testCaseStarted ) {
88
91
this . updateTestCaseStarted ( envelope . testCaseStarted )
89
92
}
93
+ if ( envelope . testStepStarted ) {
94
+ this . updateTestStepStarted ( envelope . testStepStarted )
95
+ }
90
96
if ( envelope . attachment ) {
91
97
this . updateAttachment ( envelope . attachment )
92
98
}
@@ -196,6 +202,7 @@ export default class Query {
196
202
197
203
private updateTestCaseStarted ( testCaseStarted : TestCaseStarted ) {
198
204
this . testCaseStarted . push ( testCaseStarted )
205
+ this . testCaseStartedById . set ( testCaseStarted . id , testCaseStarted )
199
206
200
207
/*
201
208
when a test case attempt starts besides the first one, clear all existing results
@@ -211,6 +218,13 @@ export default class Query {
211
218
}
212
219
}
213
220
221
+ private updateTestStepStarted ( testStepStarted : TestStepStarted ) {
222
+ this . testStepStartedByTestCaseStartedId . put (
223
+ testStepStarted . testCaseStartedId ,
224
+ testStepStarted
225
+ )
226
+ }
227
+
214
228
private updateAttachment ( attachment : Attachment ) {
215
229
if ( attachment . testStepId ) {
216
230
this . attachmentsByTestStepId . put ( attachment . testStepId , attachment )
@@ -479,14 +493,14 @@ export default class Query {
479
493
}
480
494
481
495
public findLocationOf ( pickle : Pickle ) : Location | undefined {
482
- return undefined
496
+ const lineage = this . findLineageBy ( pickle )
497
+ if ( lineage ?. example ) {
498
+ return lineage . example . location
499
+ }
500
+ return lineage ?. scenario ?. location
483
501
}
484
502
485
503
public findPickleBy ( element : TestCaseStarted | TestStepStarted ) : Pickle | undefined {
486
- if ( 'testCaseStartedId' in element ) {
487
- // TODO implement lookup by TestStepStarted
488
- return undefined
489
- }
490
504
const testCase = this . findTestCaseBy ( element )
491
505
assert . ok ( testCase , 'Expected to find TestCase from TestCaseStarted' )
492
506
return this . pickleById . get ( testCase . pickleId )
@@ -506,11 +520,9 @@ export default class Query {
506
520
}
507
521
508
522
public findTestCaseBy ( element : TestCaseStarted | TestStepStarted ) : TestCase | undefined {
509
- if ( 'testCaseStartedId' in element ) {
510
- // TODO implement lookup by TestStepStarted
511
- return undefined
512
- }
513
- return this . testCaseById . get ( element . testCaseId )
523
+ const testCaseStarted = 'testCaseStartedId' in element ? this . findTestCaseStartedBy ( element ) : element
524
+ assert . ok ( testCaseStarted , 'Expected to find TestCaseStarted by TestStepStarted' )
525
+ return this . testCaseById . get ( testCaseStarted . testCaseId )
514
526
}
515
527
516
528
public findTestCaseDurationBy ( testCaseStarted : TestCaseStarted ) : Duration | undefined {
@@ -525,8 +537,7 @@ export default class Query {
525
537
}
526
538
527
539
public findTestCaseStartedBy ( testStepStarted : TestStepStarted ) : TestCaseStarted | undefined {
528
- // TODO implement
529
- return undefined
540
+ return this . testCaseStartedById . get ( testStepStarted . testCaseStartedId )
530
541
}
531
542
532
543
public findTestCaseFinishedBy ( testCaseStarted : TestCaseStarted ) : TestCaseFinished | undefined {
@@ -558,8 +569,8 @@ export default class Query {
558
569
public findTestStepsStartedBy (
559
570
testCaseStarted : TestCaseStarted
560
571
) : ReadonlyArray < TestStepStarted > {
561
- // TODO implement
562
- return [ ]
572
+ // multimaps `get` implements `getOrDefault([])` behaviour internally
573
+ return [ ... this . testStepStartedByTestCaseStartedId . get ( testCaseStarted . id ) ]
563
574
}
564
575
565
576
public findTestStepsFinishedBy (
@@ -581,7 +592,7 @@ export default class Query {
581
592
} )
582
593
}
583
594
584
- private findLineageBy ( element : Pickle | TestCaseStarted ) {
595
+ private findLineageBy ( element : Pickle | TestCaseStarted ) : Lineage | undefined {
585
596
const pickle = 'testCaseId' in element ? this . findPickleBy ( element ) : element
586
597
const deepestAstNodeId = pickle . astNodeIds . at ( - 1 )
587
598
assert . ok ( deepestAstNodeId , 'Expected Pickle to have at least one astNodeId' )
0 commit comments