-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update to BDD Markdown v6 (#243)
- Loading branch information
1 parent
7c76431
commit ee7d15e
Showing
8 changed files
with
113 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { markdownReporter } from '@nordicsemiconductor/bdd-markdown' | ||
|
||
process.stdin.on('data', (data) => { | ||
console.log(markdownReporter(JSON.parse(data.toString()))) | ||
process.stdin.on('data', async (data) => { | ||
console.log(await markdownReporter(JSON.parse(data.toString()))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,58 @@ | ||
import { | ||
codeBlockOrThrow, | ||
noMatch, | ||
StepRunner, | ||
StepRunnerArgs, | ||
StepRunResult, | ||
groupMatcher, | ||
} from '@nordicsemiconductor/bdd-markdown' | ||
import assert from 'assert/strict' | ||
import fetch, { Response } from 'node-fetch' | ||
import { World } from '../run-features.js' | ||
import { Type } from '@sinclair/typebox' | ||
|
||
export const steps = (): StepRunner<World>[] => { | ||
let baseUrl: URL | undefined = undefined | ||
let res: Response | undefined = undefined | ||
return [ | ||
async ({ step }: StepRunnerArgs<World>): Promise<StepRunResult> => { | ||
const match = /^the endpoint is `(?<endpoint>[^`]+)`$/.exec(step.title) | ||
if (match === null) return noMatch | ||
baseUrl = new URL(match.groups?.endpoint ?? '') | ||
}, | ||
async ({ | ||
step, | ||
log: { | ||
step: { progress }, | ||
feature: { progress: featureProgress }, | ||
groupMatcher( | ||
{ | ||
regExp: /^the endpoint is `(?<endpoint>[^`]+)`$/, | ||
schema: Type.Object({ endpoint: Type.String() }), | ||
}, | ||
}: StepRunnerArgs<World>): Promise<StepRunResult> => { | ||
const match = | ||
/^I (?<method>POST) to `(?<resource>[^`]+)` with this JSON$/.exec( | ||
step.title, | ||
) | ||
if (match === null) return noMatch | ||
const url = new URL(match.groups?.resource ?? '/', baseUrl).toString() | ||
const method = match.groups?.method ?? 'GET' | ||
progress(`${method} ${url}`) | ||
const body = codeBlockOrThrow(step).code | ||
progress(body) | ||
|
||
res = await fetch(url, { | ||
method, | ||
body, | ||
}) | ||
async ({ match: { endpoint } }) => { | ||
baseUrl = new URL(endpoint) | ||
}, | ||
), | ||
groupMatcher( | ||
{ | ||
regExp: /^I (?<method>POST) to `(?<resource>[^`]+)` with this JSON$/, | ||
schema: Type.Object({ method: Type.String(), resource: Type.String() }), | ||
}, | ||
async ({ match: { method, resource }, log: { progress }, step }) => { | ||
const url = new URL(resource, baseUrl).toString() | ||
progress(`${method} ${url}`) | ||
const body = codeBlockOrThrow(step).code | ||
progress(body) | ||
|
||
progress(`${res.status} ${res.statusText}`) | ||
featureProgress(`x-amzn-trace-id: ${res.headers.get('x-amzn-trace-id')}`) | ||
}, | ||
async ({ step }: StepRunnerArgs<World>): Promise<StepRunResult> => { | ||
const match = /^the response status code should be (?<code>[0-9]+)$/.exec( | ||
step.title, | ||
) | ||
if (match === null) return noMatch | ||
res = await fetch(url, { | ||
method, | ||
body, | ||
}) | ||
|
||
assert.equal(res?.status, parseInt(match.groups?.code ?? '-1', 10)) | ||
}, | ||
progress(`${res.status} ${res.statusText}`) | ||
progress(`x-amzn-trace-id: ${res.headers.get('x-amzn-trace-id')}`) | ||
}, | ||
), | ||
groupMatcher( | ||
{ | ||
regExp: /^the response status code should be (?<code>[0-9]+)$/, | ||
schema: Type.Object({ code: Type.Integer() }), | ||
converters: { | ||
code: (s) => parseInt(s, 10), | ||
}, | ||
|
||
}, | ||
async ({ match: { code } }) => { | ||
assert.equal(res?.status, code) | ||
}, | ||
), | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,44 @@ | ||
import { | ||
codeBlockOrThrow, | ||
noMatch, | ||
groupMatcher, | ||
StepRunner, | ||
StepRunnerArgs, | ||
StepRunResult, | ||
} from '@nordicsemiconductor/bdd-markdown' | ||
import assert from 'assert/strict' | ||
import { World } from '../run-features.js' | ||
import { WebhookReceiver } from './webhook-receiver.js' | ||
import { Type } from '@sinclair/typebox' | ||
|
||
export const steps = (): StepRunner<World>[] => { | ||
let r: WebhookReceiver | ||
|
||
return [ | ||
async ({ | ||
step, | ||
log: { step: log }, | ||
context: { webhookQueue }, | ||
}: StepRunnerArgs<World>): Promise<StepRunResult> => { | ||
if (!/^I have a Webhook Receiver$/.test(step.title)) return noMatch | ||
log.progress(`Webhook queue: ${webhookQueue}`) | ||
r = new WebhookReceiver({ queueUrl: webhookQueue }) | ||
await r.clearQueue() | ||
{ | ||
match: (title) => /^I have a Webhook Receiver$/.test(title), | ||
run: async ({ log, context: { webhookQueue } }) => { | ||
log.progress(`Webhook queue: ${webhookQueue}`) | ||
r = new WebhookReceiver({ queueUrl: webhookQueue }) | ||
await r.clearQueue() | ||
}, | ||
}, | ||
async ({ | ||
step, | ||
log: { scenario: log }, | ||
}: StepRunnerArgs<World>): Promise<StepRunResult> => { | ||
const match = | ||
/^the Webhook Receiver `(?<MessageGroupId>[^"]+)` should be called$/.exec( | ||
step.title, | ||
groupMatcher( | ||
{ | ||
regExp: | ||
/^the Webhook Receiver `(?<MessageGroupId>[^"]+)` should be called$/, | ||
schema: Type.Object({ MessageGroupId: Type.String() }), | ||
}, | ||
async ({ match: { MessageGroupId }, log }) => { | ||
await r.receiveWebhookRequest(MessageGroupId, log) | ||
}, | ||
), | ||
{ | ||
match: (title) => | ||
/^the webhook request body should equal this JSON$/.test(title), | ||
run: async ({ step }) => { | ||
assert.deepEqual( | ||
JSON.parse(codeBlockOrThrow(step).code), | ||
r.latestWebhookRequest?.body, | ||
) | ||
if (match === null) return noMatch | ||
|
||
const request = await r.receiveWebhookRequest( | ||
match.groups?.MessageGroupId as string, | ||
log, | ||
) | ||
|
||
return { result: request.body } | ||
}, | ||
async ({ step }: StepRunnerArgs<World>): Promise<StepRunResult> => { | ||
if (!/^the webhook request body should equal this JSON$/.test(step.title)) | ||
return noMatch | ||
|
||
assert.deepEqual( | ||
JSON.parse(codeBlockOrThrow(step).code), | ||
r.latestWebhookRequest?.body, | ||
) | ||
}, | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters