Skip to content

Commit 61a74bc

Browse files
authored
Handle messages with fields omitted (#13)
1 parent 27d7f23 commit 61a74bc

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

features/actions/publishReport.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from 'node:path'
55
import { Action } from '../support/Actor.mjs'
66
import { PublishResult } from './types'
77

8-
export const publishReport: (privateToken?: string) => Action<PublishResult> = (privateToken) => {
8+
export const publishReport: (fixture: string, privateToken?: string) => Action<PublishResult> = (fixture, privateToken) => {
99
return async () => {
1010
const headers = new Headers()
1111
if (privateToken) {
@@ -18,7 +18,7 @@ export const publishReport: (privateToken?: string) => Action<PublishResult> = (
1818

1919
if (getResponse.ok && url) {
2020
const putUrl = getResponse.headers.get('Location') as string
21-
const envelopes = readFileSync(path.join(import.meta.dirname, '..', 'fixtures', 'messages-valid.ndjson'), { encoding: 'utf-8' })
21+
const envelopes = readFileSync(path.join(import.meta.dirname, '..', 'fixtures', fixture), { encoding: 'utf-8' })
2222
const putResponse = await fetch(putUrl, {
2323
method: 'PUT',
2424
body: envelopes,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{"meta":{"ci":{"buildNumber":"154666429","git":{"remote":"https://github.com/cucumber-ltd/shouty.rb.git","revision":"99684bcacf01d95875834d87903dcb072306c9ad"},"name":"GitHub Actions","url":"https://github.com/cucumber-ltd/shouty.rb/actions/runs/154666429"},"cpu":{"name":"x64"},"implementation":{"name":"fake-cucumber","version":"18.0.0"},"os":{"name":"darwin","version":"23.6.0"},"protocolVersion":"27.0.0","runtime":{"name":"node.js","version":"22.7.0"}}}
2+
{"source":{"data":"Feature: minimal\n \n Cucumber doesn't execute this markdown, but @cucumber/react renders it\n \n * This is\n * a bullet\n * list\n \n Scenario: cukes\n Given I have 42 cukes in my belly\n","mediaType":"text/x.cucumber.gherkin+plain","uri":"samples/minimal/minimal.feature"}}
3+
{"gherkinDocument":{"comments":[],"feature":{"children":[{"scenario":{"description":"","id":"2","keyword":"Scenario","location":{"column":3,"line":9},"name":"cukes","steps":[{"id":"1","keyword":"Given ","keywordType":"Context","location":{"column":5,"line":10},"text":"I have 42 cukes in my belly"}],"tags":[]}}],"description":" Cucumber doesn't execute this markdown, but @cucumber/react renders it\n \n * This is\n * a bullet\n * list","keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"minimal","tags":[]},"uri":"samples/minimal/minimal.feature"}}
4+
{"pickle":{"astNodeIds":["2"],"id":"4","language":"en","name":"cukes","steps":[{"astNodeIds":["1"],"id":"3","text":"I have 42 cukes in my belly","type":"Context"}],"tags":[],"uri":"samples/minimal/minimal.feature"}}
5+
{"stepDefinition":{"id":"0","pattern":{"source":"I have {int} cukes in my belly","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"location":{"line":3},"uri":"samples/minimal/minimal.feature.ts"}}}
6+
{"testRunStarted":{"id":"5","timestamp":{"seconds":0}}}
7+
{"testCase":{"id":"7","pickleId":"4","testRunStartedId":"5","testSteps":[{"id":"6","pickleStepId":"3","stepDefinitionIds":["0"],"stepMatchArgumentsLists":[{"stepMatchArguments":[{"group":{"children":[],"start":7,"value":"42"},"parameterTypeName":"int"}]}]}]}}
8+
{"testCaseStarted":{"attempt":0,"id":"8","testCaseId":"7","timestamp":{"nanos":1000000,"seconds":0}}}
9+
{"testStepStarted":{"testCaseStartedId":"8","testStepId":"6","timestamp":{"nanos":2000000,"seconds":0}}}
10+
{"testStepFinished":{"testCaseStartedId":"8","testStepId":"6","testStepResult":{"duration":{"nanos":1000000,"seconds":0},"status":"PASSED"},"timestamp":{"nanos":3000000,"seconds":0}}}
11+
{"testCaseFinished":{"testCaseStartedId":"8","timestamp":{"nanos":4000000,"seconds":0},"willBeRetried":false}}
12+
{"testRunFinished":{"success":true,"testRunStartedId":"5","timestamp":{"nanos":5000000,"seconds":0}}}

features/publishing.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ Feature: Publishing
1010
And Garrett shares their link with Hannah
1111
When Hannah views the shared report
1212
Then Hannah should see the test results
13+
14+
Scenario: Report still renders with fields omitted from messages
15+
Given a Cucumber implementation that omits some fields
16+
When Ira publishes a report
17+
And Ira views the report they just published
18+
Then Ira should see their test results

features/steps/steps.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import { wasNotFound } from '../actions/wasNotFound.mjs'
1313
import { navigateToSite } from '../actions/navigateToSite.mjs'
1414
import { canSeeSample } from '../actions/canSeeSample.mjs'
1515

16+
Given('a Cucumber implementation that omits some fields', async (t) => {
17+
t.world.messagesFixture = 'messages-omissions.ndjson'
18+
})
19+
1620
Given('{actor} has a private token', async (t, actor: Actor) => {
1721
actor.remember('privateToken', crypto.randomBytes(16).toString('hex'));
1822
})
@@ -26,7 +30,7 @@ Given('a report previously published by {actor} has been deleted', async (t, act
2630
})
2731

2832
When('{actor} publishes a report', async (t, actor: Actor) => {
29-
const publishResult = await actor.attemptsTo(publishReport(actor.recall('privateToken')))
33+
const publishResult = await actor.attemptsTo(publishReport(t.world.messagesFixture, actor.recall('privateToken')))
3034
actor.remember('publishResult', publishResult)
3135
t.world.publishResults.push(publishResult)
3236
})

features/support/CustomWorld.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PublishResult } from '../actions/types'
66
export class CustomWorld {
77
private readonly actorLookup = new ActorLookup()
88
private browser: Browser | undefined
9+
public messagesFixture = 'messages-valid.ndjson'
910
public publishResults: Array<PublishResult> = []
1011

1112
public findOrCreateActor(actorName: string): Actor {

src/hooks/useEnvelopes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQuery } from '@tanstack/react-query'
2-
import { Envelope } from '@cucumber/messages'
2+
import { Envelope, parseEnvelope } from '@cucumber/messages'
33

44
export function useEnvelopes(id: string, getUrl: string) {
55
return useQuery({
@@ -10,7 +10,7 @@ export function useEnvelopes(id: string, getUrl: string) {
1010
throw new Error('Failed to fetch envelopes', { cause: response })
1111
}
1212
const raw = await response.text()
13-
return raw.trim().split('\n').map(s => JSON.parse(s) as Envelope)
13+
return raw.trim().split('\n').map(s => parseEnvelope(s))
1414
},
1515
meta: {
1616
envelopes: true

0 commit comments

Comments
 (0)