Skip to content

Commit 48a018a

Browse files
authored
Add findLineageBy TestCaseFinished (#123)
1 parent 8521e27 commit 48a018a

14 files changed

+58
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9+
- Add `findLineageBy(TestCaseFinished)` ([#119](https://github.com/cucumber/query/pull/119))
910

1011
## [14.5.0] - 2025-10-08
1112
### Added

java/src/main/java/io/cucumber/query/Query.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,9 @@ public Optional<Lineage> findLineageBy(TestCaseStarted testCaseStarted) {
458458
return findPickleBy(testCaseStarted)
459459
.flatMap(this::findLineageBy);
460460
}
461+
462+
public Optional<Lineage> findLineageBy(TestCaseFinished testCaseFinished) {
463+
return findPickleBy(testCaseFinished)
464+
.flatMap(this::findLineageBy);
465+
}
461466
}

java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ static Map<String, Function<Query, Object>> createQueries() {
182182
.map(Optional::get)
183183
.map(namingStrategy::reduce)
184184
.collect(toList()));
185+
results.put("testCaseFinished", query.findAllTestCaseFinished().stream()
186+
.map(query::findLineageBy)
187+
.filter(Optional::isPresent)
188+
.map(Optional::get)
189+
.map(namingStrategy::reduce)
190+
.collect(toList()));
185191
results.put("pickle", query.findAllPickles().stream()
186192
.map(query::findLineageBy)
187193
.filter(Optional::isPresent)

javascript/src/Query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ export default class Query {
728728
})
729729
}
730730

731-
public findLineageBy(element: Pickle | TestCaseStarted): Lineage | undefined {
732-
const pickle = 'testCaseId' in element ? this.findPickleBy(element) : element
731+
public findLineageBy(element: Pickle | TestCaseStarted | TestCaseFinished): Lineage | undefined {
732+
const pickle = 'astNodeIds' in element ? element : this.findPickleBy(element)
733733
const deepestAstNodeId = pickle.astNodeIds.at(-1)
734734
assert.ok(deepestAstNodeId, 'Expected Pickle to have at least one astNodeId')
735735
return this.lineageById.get(deepestAstNodeId)

javascript/src/acceptance.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ describe('Acceptance Tests', async () => {
107107
},
108108
findLocationOf: (query: Query) =>
109109
query.findAllPickles().map((pickle) => query.findLocationOf(pickle)),
110+
110111
findPickleBy: (query: Query) => {
111112
return {
112113
testCaseStarted: query

testdata/src/attachments.findLineageBy.results.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
"Attachments - Attaching PDFs with a different filename",
99
"Attachments - Attaching URIs"
1010
],
11+
"testCaseFinished" : [
12+
"Attachments - Strings can be attached with a media type",
13+
"Attachments - Log text",
14+
"Attachments - Log ANSI coloured text",
15+
"Attachments - Log JSON",
16+
"Attachments - Byte arrays are base64-encoded regardless of media type",
17+
"Attachments - Attaching PDFs with a different filename",
18+
"Attachments - Attaching URIs"
19+
],
1120
"pickle" : [
1221
"Attachments - Strings can be attached with a media type",
1322
"Attachments - Log text",

testdata/src/empty.findLineageBy.results.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"testCaseStarted" : [
33
"Empty Scenarios - Blank Scenario"
44
],
5+
"testCaseFinished" : [
6+
"Empty Scenarios - Blank Scenario"
7+
],
58
"pickle" : [
69
"Empty Scenarios - Blank Scenario"
710
]

testdata/src/examples-tables.findLineageBy.results.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
"Examples Tables - Eating cucumbers with <friends> friends - #1.2",
99
"Examples Tables - Eating cucumbers with <friends> friends - #1.3"
1010
],
11+
"testCaseFinished" : [
12+
"Examples Tables - Eating cucumbers - These are passing - #1.1",
13+
"Examples Tables - Eating cucumbers - These are passing - #1.2",
14+
"Examples Tables - Eating cucumbers - These are failing - #2.1",
15+
"Examples Tables - Eating cucumbers - These are failing - #2.2",
16+
"Examples Tables - Eating cucumbers with <friends> friends - #1.1",
17+
"Examples Tables - Eating cucumbers with <friends> friends - #1.2",
18+
"Examples Tables - Eating cucumbers with <friends> friends - #1.3"
19+
],
1120
"pickle" : [
1221
"Examples Tables - Eating cucumbers - These are passing - #1.1",
1322
"Examples Tables - Eating cucumbers - These are passing - #1.2",

testdata/src/global-hooks-attachments.findLineageBy.results.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"testCaseStarted" : [
33
"Global hooks with attachments - A scenario"
44
],
5+
"testCaseFinished" : [
6+
"Global hooks with attachments - A scenario"
7+
],
58
"pickle" : [
69
"Global hooks with attachments - A scenario"
710
]

testdata/src/global-hooks.findLineageBy.results.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"Global hooks - A passing scenario",
44
"Global hooks - A failing scenario"
55
],
6+
"testCaseFinished" : [
7+
"Global hooks - A passing scenario",
8+
"Global hooks - A failing scenario"
9+
],
610
"pickle" : [
711
"Global hooks - A passing scenario",
812
"Global hooks - A failing scenario"

0 commit comments

Comments
 (0)