Testing
Every flow is already a test. waygraph test plays them all through Playwright's runner, with no spec files to write. (A project with no flows, or one that names a spec file or passes --specs, runs its Playwright specs instead; --flows still says "the flows" outright.)
Commands
| Want | Command |
|---|---|
| every flow as a test | npx waygraph test |
| some of them | npx waygraph test --flows -g checkout (matches file or export name) |
| a group of them | npx waygraph test --flows --label auth (the config's labels; --label auth,smoke for either) |
| in parallel, with retries | npx waygraph test --flows --workers 4 --retries 2 |
| your own Playwright specs | npx waygraph test --specs (or name one: waygraph test tests/a.spec.ts; the rest goes to playwright test) |
| Playwright's UI mode | npx waygraph test ui |
| the last report | npx waygraph test report |
| one trace | npx waygraph test show-trace <trace.zip> |
| another environment | npx waygraph test --flows --env staging (loads .env.staging) |
Traces are kept for failures and the HTML report is on by default. Settings come from config/waygraph.config.ts (playwright: { workers, timeout, use }): Config.
Labels
A label groups flows, so a group runs on its own. The config declares every label there is, as a list, and a flow carries its own on map({ labels }); a flow can have several:
// config/waygraph.config.ts
labels: ["auth", "smoke", "empty-db"],
// a flow
engine.map({ title: "Sign in", labels: ["auth", "smoke"] }) // completes auth | smoke | empty-dbThe labels are typed from the config: new Engine(config) makes map({ labels }) and regression accept only the declared names, so your editor completes them and a typo ("smok") is a type error. Without labels in the config, any string is accepted, as before.
A label that needs more than its name is an object in the same list: flows puts the label on flows from the config instead of from each flow (a glob over their files, or a flow's export name), and description says what it means (waygraph info shows it). A flow can still carry the label itself; both count, once.
labels: ["smoke", "empty-db", { name: "auth", flows: ["src/flows/auth/**", "logoutFlow"], description: "sign in and out" }],npx waygraph test --flows --label auth # the auth flows
npx waygraph list --label auth # which ones they areEach flow's test is tagged with its labels (@auth), so Playwright's UI mode and its reports filter by them too, and the manifest and Waygraph Studio's Flows page show them. waygraph check warns about a label that covers no flow.
A flow can also name its own labels, next to its title and description: engine.map({ title, description, labels: ["smoke"] }). They join the config's, once each, so --label finds a flow by either.
Regression: which flows the full run plays
waygraph test plays every flow, labelled or not. Some flows can't be green on a shared environment such as staging: they need an empty database, rows seeded by hand, or any other precondition the environment doesn't promise. Declare the labels in the config, label the flows, and tell the regression what to leave out, or what to keep:
// config/waygraph.config.ts
labels: ["empty-db", "db-seed", "smoke", "auth"],
regression: { exclude: ["empty-db", "db-seed"] }, // completes the declared labels
// src/flows/onboarding/signup.flow.ts
export const signupFlow = engine.map({ title: "Sign up a new tenant", labels: ["empty-db"] }).gotoPage(…)A set has two lists, both optional: include keeps only flows carrying one of its labels, then exclude drops flows carrying one of its (exclude wins). A flow with no label is in a set with no include. Name several sets to have a run per environment; default is the one a bare run uses:
regression: {
default: { exclude: ["empty-db", "db-seed"] },
staging: { exclude: ["empty-db", "db-seed", "destructive"] },
nightly: { include: ["auth", "checkout"], exclude: ["flaky"] },
},npx waygraph test # the default set: the regression, expected green
npx waygraph test --regression nightly # another set (WAYGRAPH_REGRESSION=nightly for CI)
npx waygraph test --include smoke # for this run only: replace the set's include
npx waygraph test --exclude flaky,slow # for this run only: replace the set's exclude
npx waygraph test --label empty-db # run a label's flows (picking a label always plays them)
npx waygraph test --all # everything, whatever the set leaves out- Nothing set, nothing changes: with no
regressionkey every flow runs, as before. - Skipped, not hidden: a flow the set leaves out is listed as skipped, with why and how to run it;
waygraph list, the manifest and Waygraph Studio's Flows page mark it ("left out of the full run"). - Any pick plays them:
--label,--grepand--allrun the flow whatever the set says;--grep-invertalone doesn't, since nothing was picked. - Typed and checked: the label names are completed in the editor and a typo is a type error;
--regressionnames a set that exists or the run stops, listing them;waygraph checkwarns about a label a set names that no flow carries.
This is what makes a label more than a tag: it says what a flow needs, and the full run only claims what the environment can deliver.
Which flows run, and how
| A flow that... | Gets |
|---|---|
has map({ device }) | that device's size (the config's device sets every test's browser: size, phone layout, touch) |
| needs a key a mem stub supplies | the stub's value |
| needs a key nothing supplies | skipped, with the key named |
| starts on a page it doesn't open (an episode meant to follow another) | skipped, with the reason |
has map({ exclusive: true }) | runs alone, after all the others (it changes data the rest read); --label, --grep and --grep-invert pick among them too, without running the others first |
has map({ expectedFailure }) | passes when it fails |
is left out by the regression set (regression) | skipped in the full run, with why and how to run it (Regression) |
Access tests
When the project says who's given what (for, on layouts' links, Methods and Page Blocks), waygraph test --flows adds one test per account after the flows: access › planner, tagged @access @planner (so --grep @access runs only them). Signed in as the account, it opens a page each layout covers, by its address, and checks that the layout shows exactly the links the account is given: a link it's given that isn't showing fails it, and so does one it isn't given that shows (a menu that hides its links is opened first). Then it opens each page the account isn't given and expects it not to open. An account that can't sign in is skipped, saying why.
access as planner:
sidebar › reports shows, and planner isn't given it (#reports): add planner to its for, or hide itThe world a flow runs in
A flow can set its time zone and network, and gets them put back when it ends, pass or fail, so an outage test doesn't leave the next flow offline:
engine.map({ timezone: "Asia/Tokyo" }) // the page's clock (Chromium)
engine.map({ network: { throttle: "slow-3g" } }) // or "fast-3g", { latencyMs, downloadKbps, uploadKbps }
engine.map({ network: { throttle: "offline" } }) // every browser
engine.map({ network: { faults: [{ url: "**/api/orders", status: 503 }] } }) // or abort: true, delayMs: 3000A fault answers matching requests instead of the server (status, body), fails them (abort), or holds them first (delayMs).
Tests that share things
| Shared | Use |
|---|---|
| one mail inbox | claimOnce(name): true for the first caller on the machine, false after, so two workers never open the same email (Mail) |
| data one test creates | unique in its mem stubs (Data), and a .finally cleanup |
| a signed-in user | map({ as: Account }): signs in once per worker (Flows) |
In a spec of your own
A project that keeps its specs in Playwright Test can run a flow, or a few steps of one, from a test. The test's context (and its page, when it has one open) are the flow's: its fixtures, its baseURL and its saved session carry over.
import { test, expect } from "@playwright/test";
import { MemPage } from "waygraph";
import { engine } from "../config/waygraph.config.js";
import { LinesList } from "../src/map/(app)/lines/_page.block.js";
test("a name with markup is shown as text", async ({ page, context }) => {
await engine
.map()
.gotoPage(LinesList)
.method(LinesList.do.typeLinesSearch("<b>x</b>"), { // the value is a param, written on the step
settle: true,
expect: [LinesList.check("only lines named with the markup", ({ rows }) => rows.every((r) => r.name.includes("<b>x</b>")))],
})
.run(context, new MemPage(), { page });
await expect(page.locator("b")).toHaveCount(0); // Playwright's own expect, on the page the flow drove
});A flow written for waygraph test --flows runs the same way: await checkoutFlow.run(context, mem). Mem is for what a run carries (new MemPage().set(Keys.user, marco), or --data); a value only one step uses is a param of its Method.
Beyond the flows you wrote
| Command | Does |
|---|---|
npx waygraph traverse --parallel 4 --min-edge-coverage 80% | walks every edge of the Block graph, writes .waygraph-traverse/coverage.json, exits 2 below the gate |
npx waygraph run checkoutFlow --all-branches | plays every .branch() path |
WAYGRAPH_JSON=1 npx waygraph run checkoutFlow | one JSON report on stdout (steps, timings, a failure screenshot) |
In CI
- run: npm ci && npx waygraph install --with-deps # what the config requires, with the browsers' system packages
- run: npx waygraph check # warnings only
- run: npx waygraph map # exits 1 when a folder doesn't match its URL
- run: npx waygraph test --flows --workers 4 --reporter=html,jsonEvery run also leaves .waygraph/runs/<runId>.jsonl (one event per line), worth keeping as an artifact: a failed check's wanted / saw is on its step:error.