Skip to content

Commit 71b6c39

Browse files
pudkrongcoderbyheart
authored andcommitted
fix: update BDD Markdown to v6 (#263)
1 parent 1bfbef9 commit 71b6c39

21 files changed

+2377
-8036
lines changed

feature-runner/lib/websocket.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import WebSocket from 'ws'
22
import { ulid } from '../../util/ulid.js'
33

44
export type WebSocketClient = {
5+
id: string
56
connect: () => Promise<any>
67
close: () => void
78
send: (message: Record<string, unknown>) => Promise<void>
@@ -20,8 +21,9 @@ export const createWebsocketClient = ({
2021
}): WebSocketClient => {
2122
if (clients[id] === undefined) {
2223
const client = new WebSocket(url)
23-
const messages: Record<string, unknown> = {}
24+
const messages: Record<string, unknown> = {} as const
2425
clients[id] = {
26+
id,
2527
connect: async () =>
2628
new Promise<void>((resolve, reject) =>
2729
client
@@ -33,7 +35,7 @@ export const createWebsocketClient = ({
3335
})
3436
.on('message', async (msg) => {
3537
const message = JSON.parse(msg.toString())
36-
debug?.(msg.toString())
38+
debug?.('<< ' + msg.toString())
3739
messages[ulid()] = message
3840
}),
3941
),
@@ -44,8 +46,10 @@ export const createWebsocketClient = ({
4446
messages,
4547
send: async (message) =>
4648
new Promise<void>((resolve, reject) => {
47-
client.send(JSON.stringify(message), (error) => {
49+
const strMessage = JSON.stringify(message)
50+
client.send(strMessage, (error) => {
4851
if (error) return reject(error)
52+
debug?.('>> ' + strMessage)
4953
resolve()
5054
})
5155
}),

feature-runner/run-features.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,30 @@ const runner = await runFolder({
9191
onDebug: (info, ...args) =>
9292
console.error(
9393
ts(),
94-
chalk.magenta.dim(info.context.keyword),
95-
chalk.magenta(info.context.title),
94+
chalk.magenta.dim(info.step.keyword),
95+
chalk.magenta(info.step.title),
9696
...args.map((arg) => chalk.cyan(print(arg))),
9797
),
9898
onError: (info, ...args) =>
9999
console.error(
100100
ts(),
101-
chalk.magenta.dim(info.context.keyword),
102-
chalk.magenta(info.context.title),
103-
...args.map((arg) => chalk.red(print(arg))),
101+
chalk.magenta.dim(info.step.keyword),
102+
chalk.magenta(info.step.title),
103+
...args.map((arg) => chalk.cyan(print(arg))),
104104
),
105105
onInfo: (info, ...args) =>
106106
console.error(
107107
ts(),
108-
chalk.magenta.dim(info.context.keyword),
109-
chalk.magenta(info.context.title),
110-
...args.map((arg) => chalk.green(print(arg))),
108+
chalk.magenta.dim(info.step.keyword),
109+
chalk.magenta(info.step.title),
110+
...args.map((arg) => chalk.cyan(print(arg))),
111111
),
112112
onProgress: (info, ...args) =>
113113
console.error(
114114
ts(),
115-
chalk.magenta.dim(info.context.keyword),
116-
chalk.magenta(info.context.title),
117-
...args.map((arg) => chalk.yellow(print(arg))),
115+
chalk.magenta.dim(info.step.keyword),
116+
chalk.magenta(info.step.title),
117+
...args.map((arg) => chalk.cyan(print(arg))),
118118
),
119119
},
120120
})

feature-runner/steps/config.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import {
2-
matchGroups,
3-
noMatch,
4-
type StepRunResult,
52
type StepRunner,
6-
type StepRunnerArgs,
3+
regExpMatchedStep,
74
} from '@nordicsemiconductor/bdd-markdown'
85
import { Type } from '@sinclair/typebox'
96
import { hashSHA1 } from '../../util/hashSHA1.js'
@@ -18,34 +15,24 @@ const createConfigStepRunners = ({
1815
}: {
1916
configWriter: ReturnType<typeof putSettings>
2017
}): StepRunner<Record<string, any>>[] => {
21-
const setupDeviceShadowFetchingConfiguration = async ({
22-
step,
23-
log: {
24-
step: { progress },
25-
},
26-
}: StepRunnerArgs<Record<string, any>>): Promise<StepRunResult> => {
27-
const match = matchGroups(
28-
Type.Object({
18+
const setupDeviceShadowFetchingConfiguration = regExpMatchedStep(
19+
{
20+
regExp:
21+
/^device shadow fetching config for model `(?<model>[^`]+)` is `(?<interval>[^`]+)`$/,
22+
schema: Type.Object({
2923
model: Type.String(),
3024
interval: Type.Integer(),
3125
}),
32-
{
26+
converters: {
3327
interval: (s) => parseInt(s, 10),
3428
},
35-
)(
36-
/^device shadow fetching config for model `(?<model>[^`]+)` is `(?<interval>[^`]+)`$/,
37-
step.title,
38-
)
39-
40-
if (match === null) return noMatch
41-
42-
// ssm path must be letter, number, .(dot), -(dash), or _(underscore)
43-
const model = hashSHA1(match.model)
44-
const interval = match.interval
45-
46-
progress(`Set fetching interval for ${model} as ${interval} seconds`)
47-
await configWriter({ property: model, value: `${interval}` })
48-
}
29+
},
30+
async ({ match: { model, interval }, log: { progress } }) => {
31+
const modelHash = hashSHA1(model)
32+
progress(`Set fetching interval for ${modelHash} as ${interval} seconds`)
33+
await configWriter({ property: modelHash, value: `${interval}` })
34+
},
35+
)
4936

5037
return [setupDeviceShadowFetchingConfiguration]
5138
}

0 commit comments

Comments
 (0)