Skip to content

Commit

Permalink
add findMeta method
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss committed Jan 3, 2025
1 parent a541c36 commit 8a33881
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ status of a step, a scenario or an entire file.
| `findAttachmentsBy(TestStepFinished): List<Attachment>` | | || ||
| `findFeatureBy(TestCaseStarted): Optional<Feature>` | | || ||
| `findHookBy(TestStep): Optional<Hook>` | | || ||
| `findMeta(): Optional<Meta>` | | || ||
| `findMostSevereTestStepResulBy(TestCaseStarted): Optional<TestStepResult>` | | || ||
| `findNameOf(Pickle, NamingStrategy): String` | | || ||
| `findPickleBy(TestCaseStarted): Optional<Pickle>` | | || ||
Expand Down
33 changes: 11 additions & 22 deletions java/src/main/java/io/cucumber/query/Query.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -72,6 +51,7 @@ public final class Query {
private final Map<String, Hook> hookById = new ConcurrentHashMap<>();
private final Map<String, List<Attachment>> attachmentsByTestCaseStartedId = new ConcurrentHashMap<>();
private final Map<Object, Lineage> lineageById = new ConcurrentHashMap<>();
private Meta meta;
private TestRunStarted testRunStarted;
private TestRunFinished testRunFinished;

Expand Down Expand Up @@ -157,6 +137,10 @@ public Optional<Hook> findHookBy(TestStep testStep) {
.map(hookById::get);
}

public Optional<Meta> findMeta() {
return ofNullable(meta);
}

public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseStarted testCaseStarted) {
requireNonNull(testCaseStarted);
return findTestStepsFinishedBy(testCaseStarted)
Expand Down Expand Up @@ -348,6 +332,7 @@ public List<Entry<TestStepFinished, TestStep>> 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);
Expand Down Expand Up @@ -466,6 +451,10 @@ private void updateSteps(List<Step> steps) {
steps.forEach(step -> stepById.put(step.getId(), step));
}

private void updateMeta(Meta event) {
this.meta = event;
}

private <K, E> BiFunction<K, List<E>, List<E>> updateList(E element) {
return (key, existing) -> {
if (existing != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private static Map<String, Object> 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))
Expand Down
12 changes: 11 additions & 1 deletion javascript/src/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
Duration,
Feature,
getWorstTestStepResult,
GherkinDocument, Hook,
GherkinDocument,
Hook,
Meta,
Pickle,
PickleStep,
Rule,
Expand Down Expand Up @@ -46,6 +48,7 @@ export default class Query {
readonly messages.StepMatchArgumentsList[]
>()

private meta: Meta
private testRunStarted: TestRunStarted
private testRunFinished: TestRunFinished
private readonly testCaseStarted: Array<TestCaseStarted> = []
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions javascript/src/acceptance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -135,6 +136,7 @@ interface ResultsFixture {
findAllTestCaseStartedGroupedByFeature: Array<[string, string[]]>,
findAttachmentsBy: Array<[string, string, string, string]>,
findFeatureBy: Array<string>,
findMeta: string,
findMostSevereTestStepResultBy: Array<TestStepResultStatus>,
findNameOf: {
long: Array<string>,
Expand Down
1 change: 1 addition & 0 deletions testdata/attachments.feature.query-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"0",
"0"
],
"findMeta" : "fake-cucumber",
"findMostSevereTestStepResultBy" : [
"PASSED",
"PASSED",
Expand Down
1 change: 1 addition & 0 deletions testdata/examples-tables.feature.query-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Examples Tables",
"Examples Tables"
],
"findMeta" : "fake-cucumber",
"findMostSevereTestStepResultBy" : [
"PASSED",
"PASSED",
Expand Down
1 change: 1 addition & 0 deletions testdata/hooks.feature.query-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"6",
"4"
],
"findMeta" : "fake-cucumber",
"findMostSevereTestStepResultBy" : [
"PASSED",
"FAILED",
Expand Down
1 change: 1 addition & 0 deletions testdata/minimal.feature.query-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"findFeatureBy" : [
"minimal"
],
"findMeta" : "fake-cucumber",
"findMostSevereTestStepResultBy" : [
"PASSED"
],
Expand Down
1 change: 1 addition & 0 deletions testdata/rules.feature.query-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"Usage of a `Rule`",
"Usage of a `Rule`"
],
"findMeta" : "fake-cucumber",
"findMostSevereTestStepResultBy" : [
"PASSED",
"PASSED",
Expand Down

0 comments on commit 8a33881

Please sign in to comment.