diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a140eac..c477c5ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - New method `findAttachmentsBy(TestStepFinished)` ([#67](https://github.com/cucumber/query/pull/67)) - New method `findHookBy(TestStep)` ([#67](https://github.com/cucumber/query/pull/67)) +- New method `findMeta()` ([#67](https://github.com/cucumber/query/pull/67)) ### Fixed - [JavaScript] Attachments are not presumed to have a related test step ([#67](https://github.com/cucumber/query/pull/67)) diff --git a/README.md b/README.md index 8d3bf9d9..9182d34a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ status of a step, a scenario or an entire file. | `findAttachmentsBy(TestStepFinished): List` | | | ✓ | | ✓ | | `findFeatureBy(TestCaseStarted): Optional` | | | ✓ | | ✓ | | `findHookBy(TestStep): Optional` | | | ✓ | | ✓ | +| `findMeta(): Optional` | | | ✓ | | ✓ | | `findMostSevereTestStepResulBy(TestCaseStarted): Optional` | | | ✓ | | ✓ | | `findNameOf(Pickle, NamingStrategy): String` | | | ✓ | | ✓ | | `findPickleBy(TestCaseStarted): Optional` | | | ✓ | | ✓ | diff --git a/java/src/main/java/io/cucumber/query/Query.java b/java/src/main/java/io/cucumber/query/Query.java index 742ce0ad..7a557a2f 100644 --- a/java/src/main/java/io/cucumber/query/Query.java +++ b/java/src/main/java/io/cucumber/query/Query.java @@ -1,28 +1,7 @@ package io.cucumber.query; import io.cucumber.messages.Convertor; -import io.cucumber.messages.types.Attachment; -import io.cucumber.messages.types.Envelope; -import io.cucumber.messages.types.Examples; -import io.cucumber.messages.types.Feature; -import io.cucumber.messages.types.GherkinDocument; -import io.cucumber.messages.types.Hook; -import io.cucumber.messages.types.Pickle; -import io.cucumber.messages.types.PickleStep; -import io.cucumber.messages.types.Rule; -import io.cucumber.messages.types.Scenario; -import io.cucumber.messages.types.Step; -import io.cucumber.messages.types.TableRow; -import io.cucumber.messages.types.TestCase; -import io.cucumber.messages.types.TestCaseFinished; -import io.cucumber.messages.types.TestCaseStarted; -import io.cucumber.messages.types.TestRunFinished; -import io.cucumber.messages.types.TestRunStarted; -import io.cucumber.messages.types.TestStep; -import io.cucumber.messages.types.TestStepFinished; -import io.cucumber.messages.types.TestStepResult; -import io.cucumber.messages.types.TestStepResultStatus; -import io.cucumber.messages.types.Timestamp; +import io.cucumber.messages.types.*; import java.time.Duration; import java.util.*; @@ -72,6 +51,7 @@ public final class Query { private final Map hookById = new ConcurrentHashMap<>(); private final Map> attachmentsByTestCaseStartedId = new ConcurrentHashMap<>(); private final Map lineageById = new ConcurrentHashMap<>(); + private Meta meta; private TestRunStarted testRunStarted; private TestRunFinished testRunFinished; @@ -157,6 +137,10 @@ public Optional findHookBy(TestStep testStep) { .map(hookById::get); } + public Optional findMeta() { + return ofNullable(meta); + } + public Optional findMostSevereTestStepResultBy(TestCaseStarted testCaseStarted) { requireNonNull(testCaseStarted); return findTestStepsFinishedBy(testCaseStarted) @@ -348,6 +332,7 @@ public List> findTestStepFinishedAndTestStepBy } public void update(Envelope envelope) { + envelope.getMeta().ifPresent(this::updateMeta); envelope.getTestRunStarted().ifPresent(this::updateTestRunStarted); envelope.getTestRunFinished().ifPresent(this::updateTestRunFinished); envelope.getTestCaseStarted().ifPresent(this::updateTestCaseStarted); @@ -466,6 +451,10 @@ private void updateSteps(List steps) { steps.forEach(step -> stepById.put(step.getId(), step)); } + private void updateMeta(Meta event) { + this.meta = event; + } + private BiFunction, List> updateList(E element) { return (key, existing) -> { if (existing != null) { diff --git a/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java b/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java index 007159d8..bd0ed49c 100644 --- a/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java +++ b/java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java @@ -137,6 +137,7 @@ private static Map createQueryResults(Query query) { .map(hook -> hook.map(Hook::getId)) .filter(Optional::isPresent) .collect(toList())); + results.put("findMeta", query.findMeta().map(meta -> meta.getImplementation().getName())); results.put("findMostSevereTestStepResultBy", query.findAllTestCaseStarted().stream() .map(query::findMostSevereTestStepResultBy) .map(testStepResult -> testStepResult.map(TestStepResult::getStatus)) diff --git a/javascript/src/Query.ts b/javascript/src/Query.ts index 0f5dca93..d5078d22 100644 --- a/javascript/src/Query.ts +++ b/javascript/src/Query.ts @@ -4,7 +4,9 @@ import { Duration, Feature, getWorstTestStepResult, - GherkinDocument, Hook, + GherkinDocument, + Hook, + Meta, Pickle, PickleStep, Rule, @@ -46,6 +48,7 @@ export default class Query { readonly messages.StepMatchArgumentsList[] >() + private meta: Meta private testRunStarted: TestRunStarted private testRunFinished: TestRunFinished private readonly testCaseStarted: Array = [] @@ -62,6 +65,9 @@ export default class Query { new ArrayMultimap() public update(envelope: messages.Envelope) { + if (envelope.meta) { + this.meta = envelope.meta + } if (envelope.gherkinDocument) { this.updateGherkinDocument(envelope.gherkinDocument) } @@ -448,6 +454,10 @@ export default class Query { return this.hooksById.get(testStep.hookId) } + public findMeta(): Meta | undefined { + return this.meta; + } + public findMostSevereTestStepResultBy(testCaseStarted: TestCaseStarted): TestStepResult | undefined { return this.findTestStepFinishedAndTestStepBy(testCaseStarted) .map(([testStepFinished]) => testStepFinished.testStepResult) diff --git a/javascript/src/acceptance.spec.ts b/javascript/src/acceptance.spec.ts index 713efdba..5ff1f226 100644 --- a/javascript/src/acceptance.spec.ts +++ b/javascript/src/acceptance.spec.ts @@ -77,6 +77,7 @@ describe('Acceptance Tests', async () => { .map(testStep => query.findHookBy(testStep)) .map(hook => hook?.id) .filter(value => !!value), + findMeta: query.findMeta()?.implementation?.name, findMostSevereTestStepResultBy: query.findAllTestCaseStarted() .map(testCaseStarted => query.findMostSevereTestStepResultBy(testCaseStarted)) .map(testStepResult => testStepResult?.status), @@ -135,6 +136,7 @@ interface ResultsFixture { findAllTestCaseStartedGroupedByFeature: Array<[string, string[]]>, findAttachmentsBy: Array<[string, string, string, string]>, findFeatureBy: Array, + findMeta: string, findMostSevereTestStepResultBy: Array, findNameOf: { long: Array, diff --git a/testdata/attachments.feature.query-results.json b/testdata/attachments.feature.query-results.json index 5181f27a..3e9fd7c8 100644 --- a/testdata/attachments.feature.query-results.json +++ b/testdata/attachments.feature.query-results.json @@ -116,6 +116,7 @@ "0", "0" ], + "findMeta" : "fake-cucumber", "findMostSevereTestStepResultBy" : [ "PASSED", "PASSED", diff --git a/testdata/examples-tables.feature.query-results.json b/testdata/examples-tables.feature.query-results.json index a7ed16a0..d758daab 100644 --- a/testdata/examples-tables.feature.query-results.json +++ b/testdata/examples-tables.feature.query-results.json @@ -40,6 +40,7 @@ "Examples Tables", "Examples Tables" ], + "findMeta" : "fake-cucumber", "findMostSevereTestStepResultBy" : [ "PASSED", "PASSED", diff --git a/testdata/hooks.feature.query-results.json b/testdata/hooks.feature.query-results.json index 58db040e..f00da354 100644 --- a/testdata/hooks.feature.query-results.json +++ b/testdata/hooks.feature.query-results.json @@ -59,6 +59,7 @@ "6", "4" ], + "findMeta" : "fake-cucumber", "findMostSevereTestStepResultBy" : [ "PASSED", "FAILED", diff --git a/testdata/minimal.feature.query-results.json b/testdata/minimal.feature.query-results.json index 6bf98eff..479527fc 100644 --- a/testdata/minimal.feature.query-results.json +++ b/testdata/minimal.feature.query-results.json @@ -24,6 +24,7 @@ "findFeatureBy" : [ "minimal" ], + "findMeta" : "fake-cucumber", "findMostSevereTestStepResultBy" : [ "PASSED" ], diff --git a/testdata/rules.feature.query-results.json b/testdata/rules.feature.query-results.json index dd05d44c..b268bff7 100644 --- a/testdata/rules.feature.query-results.json +++ b/testdata/rules.feature.query-results.json @@ -28,6 +28,7 @@ "Usage of a `Rule`", "Usage of a `Rule`" ], + "findMeta" : "fake-cucumber", "findMostSevereTestStepResultBy" : [ "PASSED", "PASSED",