docs(core): say where test.step records no step

Merged
LE
3d ago
+17-6

What

  • The test.step() doc comment and reference entry now say that in a beforeAll or afterAll hook, a worker fixture, or an openHost() session, body just runs, and no report gets a step for title. A call from work its phase left running (a body or hook past its timeout) is CANCELLED, and any other call outside these, such as one at collection, is COLLECTION_ERROR.

Why

  • The comment said reports show the title wherever the call is allowed, and "Outside a test the call is COLLECTION_ERROR", which reads as if a beforeAll hook (not a test) throws. In fact runTestStep just runs the body there (packages/core/src/internal/test-step.ts:30), and in a hosted session, whose attempt has no step recorder (test-step.ts:35). This was the cubic thread on #2381.
  • The prose entry on docs/reference/test.mdx already covered suite hooks, but not worker fixtures or openHost().

How it works

  1. packages/core/src/types.ts:1149-1154: the closing paragraph of the TestAPI.step comment. Since #2448 the TestAPI block in docs/reference/test.mdx has no doc comments, so there is no mirrored copy.
  2. docs/reference/test.mdx:401-405: the test.step bullet adds worker fixtures and openHost() sessions, and the next bullet now limits the STEP_NOT_AWAITED failure around use() to test-scoped fixtures. The Throws table gets a CANCELLED row (test.mdx:415, from leftRunning() at test-step.ts:24-27), and the COLLECTION_ERROR row (test.mdx:416) names openHost() sessions.
  3. .changeset/document-test-step-in-suite-hooks.md is a @e2e-dev/core patch.

Issue

Docs-only change, no issue.

Verified

Ran it locally: yes

  • pnpm check passes. pnpm test passes except one timing test, host-libraries.test.ts "kills an ldd that outlives its time", which failed once under the full run and passes when rerun alone. This change touches no code.
  • I checked the hook and worker-fixture claim with a throwaway run (not committed) through the runProject helper used by tests/integration/test-step.test.ts. A worker fixture, a test fixture and a beforeAll hook each call test.step, and the test checks that all three bodies ran. It passes, and its report has only the test fixture's step:
status: passed
steps (kind "step"): [["Test fixture setup", "beforeEach", "passed"]]
  • The hosted-session case is the existing unit test "just runs the body where the attempt records no steps" (packages/e2e/tests/unit/test-step.test.ts:384). The step tests still pass:
$ npx vitest run tests/integration/test-step.test.ts tests/unit/test-step.test.ts
 Test Files  2 passed (2)
      Tests  34 passed (34)
  • The CANCELLED case: two more throwaway runProject runs call test.step after the phase timed out, once from a test body (timeout: 300, step at 700 ms) and once from a beforeEach hook. Both catch:
{"code":"CANCELLED","message":"test.step() was called after its test ended"}
  • use() inside test.step: a throwaway runProject probe shows the test passes for a worker fixture, and fails with STEP_NOT_AWAITED for a test-scoped fixture.
  • No screenshot: only comment and reference text change.

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/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

Summary by CodeRabbit

  • Documentation
    • Clarified that test.step() calls in setup and teardown hooks, worker fixtures, and openHost() sessions run but don’t appear in reports.
    • Documented that calls from work continuing after its phase ends are reported as CANCELLED. Other out-of-scope calls, except those in openHost() sessions, are reported as COLLECTION_ERROR.
    • Noted that wrapping use() in a test-scoped fixture fails with STEP_NOT_AWAITED.