packages/engine/testSpecRender
the ONE renderer of a generated spec's executable part, shared by the generator and the step editor (testSteps.mjs), so a step document and its Playwright file can never drift apart: the generator builds steps from a...
Engine, v0.9. Source: packages/engine/testSpecRender.mjs.
Variables#
HELPERS#
constHELPERS: "const harness = (selector: string, why: string) =>\n new Error(\n `Test harness problem, not a bug in the page: the test harness expected ${selector}. ` +\n `${why} Construct binds workflow events to elements by convention (data-testid = the event name in kebab-case; ` +\n `data-flow / data-flow-state on the element that shows the machine's state). ` +\n `Add the attribute (or scaffold the page with \`construct create page --from\`); do not file a product bug for this.`,\n );\n\nasync function required(page: Page, selector: string, why: string) {\n const el = page.locator(selector).first();\n try {\n await el.waitFor({ state: 'attached', timeout: 5_000 });\n } catch {\n throw harness(selector, why);\n }\n return el;\n}\n\nasync function trigger(page: Page, testId: string, event: string) {\n const el = await required(page, `[data-testid="${testId}"]`, `It is what the workflow event ${event} binds to.`);\n await el.click();\n}\n\nasync function expectFlowState(page: Page, machine: string, state: string, timeout = 5_000) {\n const el = await required(page, `[data-flow="${machine}"][data-flow-state]`, `It shows the state of the ${machine} workflow.`);\n await expect(el).toHaveAttribute('data-flow-state', state, { timeout });\n}"
Defined in: packages/engine/testSpecRender.mjs:16
Functions#
comment()#
comment(
s):string
Defined in: packages/engine/testSpecRender.mjs:14
Text for a // comment: control characters and every JS line terminator become spaces.
Parameters#
s
any
Returns#
string
lit()#
lit(
s):string
Defined in: packages/engine/testSpecRender.mjs:12
A JS/TS string literal for arbitrary text: JSON-escaped, plus the two line separators JSON leaves raw.
Parameters#
s
any
Returns#
string
machineLine()#
machineLine(
key):string
Defined in: packages/engine/testSpecRender.mjs:46
Parameters#
key
any
Returns#
string
startUrlLine()#
startUrlLine(
url):string
Defined in: packages/engine/testSpecRender.mjs:45
const START_URL ...; for a start URL (or null: no route reaches the feature).
Parameters#
url
any
Returns#
string
stepLines()#
stepLines(
step):string[]
Defined in: packages/engine/testSpecRender.mjs:56
The lines of ONE step of a test body. Step kinds (the whole vocabulary the editor can read back):
fixme { text } test.fixme(true, "...") (what the test needs; from the generator)
goto { url } the guard + page.goto(START_URL); url lives in START_URL
state { state, timeout?, note? } the flow shows this state
event { event, testId, note? } a user event: click what data-testid binds to
check-text { text, timeout, note? } the page shows this text (an assertion: CHECK)
Parameters#
step
any
Returns#
string[]
testBlockLines()#
testBlockLines(
title,steps):any[]
Defined in: packages/engine/testSpecRender.mjs:69
test("title", async ({ page }) => { ...steps }); as lines.
Parameters#
title
any
steps
any
Returns#
any[]