fix(runner): isolate worker fixture instances across extend() overrides (ENG-1400)
Merged
KR
21h ago+179+179+012345678901234567890123456789-20-20-01234567890123456789
What
A worker fixture that depends on another worker fixture now gets a separate instance for each test.extend() chain that overrides one of its dependencies, directly or through another fixture. Chains that share every worker fixture it names still share one instance.
Why
WorkerFixturePool.acquire cached each worker fixture solely by its own identity. When client depended on account and another file defined adminTest = test.extend({ account }), both chains resolved client to the same cached instance. Whichever file ran first set client for the rest of the worker, so the second file got the wrong account's client.
How it works
WorkerFixturePool.instancesmaps each fixture key (definition.identity ?? definition) to a list ofWorkerInstanceentries holding{ inputs, instance }, whereinputsare the instance promises returned byacquirefor the chain worker fixtures it depends on (packages/e2e/src/run/fixture-pool.ts:140,packages/e2e/src/run/fixture-pool.ts:199). On lookup,acquirereuses an entry only when allinputsmatch by reference; on setup failure, only that entry is evicted.bindFixturestracks theacquirepromise for each worker fixture inworkerInstances(packages/e2e/src/run/fixture-pool.ts:321) and passes the resolved dependency promises in declaration order topool.acquire, leaving built-in fixtures out of the key (packages/e2e/src/run/fixture-pool.ts:354-359). Keying by instance promise rather than by definition handles transitive overrides (client -> link -> account), and keying by promise rather than resolved value handles overrides that pass the extended object through.- Updated the fixture doc comment (
packages/e2e/src/collect/registry.ts:66), documented the instance rule under worker fixtures (docs/reference/test.mdx:1185), and added a patch changeset fore2e. - Added unit tests covering both chain orders, transitive overrides with a shared dependency, and pass-through overrides (
packages/e2e/tests/unit/fixture-pool.test.ts), plus a runner integration test for the two-file repro in both orders (packages/e2e/tests/integration/worker-fixtures.test.ts).
Issue
ENG-1400
Verified
Ran it locally: yes
- Built CLI (
node node_modules/e2e/dist/cli/bin.js run) on a two-file repro project (workers: 1,retries: 0) wheretests/support.tsdefines worker fixturesaccountandclient,tests/user.e2e.tsusestest, andtests/admin.e2e.tsoverridesaccountwithbase.extend:
| main | this PR |
|---|---|
tests/user.e2e.ts fails: ERROR: expected client:user, got client:admin (1 failed | 1 passed (2)) | Both files pass (2 passed (2)) |
=== main ===
✓ |web| tests/admin.e2e.ts > admin gets admin client 461ms
✓ |web| tests/admin.e2e.ts (1 test) 461ms
× |web| tests/user.e2e.ts > user gets user client 13ms
→ expected client:user, got client:admin
❯ |web| tests/user.e2e.ts (1 test | 1 failed) 13ms
Test Files 1 failed | 1 passed (2)
Tests 1 failed | 1 passed (2)
=== this PR ===
✓ |web| tests/admin.e2e.ts > admin gets admin client 459ms
✓ |web| tests/admin.e2e.ts (1 test) 459ms
✓ |web| tests/user.e2e.ts > user gets user client 9ms
✓ |web| tests/user.e2e.ts (1 test) 9ms
Test Files 2 passed (2)
Tests 2 passed (2)
apps/testbed:tests/hooks.e2e.tspasses (7 passed (7)in 2.50s).- Skipped
pnpm bench:ab: this change adds a reference equality check over a fixture's dependency list on worker-fixture acquisition and does not alter attempt scheduling or execution loops. - Not verified locally: mobile (
isolation: 'worker'), serial groups, andbox(all go through the samebindFixtures->acquirepath).
Summary by CodeRabbit
-
Bug Fixes
- Fixed worker-scoped fixtures so tests that override a dependency receive the correct separate fixture instance, while tests with matching fixture chains can share instances.
- Improved handling of failed fixture setup so other fixture instances remain available and later requests can retry.
- Verified that dependent fixtures are set up separately for overridden values, including when overrides are indirect or applied in a different order.
-
Documentation
- Clarified how worker-fixture instances are shared across tests and how direct and indirect overrides affect dependent fixtures.