feat(test): name a group of calls with test.step (ENG-1528)
What
test.step(title, fn) runs a function as one named step and returns what it returns. Reports show the title with the calls made inside it nested under it, and steps nest.
await test.step('Log in as test user', async () => {
await screen.getByTestId('login_button').tap();
});
- It works in a test body,
beforeEach,afterEach, and a fixture (before or afteruse(), not around it). InbeforeAll,afterAll, and a hosted session the function runs and nothing is recorded. - A call that fails inside fails the step, and the error stays on the call. The step keeps an error only when its own body threw one.
test.skip()inside a step skips the test and the step passes. A failedexpect.softinside does not fail the step.report.jsongets step kindstep(apitest.step) andparenton each step inside one. Step progress getsidentity.parentStepId. CTRF getsextra.parent. Telemetry countssteps_step.
Why
A Maestro flow can put a label on any command, and the CLI and reports show it in place of the generated description. e2e had no way to name part of a test: the migrate guide told Maestro users "the call names each step" and listed Playwright's test.step as planned. One API covers both.
How it works
test.stepisrunTestStep(packages/core/src/internal/test-step.ts:13). It validates the arguments, runs the body bare in a suite hook or a hosted session, and otherwise calls the published attempt'sstep, which the runner builds withattemptStep(packages/e2e/src/internal/skip.ts:62).StepRecorder.group(packages/core/src/run/steps.ts:681) opens a record of kindstepand runs the body in a secondAsyncLocalStorage, apart from the one that marks a running call. A call inside atest.stepis therefore still a top-level call:--stepholds it, and a passed assertion still confirms the steps before it. Thetest.stepitself is never held.- Each step is opened with the
test.steparound it (enclosingGroup(packages/core/src/run/steps.ts:1283)), which becomesStepRecord.parent. A held call keeps it, so a call recorded later from outside the body still has its parent. - A failed call adds what it throws to its group's
rethrownset (packages/core/src/run/steps.ts:965).executeGroup(packages/core/src/run/steps.ts:709) records an error only for a throw that is not in the set, so one failure is one error in the report. The same error thrown again from a latertest.stepis recorded there. - The group is cut by the attempt's phase signal as well as by what cuts any step, because its body can wait on something no engine call ends. Each
test.steptracks the calls running in it, alaunch()session's included (runsInside,packages/core/src/run/steps.ts:764), and ends after them (cutAfterCallsInside,packages/core/src/run/steps.ts:748), so a timeout records them as cancelled and not as calls the test did not await. It records the cancellation itself only when no call inside did. A runtime skip passes through and leaves the step passed. Before it records what its body threw it refreshes the provider keys, as every other step does. - A
test.stepcalled by a body its test left running (past its timeout) is cancelled (packages/core/src/internal/test-step.ts:24). It would otherwise be recorded on the test that runs then. In a worker fixture the function runs unrecorded. - A
test.stepowns no app events or artifacts (lastOwn(packages/core/src/run/steps.ts:1267)) and is left out of the prior steps an agent step is told, so prompts do not change. - List reporter:
StepCall(packages/e2e/src/report/list-model.ts:23) carries a tree path (attempt index, the indexes of thetest.stepcalls around the step, its own).listStep(packages/e2e/src/report/list-model.ts:124) inserts by path, so steps stay under theirtest.stepwhen two run side by side or a retry overlaps. A step an earlier attempt left open stays known, so its late end lands under itstest.step, and atest.stepwhose end never came is still listed above its steps. A runningtest.stepis listed at its start and replaced when it ends. OnestepLine(packages/e2e/src/report/list-steps.ts:75) draws every row. A finished test keeps only its agent steps, atest.stepthat did not pass, and thetest.stepcalls around either (recordedSteps), so a green file of plain calls stays one line. Without a live window only an agent step prints as it ends, namedtest > step > call. - Trace page and MCP outcome keep flat numbers and mark nesting with
↳(nestingMarks(packages/e2e/src/report/failure-text.ts:100)). The failure summary readsat step 4 of 6 in "Log in": .... The HTML report indents rows and shows atest.stepas its title. - The standalone verdict takes the first failed step that has an error (
packages/core/src/run/standalone-attempt.ts:231), since a failedtest.stepcomes before the call that failed in it and has none.
Dropped: a label option on every action. It would touch every options type and add one to calls that take none.
Reviewed in three rounds by fresh-context subagents (structure, bugs, then runtime and reporting halves). Declined:
- Moving the group path out of
steps.ts: it needs the recorder's privateopen,active, andpublishEnd. The file was 1146 lines before this PR. - One spelling for
parentandparentStepId: the record uses a step index like the app log does, progress uses an id likestepId. - A fixture wrapping
use()in atest.step: it fails withSTEP_NOT_AWAITEDand a hint that says so. Keeping a step open across the fixture boundary is a larger change. Documented. - Failing the step on a soft failure inside it. Documented.
Issue
ENG-1528
Verified
Ran it locally: yes
Built CLI on the testbed, node node_modules/e2e/dist/cli/bin.js run tests/step.e2e.ts, without a live window. A green run prints no test.step line:
✓ |web| tests/step.e2e.ts > test.step > names a group of calls and returns what its body returns 300ms
✓ |web| tests/step.e2e.ts > test.step > passes the error of a failed call on to the test 258ms
✓ |web| tests/step.e2e.ts (2 tests) 558ms
With a live window (same run under script), the steps show while the test runs:
◌ Add two todos
✓ Add "Write spec" 60ms
◌ Add "Ship runner"
The file block then keeps only the step that failed (the test catches it):
✓ web tests/step.e2e.ts (2 tests) 590ms
× Tap a button that is not there 206ms failed
trace.md of a scratch test that fails inside a step:
1. ✓ `test.step` "Open the todos page" (57ms)
2. ✓ ↳ `app.open` `/todos` (56ms)
3. ✓ `test.step` "Add two todos" (78ms)
4. ✓ ↳ `test.step` "Add "Write spec"" (59ms)
5. ✓ ↳ ↳ `locator.fill` `getByLabel("New todo")` (47ms)
- The recording below is the live window on that scratch test. No
mainside: nothing printed for these rows before. - HTML report of the same run:
pnpm lint,pnpm typecheck, the e2e suite (6481 passed), and the testbed step test are green on the head. The whole testbed suite (634 passed) ran before the last two commits. A realreport.jsonvalidates against the schema intests/integration/test-step.test.ts.- No
bench:abtable: a step now does oneAsyncLocalStorageread at start, and nothing else on the path of a test withouttest.step.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.
https://github.com/user-attachments/assets/4937539e-6c62-487a-8b64-b21f0da8e05a