Skip to content

Commit 412ef9a

Browse files
committed
add new real implementations
1 parent 85b81e8 commit 412ef9a

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

javascript/src/Query.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ export default class Query {
5353
private testRunStarted: TestRunStarted
5454
private testRunFinished: TestRunFinished
5555
private readonly testCaseStarted: Array<TestCaseStarted> = []
56+
private readonly testCaseStartedById: Map<string, TestCaseStarted> = new Map()
5657
private readonly lineageById: Map<string, Lineage> = new Map()
5758
private readonly stepById: Map<string, Step> = new Map()
5859
private readonly pickleById: Map<string, Pickle> = new Map()
5960
private readonly pickleStepById: Map<string, PickleStep> = new Map()
6061
private readonly testCaseById: Map<string, TestCase> = new Map()
6162
private readonly testStepById: Map<string, TestStep> = new Map()
6263
private readonly testCaseFinishedByTestCaseStartedId: Map<string, TestCaseFinished> = new Map()
64+
private readonly testStepStartedByTestCaseStartedId: ArrayMultimap<string, TestStepStarted> =
65+
new ArrayMultimap()
6366
private readonly testStepFinishedByTestCaseStartedId: ArrayMultimap<string, TestStepFinished> =
6467
new ArrayMultimap()
6568
private readonly attachmentsByTestCaseStartedId: ArrayMultimap<string, Attachment> =
@@ -87,6 +90,9 @@ export default class Query {
8790
if (envelope.testCaseStarted) {
8891
this.updateTestCaseStarted(envelope.testCaseStarted)
8992
}
93+
if (envelope.testStepStarted) {
94+
this.updateTestStepStarted(envelope.testStepStarted)
95+
}
9096
if (envelope.attachment) {
9197
this.updateAttachment(envelope.attachment)
9298
}
@@ -196,6 +202,7 @@ export default class Query {
196202

197203
private updateTestCaseStarted(testCaseStarted: TestCaseStarted) {
198204
this.testCaseStarted.push(testCaseStarted)
205+
this.testCaseStartedById.set(testCaseStarted.id, testCaseStarted)
199206

200207
/*
201208
when a test case attempt starts besides the first one, clear all existing results
@@ -211,6 +218,13 @@ export default class Query {
211218
}
212219
}
213220

221+
private updateTestStepStarted(testStepStarted: TestStepStarted) {
222+
this.testStepStartedByTestCaseStartedId.put(
223+
testStepStarted.testCaseStartedId,
224+
testStepStarted
225+
)
226+
}
227+
214228
private updateAttachment(attachment: Attachment) {
215229
if (attachment.testStepId) {
216230
this.attachmentsByTestStepId.put(attachment.testStepId, attachment)
@@ -479,14 +493,14 @@ export default class Query {
479493
}
480494

481495
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
483501
}
484502

485503
public findPickleBy(element: TestCaseStarted | TestStepStarted): Pickle | undefined {
486-
if ('testCaseStartedId' in element) {
487-
// TODO implement lookup by TestStepStarted
488-
return undefined
489-
}
490504
const testCase = this.findTestCaseBy(element)
491505
assert.ok(testCase, 'Expected to find TestCase from TestCaseStarted')
492506
return this.pickleById.get(testCase.pickleId)
@@ -506,11 +520,9 @@ export default class Query {
506520
}
507521

508522
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)
514526
}
515527

516528
public findTestCaseDurationBy(testCaseStarted: TestCaseStarted): Duration | undefined {
@@ -525,8 +537,7 @@ export default class Query {
525537
}
526538

527539
public findTestCaseStartedBy(testStepStarted: TestStepStarted): TestCaseStarted | undefined {
528-
// TODO implement
529-
return undefined
540+
return this.testCaseStartedById.get(testStepStarted.testCaseStartedId)
530541
}
531542

532543
public findTestCaseFinishedBy(testCaseStarted: TestCaseStarted): TestCaseFinished | undefined {
@@ -558,8 +569,8 @@ export default class Query {
558569
public findTestStepsStartedBy(
559570
testCaseStarted: TestCaseStarted
560571
): ReadonlyArray<TestStepStarted> {
561-
// TODO implement
562-
return []
572+
// multimaps `get` implements `getOrDefault([])` behaviour internally
573+
return [...this.testStepStartedByTestCaseStartedId.get(testCaseStarted.id)]
563574
}
564575

565576
public findTestStepsFinishedBy(
@@ -581,7 +592,7 @@ export default class Query {
581592
})
582593
}
583594

584-
private findLineageBy(element: Pickle | TestCaseStarted) {
595+
private findLineageBy(element: Pickle | TestCaseStarted): Lineage | undefined {
585596
const pickle = 'testCaseId' in element ? this.findPickleBy(element) : element
586597
const deepestAstNodeId = pickle.astNodeIds.at(-1)
587598
assert.ok(deepestAstNodeId, 'Expected Pickle to have at least one astNodeId')

0 commit comments

Comments
 (0)