feat(run): add test.info(), testInfo/workerInfo, and annotations (ENG-1233)
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 receiveTestInfo(and can calltest.info()):testId,title,titlePath,file,line,column,tags,agent,target,config,retry,repeatEachIndex,workerIndex,parallelIndex,timeout,duration,expectedStatus,status,error,errors,annotations,outputDir, andoutputPath(...segments). beforeAll,afterAll, and worker-scoped fixtures receiveWorkerInfo(workerIndex,parallelIndex,target,config).process.env.TEST_WORKER_INDEXandprocess.env.TEST_PARALLEL_INDEXare set for every child-process and in-process worker.- Static
{ annotation }options ondescribe,test, andtest.setup, plus runtime entries pushed totestInfo.annotations, are secret-redacted and written toreport.json, JUnit<properties>, CTRF, Markdown,trace.md,list, andreport.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
- 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): definesWorkerInfo,TestInfo,TestAnnotation,TestInfoError,TestInfoStatus,TestTargetInfo, andTestConfigInfo; extendsTestFn,SetupFn,TestHookFn,EachArgs,FixtureFn, andTestAPI.info().currentTestInfo()readsPublishedAttempt.testInfoand refuses calls outside a running test, from work a test left running such as a body past its timeout (leftRunning(),CANCELLED, astest.step()does), in suite hooks (runningSuiteHook()), in worker-scoped fixtures (outlivesTest()), and in hosted sessions without a running test.FixtureFnandTestHookFndefault their info type toWorkerInfo, so one written without it fits test and worker slots alike;TestFnandSetupFntake a requiredTestInfo, which the changeset marks Breaking: (minor).resolveOutputPath()blocks path traversal outsideoutputDir;sanitizeAnnotations()redacts before truncating to report-1 bounds. - 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 ofregistry.tsintovalidate-options.ts(bringingregistry.tsfrom 1007 to 817 lines), validates{ annotation }ondescribe,test, andtest.setup, concatenates annotations outermost-first with static secret redaction, and forwardstestInfothroughtest.each/test.for. - 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 monotonicworkerIndexper spawned worker and a globally unique reusableparallelIndex(0..workers - 1) across all live workers. Both child-process workers andInProcessRunnerexposeTEST_WORKER_INDEXandTEST_PARALLEL_INDEX. Two programmatic runs in one process may both be live;process.envthen names the newest live in-process runner's slots and gets its previous values back when the last ends, whiletestInfokeeps each attempt's own. Workers carry these as oneWorkerSlotsvalue from the scheduler to the executor. Hosted sessions are worker0, parallel slot0. - 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): BothTargetExecutorand session tests (open_session {test}) record failures, skips, and timeouts into oneAttemptVerdict; the attempt record and the liveTestInfo(status, redactederror/errors,expectedStatus) both read it, so anafterEachfailure shows in a laterafterEachand in fixture teardown.testInfo.erroris the verdict's error only;errorsadds the ones kept beside it.testInfo.file,line, andcolumncome from the declaration site, which may be a module the test file imports. A serial member'soutputDiris a directory of its own inside the group attempt's.bindFixtures<Info>passesTestInfoto tests,beforeEach/afterEach, and test fixtures, andWorkerInfotobeforeAll/afterAlland worker fixtures.executeAttempt()redacts and records annotations before closing the session, andserial.tscopies them ontoSerialMemberRecord. A session test writes no report-1 document;open_sessionprints its annotations (Annotations: issue: https://... · retry: 0). - 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 optionalannotationsonattempt,serialMember, andresultinreport-1.result.annotationsholds 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 writesextra['e2e-inc.e2e'].annotations, Markdown andtrace.mdlist them,listprints dimtype: descriptionglance lines (an empty description is dropped; a serial member that skipped itself shows what it pushed), and the HTML report renders them inTestView(linking onlyhttp(s)URLs). - 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): documentstest.info(),TestInfo,WorkerInfo,{ annotation }, andTEST_WORKER_INDEX/TEST_PARALLEL_INDEX, thetestInfoargument oftest.each/test.for, and the annotation output oflist,junit,markdown, andctrfindocs/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) exercisingtest.info(), a test-scoped fixture writing viatestInfo.outputPath(),TEST_WORKER_INDEX/TEST_PARALLEL_INDEX, static + runtime annotations, andlist,junit,ctrf,markdown,htmlReporter(), andtrace: '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 > 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()insidetest.step, and a laterafterEachseeing 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, keepstestInfo.durationrunning through teardown, and a teardown failure turnsstatustofailedfor the nextafterEach. 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
CANCELLEDfromtest.info()and leaves the next test's annotations alone, serial members writelog.txtinto their own directories, a test declared in an imported module reports that module, and a worker that exits mid-test keeps its declared annotation inlist,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:aband 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.