diff --git a/CHANGELOG.md b/CHANGELOG.md index 692345ac..ed63eea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Add `findTestRunHookFinishedBy(TestRunHookStarted)` ([#109](https://github.com/cucumber/query/pull/109)) - Add `findAttachmentsBy(TestRunHookFinished)` ([#109](https://github.com/cucumber/query/pull/109)) +### Fixed +- [JavaScript] Support `TestCaseFinished` as parameter to `findTestStepsStartedBy` ([#111](https://github.com/cucumber/query/pull/111)) + ## [14.1.0] - 2025-09-15 ### Added - [Java] Add `findTestCaseStartedBy(TestCaseFinished)` diff --git a/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java b/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java index 6bfddbc1..ae87a845 100644 --- a/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java +++ b/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java @@ -18,6 +18,7 @@ import io.cucumber.messages.types.TestStep; import io.cucumber.messages.types.TestStepFinished; import io.cucumber.messages.types.TestStepResult; +import io.cucumber.messages.types.TestStepStarted; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -336,6 +337,22 @@ static Map> createQueries() { .map(testStep -> testStep.map(TestStep::getId)) .collect(toList())); + queries.put("findTestStepsStartedBy", (query) -> { + Map results = new LinkedHashMap<>(); + + results.put("testCaseStarted", query.findAllTestCaseStarted().stream() + .map(query::findTestStepsStartedBy) + .map(Collection::stream) + .map(testStepStarted -> testStepStarted.map(TestStepStarted::getTestStepId)) + .collect(toList())); + results.put("testCaseFinished", query.findAllTestCaseFinished().stream() + .map(query::findTestStepsStartedBy) + .map(Collection::stream) + .map(testStepStarted -> testStepStarted.map(TestStepStarted::getTestStepId)) + .collect(toList())); + return results; + }); + queries.put("findTestRunHookFinishedBy", (query) -> query.findAllTestRunHookStarted().stream() .map(query::findTestRunHookFinishedBy) .map(testRunHookFinished -> testRunHookFinished.map(TestRunHookFinished::getTestRunHookStartedId)) diff --git a/javascript/src/Query.ts b/javascript/src/Query.ts index 721535a0..0b7a1c01 100644 --- a/javascript/src/Query.ts +++ b/javascript/src/Query.ts @@ -676,9 +676,13 @@ export default class Query { return this.testStepById.get(element.testStepId) } - public findTestStepsStartedBy(testCaseStarted: TestCaseStarted): ReadonlyArray { + public findTestStepsStartedBy( + element: TestCaseStarted | TestCaseFinished + ): ReadonlyArray { + const testCaseStartedId = + 'testCaseStartedId' in element ? element.testCaseStartedId : element.id // multimaps `get` implements `getOrDefault([])` behaviour internally - return [...this.testStepStartedByTestCaseStartedId.get(testCaseStarted.id)] + return [...this.testStepStartedByTestCaseStartedId.get(testCaseStartedId)] } public findTestStepsFinishedBy( diff --git a/javascript/src/acceptance.spec.ts b/javascript/src/acceptance.spec.ts index 09c6eaeb..b5286826 100644 --- a/javascript/src/acceptance.spec.ts +++ b/javascript/src/acceptance.spec.ts @@ -205,6 +205,22 @@ describe('Acceptance Tests', async () => { .flatMap((testCaseStarted) => query.findTestStepsStartedBy(testCaseStarted)) .map((testStepStarted) => query.findTestStepBy(testStepStarted)) .map((testStep) => testStep?.id), + findTestStepsStartedBy: (query: Query) => { + return { + testCaseStarted: query + .findAllTestCaseStarted() + .map((testCaseStarted) => query.findTestStepsStartedBy(testCaseStarted)) + .map((testStepsStarted) => + testStepsStarted.map((testStepStarted) => testStepStarted.testStepId) + ), + testCaseFinished: query + .findAllTestCaseFinished() + .map((testCaseFinished) => query.findTestStepsStartedBy(testCaseFinished)) + .map((testStepsStarted) => + testStepsStarted.map((testStepStarted) => testStepStarted.testStepId) + ), + } + }, findTestStepByTestStepFinished: (query: Query) => { return { testCaseStarted: query diff --git a/testdata/src/attachments.findTestStepsStartedBy.results.json b/testdata/src/attachments.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..4f9ab446 --- /dev/null +++ b/testdata/src/attachments.findTestStepsStartedBy.results.json @@ -0,0 +1,48 @@ +{ + "testCaseStarted" : [ + [ + "37" + ], + [ + "39" + ], + [ + "41" + ], + [ + "43" + ], + [ + "45" + ], + [ + "47" + ], + [ + "49" + ] + ], + "testCaseFinished" : [ + [ + "37" + ], + [ + "39" + ], + [ + "41" + ], + [ + "43" + ], + [ + "45" + ], + [ + "47" + ], + [ + "49" + ] + ] +} \ No newline at end of file diff --git a/testdata/src/empty.findTestStepsStartedBy.results.json b/testdata/src/empty.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..713d2c73 --- /dev/null +++ b/testdata/src/empty.findTestStepsStartedBy.results.json @@ -0,0 +1,8 @@ +{ + "testCaseStarted" : [ + [ ] + ], + "testCaseFinished" : [ + [ ] + ] +} \ No newline at end of file diff --git a/testdata/src/examples-tables.findTestStepsStartedBy.results.json b/testdata/src/examples-tables.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..2cf18c71 --- /dev/null +++ b/testdata/src/examples-tables.findTestStepsStartedBy.results.json @@ -0,0 +1,96 @@ +{ + "testCaseStarted" : [ + [ + "71", + "72", + "73" + ], + [ + "75", + "76", + "77" + ], + [ + "79", + "80", + "81" + ], + [ + "83", + "84", + "85" + ], + [ + "87", + "88", + "89" + ], + [ + "91", + "92", + "93" + ], + [ + "95", + "96", + "97" + ], + [ + "99", + "100", + "101" + ], + [ + "103", + "104", + "105" + ] + ], + "testCaseFinished" : [ + [ + "71", + "72", + "73" + ], + [ + "75", + "76", + "77" + ], + [ + "79", + "80", + "81" + ], + [ + "83", + "84", + "85" + ], + [ + "87", + "88", + "89" + ], + [ + "91", + "92", + "93" + ], + [ + "95", + "96", + "97" + ], + [ + "99", + "100", + "101" + ], + [ + "103", + "104", + "105" + ] + ] +} \ No newline at end of file diff --git a/testdata/src/global-hooks-attachments.findTestStepsStartedBy.results.json b/testdata/src/global-hooks-attachments.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..68029809 --- /dev/null +++ b/testdata/src/global-hooks-attachments.findTestStepsStartedBy.results.json @@ -0,0 +1,12 @@ +{ + "testCaseStarted" : [ + [ + "10" + ] + ], + "testCaseFinished" : [ + [ + "10" + ] + ] +} \ No newline at end of file diff --git a/testdata/src/global-hooks.findTestStepsStartedBy.results.json b/testdata/src/global-hooks.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..c5ac03fe --- /dev/null +++ b/testdata/src/global-hooks.findTestStepsStartedBy.results.json @@ -0,0 +1,18 @@ +{ + "testCaseStarted" : [ + [ + "18" + ], + [ + "20" + ] + ], + "testCaseFinished" : [ + [ + "18" + ], + [ + "20" + ] + ] +} \ No newline at end of file diff --git a/testdata/src/hooks.findTestStepsStartedBy.results.json b/testdata/src/hooks.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..991ddce8 --- /dev/null +++ b/testdata/src/hooks.findTestStepsStartedBy.results.json @@ -0,0 +1,36 @@ +{ + "testCaseStarted" : [ + [ + "18", + "19", + "20" + ], + [ + "22", + "23", + "24" + ], + [ + "26", + "27", + "28" + ] + ], + "testCaseFinished" : [ + [ + "18", + "19", + "20" + ], + [ + "22", + "23", + "24" + ], + [ + "26", + "27", + "28" + ] + ] +} \ No newline at end of file diff --git a/testdata/src/minimal.findTestStepsStartedBy.results.json b/testdata/src/minimal.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..99df297f --- /dev/null +++ b/testdata/src/minimal.findTestStepsStartedBy.results.json @@ -0,0 +1,12 @@ +{ + "testCaseStarted" : [ + [ + "7" + ] + ], + "testCaseFinished" : [ + [ + "7" + ] + ] +} \ No newline at end of file diff --git a/testdata/src/rules.findTestStepsStartedBy.results.json b/testdata/src/rules.findTestStepsStartedBy.results.json new file mode 100644 index 00000000..c30a7a42 --- /dev/null +++ b/testdata/src/rules.findTestStepsStartedBy.results.json @@ -0,0 +1,42 @@ +{ + "testCaseStarted" : [ + [ + "41", + "42", + "43", + "44" + ], + [ + "46", + "47", + "48", + "49" + ], + [ + "51", + "52", + "53", + "54" + ] + ], + "testCaseFinished" : [ + [ + "41", + "42", + "43", + "44" + ], + [ + "46", + "47", + "48", + "49" + ], + [ + "51", + "52", + "53", + "54" + ] + ] +} \ No newline at end of file