feat(run): add test.info(), testInfo/workerInfo, and annotations (ENG-1233)

OK
14h ago
+3515-520

What

Adds test.info(), the testInfo / workerInfo arguments on tests, hooks, and fixtures, TEST_WORKER_INDEX / TEST_PARALLEL_INDEX worker environment variables, per-attempt outputDir / outputPath, live teardown status / error / errors / expectedStatus, and static + runtime test annotations across reports.

import { writeFileSync } from 'node:fs';
import { test as base } from '@e2e-dev/web';

const test = base.extend<{ logFile: string }>({
  logFile: async ({}, use, testInfo) => {
    const file = testInfo.outputPath('fixture.log');
    writeFileSync(file, `started ${testInfo.title} (timeout ${testInfo.timeout}ms)\n`);
    await use(file);
    writeFileSync(file, `finished status=${testInfo.status} expected=${testInfo.expectedStatus}\n`);
  },
});

test('checkout', { annotation: { type: 'issue', description: 'https://github.com/e2e-inc/e2e/issues/1233' } }, async ({ app, logFile }, testInfo) => {
  testInfo.annotations.push({ type: 'worker', description: String(testInfo.parallelIndex) });
  await app.open('/checkout');
});
  • Tests, test.setup, test.each, test.for, beforeEach, afterEach, and test-scoped fixtures receive TestInfo (and can call test.info()): testId, title, titlePath, file, line, column, tags, agent, target, config, retry, repeatEachIndex, workerIndex, parallelIndex, timeout, duration, expectedStatus, status, error, errors, annotations, outputDir, and outputPath(...segments).
  • beforeAll, afterAll, and worker-scoped fixtures receive WorkerInfo (workerIndex, parallelIndex, target, config).
  • process.env.TEST_WORKER_INDEX and process.env.TEST_PARALLEL_INDEX are set for every child-process and in-process worker.
  • Static { annotation } options on describe, test, and test.setup, plus runtime entries pushed to testInfo.annotations, are secret-redacted and written to report.json, JUnit <properties>, CTRF, Markdown, trace.md, list, and report.html.

Why

Teams migrating from Playwright, Cypress, and Selenium hit missing TestInfo primitives: fixtures could not write per-test logs next to test artifacts (outputDir / outputPath), afterEach and fixture teardowns could not tell whether a test passed, failed, or timed out, tests could not partition resources by worker index or inspect retries, and tests could not attach annotations such as issue links to reports.

How it works

  1. Public types and core helpers (packages/core/src/types.ts, packages/core/src/types/fixtures.ts, packages/core/src/internal/test-info.ts, packages/core/src/expect/attempt.ts): defines WorkerInfo, TestInfo, TestAnnotation, TestInfoError, TestInfoStatus, TestTargetInfo, and TestConfigInfo; extends TestFn, SetupFn, TestHookFn, EachArgs, FixtureFn, and TestAPI.info(). currentTestInfo() reads PublishedAttempt.testInfo and refuses calls outside a running test, from work a test left running such as a body past its timeout (leftRunning(), CANCELLED, as test.step() does), in suite hooks (runningSuiteHook()), in worker-scoped fixtures (outlivesTest()), and in hosted sessions without a running test. FixtureFn and TestHookFn default their info type to WorkerInfo, so one written without it fits test and worker slots alike; TestFn and SetupFn take a required TestInfo, which the changeset marks Breaking: (minor). resolveOutputPath() blocks path traversal outside outputDir; sanitizeAnnotations() redacts before truncating to report-1 bounds.
  2. Option validation and annotation collection (packages/e2e/src/collect/validate-options.ts, packages/e2e/src/collect/registry.ts, packages/e2e/src/collect/collect.ts): extracts option key tables and validators out of registry.ts into validate-options.ts (bringing registry.ts from 1007 to 817 lines), validates { annotation } on describe, test, and test.setup, concatenates annotations outermost-first with static secret redaction, and forwards testInfo through test.each / test.for.
  3. Worker indices and env vars (packages/e2e/src/run/unit-runner.ts, packages/e2e/src/run/scheduler.ts, packages/e2e/src/run/worker/protocol.ts, packages/e2e/src/run/worker/handle.ts, packages/e2e/src/run/worker/entry.ts, packages/e2e/src/run/worker/session.ts, packages/e2e/src/run/in-process.ts, packages/e2e/src/run/standalone-kinds.ts): Scheduler.spawn() assigns a monotonic workerIndex per spawned worker and a globally unique reusable parallelIndex (0..workers - 1) across all live workers. Both child-process workers and InProcessRunner expose TEST_WORKER_INDEX and TEST_PARALLEL_INDEX. Two programmatic runs in one process may both be live; process.env then names the newest live in-process runner's slots and gets its previous values back when the last ends, while testInfo keeps each attempt's own. Workers carry these as one WorkerSlots value from the scheduler to the executor. Hosted sessions are worker 0, parallel slot 0.
  4. Attempt lifecycle and fixture delivery (packages/e2e/src/run/attempt-verdict.ts, packages/e2e/src/run/execute.ts, packages/e2e/src/run/standalone-test.ts, packages/e2e/src/run/fixture-pool.ts, packages/e2e/src/run/suite-attempt.ts, packages/e2e/src/run/serial.ts): Both TargetExecutor and session tests (open_session {test}) record failures, skips, and timeouts into one AttemptVerdict; the attempt record and the live TestInfo (status, redacted error/errors, expectedStatus) both read it, so an afterEach failure shows in a later afterEach and in fixture teardown. testInfo.error is the verdict's error only; errors adds the ones kept beside it. testInfo.file, line, and column come from the declaration site, which may be a module the test file imports. A serial member's outputDir is a directory of its own inside the group attempt's. bindFixtures<Info> passes TestInfo to tests, beforeEach/afterEach, and test fixtures, and WorkerInfo to beforeAll/afterAll and worker fixtures. executeAttempt() redacts and records annotations before closing the session, and serial.ts copies them onto SerialMemberRecord. A session test writes no report-1 document; open_session prints its annotations (Annotations: issue: https://... · retry: 0).
  5. Wire schema and reporters (packages/e2e/schema/report-v1.schema.json, packages/e2e/schema/fixtures/report-v1.{valid,invalid}.json, packages/e2e/src/report/{build,outcome,junit,ctrf,failure-text,markdown,list,list-model}.ts, packages/html-reporter/app/{data.ts,test.tsx}): adds optional annotations on attempt, serialMember, and result in report-1. result.annotations holds the verdict attempt's annotations (verdictAttempt(): the last attempt the run did not interrupt), falling back to declared annotations only when no attempt ran. Attempts the scheduler synthesizes for a worker crash, a watchdog kill, or an app exit carry the declared annotations. JUnit emits <properties><property name value/></properties>, CTRF writes extra['e2e-inc.e2e'].annotations, Markdown and trace.md list them, list prints dim type: description glance lines (an empty description is dropped; a serial member that skipped itself shows what it pushed), and the HTML report renders them in TestView (linking only http(s) URLs).
  6. Docs, skill, plugin, changeset (docs/reference/test.mdx, docs/migrate/{playwright,cypress,selenium}.mdx, skills/e2e/references/writing-tests.md, plugins/e2e/, .changeset/test-info.md): documents test.info(), TestInfo, WorkerInfo, { annotation }, and TEST_WORKER_INDEX / TEST_PARALLEL_INDEX, the testInfo argument of test.each / test.for, and the annotation output of list, junit, markdown, and ctrf in docs/reference/reporters.mdx, and moves the gap out of Playwright's "What e2e doesn't have yet" table.

Verified

Ran it locally: yes

  • Scratch project with the built CLI (node packages/e2e/dist/cli/bin.js run) exercising test.info(), a test-scoped fixture writing via testInfo.outputPath(), TEST_WORKER_INDEX / TEST_PARALLEL_INDEX, static + runtime annotations, and list, junit, ctrf, markdown, htmlReporter(), and trace: 'on':
 RUN  e2e v0.25.0 /private/var/folders/c2/by_p5dmd3zj0mk_xfstbj69r0000gn/T/e2e-testinfo-verify-h4sDyO
      run 01a2179b-b959-7d89-b272-82760d9edb08 · targets: local

   ✓ |local| tests/demo.e2e.ts > billing > annotated checkout 3ms
     → area: payments
     → issue: https://github.com/e2e-inc/e2e/issues/1233
     → worker: idx=0
 ✓ |local| tests/demo.e2e.ts (1 test) 3ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  12:26:51
   Duration  139ms
     Traces  .e2e/results/ (1 page, trace.md in each test's directory)

      JUnit  .e2e/junit.xml
       CTRF  .e2e/ctrf.json
   Markdown  .e2e/summary.md
HTML report  .e2e/report.html
<testcase name="billing &gt; annotated checkout [local]" classname="tests/demo.e2e.ts" time="0.003">
  <properties>
    <property name="area" value="payments"/>
    <property name="issue" value="https://github.com/e2e-inc/e2e/issues/1233"/>
    <property name="worker" value="idx=0"/>
  </properties>
</testcase>
  • Testbed (pnpm --filter @e2e-dev/testbed exec e2e run tests/todos.e2e.ts): 7/7 passed against live Chromium with built packages.
  • Testbed scratch file, built CLI, live Chromium: runtime annotations, test.info() inside test.step, and a later afterEach seeing an earlier one's failure:
afterEach-later sees passed  worker=0/0
   ✓ |web| tests/zz-info-verify.e2e.ts > info verify > carries annotations 519ms
     → area: todos
     → issue: https://example.com/1233
     → retry: 0
     → empty
afterEach-later sees failed ERROR@afterEach worker=0/0
   × |web| tests/zz-info-verify.e2e.ts > info verify > passes then teardown fails 179ms
     → area: todos
     → teardown boom
  • open_session {test} over the built CLI and a real MCP client (tests/integration/mcp-test-run.test.ts): prints the annotations, keeps testInfo.duration running through teardown, and a teardown failure turns status to failed for the next afterEach. Confirmed this case fails if teardown failures do not reach the verdict.
  • Review fixes, built CLI on the testbed (live Chromium): a body past its timeout gets CANCELLED from test.info() and leaves the next test's annotations alone, serial members write log.txt into their own directories, a test declared in an imported module reports that module, and a worker that exits mid-test keeps its declared annotation in list, report.json, and JUnit:
   × |web| tests/zz-verify-2308.e2e.ts > late > first times out (timed-out) 515ms
   ✓ |web| tests/zz-verify-2308.e2e.ts > late > second 278ms
   ✓ |web| tests/zz-verify-2308.e2e.ts > flow > one 54ms
     → flow: wizard
   ↓ |web| tests/zz-verify-2308.e2e.ts > flow > two skips itself [not today]
     → flow: wizard
     → pushed: before-skip
   × |web| tests/zz-verify-2308.e2e.ts > crashes 0ms
     → issue: https://example.com/1
     → worker process exited during this test
declared file=tests/zz/declared.ts:5
late test.info(): CANCELLED
serial one outputDir=.e2e/results/zz-verify-2308-flow-49dfaf4d6033dd5b/attempt-1/zz-verify-2308-flow-one-04d6b43ee0fb0d32
serial two outputDir=.e2e/results/zz-verify-2308-flow-49dfaf4d6033dd5b/attempt-1/zz-verify-2308-flow-two-skips-itself-bab06161075015ea
  • Each review fix has a regression test (tests/integration/test-info-edges.test.ts, tests/unit/{attempt-verdict,report-status,test-info}.test.ts, tests/types/sdk-types.ts) that fails with the fix reverted.
  • pnpm bench:ab and terminal GIF recording: not captured locally for this feature PR; list output for tests without annotations is unchanged.

Summary by CodeRabbit

  • New Features

    • Added test and worker information APIs for accessing status, timing, errors, configuration, and output paths in tests, hooks, and fixtures.
    • Test and setup callbacks now receive test information; suite hooks and worker fixtures receive worker information.
    • Added test annotations, including inherited annotations and redaction of sensitive text.
    • Annotations now appear in reports and test outcome summaries.
    • Added worker and parallel index environment variables.
  • Documentation

    • Expanded API and migration guides with test information and annotation usage and reporting details.