feat(runner): run the tests of one file in parallel
What
Tests of one file can run at the same time on separate workers. Until now only files ran in parallel, and a file's tests ran in order on one worker.
import { describe, test } from 'e2e';
describe.configure({ parallel: true }); // the whole file
describe('reports', { parallel: true }, () => {}); // one group
describe('checkout', { parallel: false }, () => {}); // a group kept in order inside a parallel scope
// e2e.config.ts
export default {
fullyParallel: true, // every file; also on a target, and `e2e run --fully-parallel`
targets: [{ engine: web(), fullyParallel: false }],
};
The grouping follows Playwright's (createTestGroups):
- A test in a parallel scope with no
beforeAllorafterAllaround it runs as a unit of its own. - Tests with such hooks share units, at most as many as the target has workers for each agent, so the hooks run one time per unit.
- Every repeat of a test (
--repeat-each) stays in the unit of its test, in order, so the first records the replay cache and the rest replay it. - A serial group, or a group with
parallel: false, is one unit on one worker. parallel: trueinside a serial group or inside aparallel: falsescope is aCOLLECTION_ERROR.- The cut is the same for any worker count. With one worker the units run one at a time.
Without any of the new settings a file is still one unit, with the same unit id.
A test or hook declared by a module the test file imports now reaches every import of the file. A helper that registers a beforeEach or a test at import time used to register it for the first test file a worker imported and for no later one.
Why
One file of 4 slow tests took 7 minutes of a 7m17s run on 7 workers, while every other file finished by 2m53s. The only workaround was one test per file. The migration guide listed fullyParallel and describe.configure({ mode: 'parallel' }) as missing.
A worker imports a test file again after a failed test, and imports a second file that shares a helper. The loader evaluates only the test file afresh, and the modules it imports keep one instance per process. So a helper's test() and hook calls ran for one import only: on main the tests after a failed one, and the second file, run without the helper's hooks.
How it works
The scheduler and the worker already run a unit that holds only some of a file's tests (setup gating and the hung-worker reschedule send such units), so neither changed. The change is in how the planner cuts a file.
- Registration keeps
parallelon each group, from thedescribeoption or adescribe.configure()call in its body, and on the file for a top-level call (packages/e2e/src/collect/registry.ts:299). The value checks are inpackages/e2e/src/collect/parallel.ts:12and:27. - When the file has registered,
checkParallelNestingrefuses a parallel group inside a serial group or aparallel: falsescope (packages/e2e/src/collect/parallel.ts:47). It runs at the end becausedescribe.configure()can set a scope's value after the groups inside it were declared. Playwright checks at the call and so accepts one of the two declaration orders. Here both orders are an error. - Collection gives every test a placement: whether a scope around it is parallel, the outermost scope around it that runs in order, and whether a suite hook is around it (
packages/e2e/src/collect/parallel.ts:103,packages/e2e/src/collect/collect.ts:200). No record or wire message carries it. Two serial groups with one title path share a serial group id, so they also share a placement and stay in one unit, together with theparallel: falsegroups around them (packages/e2e/src/collect/parallel.ts:107). splitFilecuts one file's runnable pairs into units from those placements and the target'sfullyParallel(packages/e2e/src/run/units.ts:162). The unit kind staysfile. The first unit of a file keeps the idfile::<target>::<file>and the others add an index. A file of tests registered in memory (e2e explore) stays one unit, since no module exists to import again.fullyParallelresolves per target:--fully-parallel, then the target's, then the config's (packages/core/src/config/resolve.ts:251). It stays out of the config digest, so turning it on keeps the replay cache valid.- When an engine's
preparereports fewer workers than the plan was cut for,withWorkerCapcuts the target's files again for that many, so hooked tests do not run their hooks more often than the devices there are (packages/e2e/src/run/units.ts:131,packages/e2e/src/run/runner.ts:1351). The runner then orders the plan again. orderWorkPlansranks a unit by the file's time from the timings history times the unit's share of the file's pairs (packages/e2e/src/run/units.ts:218). The timings file keeps its per-file schema.- Each
test(), hook anddescribe.configure()call asks which module is evaluating: the frame Node.js's ES module loader is running, or the outermost frame once the module has awaited (packages/e2e/src/collect/evaluating-module.ts). When that is a module other than the test file, registration reports it to the loader (packages/e2e/src/collect/registry.ts:717). The stack is read with source maps off, so a compiled helper is known by the file that was loaded. A module that calls or awaits a function of a library is the one reported, so the library stays one instance. - The loader keeps the import graph of project files. A reported module and every file that imports it take the importing load's
e2equery, so they evaluate again with each fresh import of a test file (packages/e2e/src/config/esm-hooks.ts:104,:115). A module that registers nothing keeps one instance per worker, so a worker fixture declared in such a module still has one instance. The load that first reached a file keeps the instance it evaluated, so a second import of a helper in the same load (another spelling, a dynamic import in a test body) does not evaluate it twice. A file without a query is one instance for every load, so an import it runs while a test file loads (a function of it the test file calls) belongs to the load that is importing.
Decisions a reviewer may ask about:
parallel: true | falseinstead of Playwright'smode. It sits beside the existingserial: true.describe.configure({ mode })fails with a message that names the replacement.- A worker imports a file one time for the units of it that it runs, as Playwright does: a unit that ends with nothing failed leaves its import for the file's next unit on that worker (
RealmManager.keep,packages/e2e/src/run/realm.ts). So tests that run apart share the file's state on one worker and not across workers, abeforeAllandafterAllpair can run several times on that state, and a worker fixture the file declares is one instance per worker. A failed test, a failed suite hook, a serial group and a setup test still get their own import, as on main, and the scheduler replaces a worker that saw a failure. - For step 9 a fresh module graph per import was the other option. It would evaluate every imported project file again, so every worker fixture in a support module would get one instance per file instead of one per worker.
- A CommonJS helper loaded with
require()has no query to make it fresh, a package undernode_modulesis never evaluated again, and Bun runs without these hooks. All three keep one instance, so a hook such a helper declares is missing where a worker imports the file again: a retry, the tests after a failed one in the same unit, a serial group, and a second file that imports the helper. That is main's behavior. Tests of a parallel file that pass keep the hook, on Bun too (bun-runtime.test.ts). - A worker fixture keeps one instance per worker when the module that defines it is evaluated again (a registering module, a module that imports one, the test file after a failed test). The worker knows a fixture by where it is defined: the module evaluating, the
test.extend()call, the name, and its count in that collection (packages/e2e/src/collect/fixture-identity.ts). Only the fixture's value is kept, not the module's variables; the docs say so. Bun keeps one instance per definition. - Code of a test file runs as part of the load that imported the file (
runInLoad,packages/e2e/src/config/esm-hooks.ts), so an import a shared module makes from a test resolves to the instance the file imported. - A failing suite hook is reported one time per unit that ran it.
- Not changed, where Playwright differs: a unit holds every repeat of its tests, a retry still runs right after the failed attempt, and skipped tests do not count toward hook batch sizes.
Issue
Linear ENG-961
Verified
Ran it locally: yes
Testbed app, built CLI, real Chromium, one file of four 5 s tests, --workers 4:
$ e2e run --workers 4
✓ |web| slow.e2e.ts > slow test 1 5.36s
✓ |web| slow.e2e.ts > slow test 2 5.08s
✓ |web| slow.e2e.ts > slow test 3 5.07s
✓ |web| slow.e2e.ts > slow test 4 5.07s
✓ |web| slow.e2e.ts (4 tests) 20.58s
Duration 20.93s (startup 98ms)
$ e2e run --workers 4 --fully-parallel
✓ |web| slow.e2e.ts > slow test 2 5.33s
✓ |web| slow.e2e.ts > slow test 4 5.33s
✓ |web| slow.e2e.ts > slow test 1 5.33s
✓ |web| slow.e2e.ts > slow test 3 5.33s
✓ |web| slow.e2e.ts (4 tests) 21.31s
Duration 5.61s (startup 91ms)
The error a user gets for a parallel group inside a serial one:
ERROR configuration error COLLECTION_ERROR (collection)
tests/bad.e2e.ts: describe "inner": parallel: true cannot be set inside a serial group, which runs as one unit on one worker
A helper module with a beforeEach, imported by two test files, one worker, fake engine. Each test prints a line, and so does the hook:
main (97b51a22) | this PR |
|---|---|
helper beforeEach | helper beforeEach |
The reviewer's two probes (a helper that declares two tests, a helper beforeEach that throws once a marker file exists) give the same results with and without --fully-parallel at this head: both tests pass in the first, and second fails with imported beforeEach ran in the second.
Tests added:
packages/e2e/tests/integration/parallel-tests-in-file.test.tsruns real worker processes. Its parallel cases pass only when the tests are inside their bodies at the same time (a file barrier, no timing). It also covers hook batches, serial andparallel: falsegroups, a retry, one worker, a run without worker processes, and an engine whosepreparereports fewer workers. For the one import per worker it counts the file's evaluations per process: across ordered groups, across a serial group, after a failed test (a new worker), after a failedbeforeAll(a fresh import), and for a worker fixture the file declares. It also covers the repeats of a parallel test and a unit after an expected failure.packages/e2e/tests/integration/imported-registrations.test.tscovers a helper that declares a test and abeforeEach: a parallel file on one worker, a CommonJS helper in a parallel file, a second test file, the tests after a failed one, a helper reached through another module in both file orders, a helper imported twice in one load, an awaited library function, and a helper with onlydescribe.configure(). Also a helper whose one import is a dynamic one, a compiled helper whose source map names another file, and a helper that awaits a library function. Each case fails without its part of steps 8 and 9.apps/testbed/tests/parallel.e2e.tsruns a parallel file on the web engine.packages/e2e/tests/unit/units.test.tsandparallel-scopes.test.tscover the cut and the placements,cli.test.tsthe flag,sdk-types.tsthe types.
pnpm bench:ab on the testbed, files that use none of the new settings. Measured at 227588f7, one commit before the head; that commit changes what a file's later units import, and these files are one unit each:
bench-ab: 425cdb28 (merge base with origin/main) vs 227588f7
apps/testbed: e2e run --workers 1 tests/forms.e2e.ts tests/hooks.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x15, Node 24.19.0, load 2.7.
The suite's tests or config differ between base and head, so each side ran its own. A timing change can be the test change.
Behavior
These tests are left out of the timing rows below.
- added tests/parallel.e2e.ts › in order › adds a todo (web)
- added tests/parallel.e2e.ts › in order › runs after it, in the same import of the file (web)
- added tests/parallel.e2e.ts › opens the todos (web)
- added tests/parallel.e2e.ts › opens the todos again (web)
Timings
Every row but the process wall clock covers the 607 tests whose behavior matched.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 2.94 s (2.94 s-2.96 s) | 2.95 s (2.95 s-2.97 s) | +0.4% (-0.7% to +1.7%) | same |
| suite (sum of attempts) | 2.25 s (2.25 s-2.26 s) | 2.25 s (2.25 s-2.25 s) | +0.1% (-1.5% to +0.6%) | same, under the floor |
| action (events) | 480 ms (478 ms-489 ms) | 482 ms (480 ms-484 ms) | -0.1% (-2.1% to +1.9%) | same, under the floor |
| step expect.not.toBeChecked | 1.01 s (1.01 s-1.01 s) | 1.01 s (1.01 s-1.01 s) | -0.1% (-0.4% to +0.2%) | same, under the floor |
| step app.open | 431 ms (431 ms-433 ms) | 428 ms (424 ms-430 ms) | -0.7% (-3.5% to +0.5%) | same, under the floor |
| step locator.fill | 283 ms (282 ms-285 ms) | 283 ms (283 ms-287 ms) | -0.4% (-1.2% to +2.1%) | same, under the floor |
| step locator.tap | 60 ms (58 ms-70 ms) | 60 ms (58 ms-61 ms) | -3.3% (-19.6% to +10.6%) | same, under the floor |
| step expect.toBeVisible | 46 ms (46 ms-47 ms) | 46 ms (46 ms-46 ms) | 0.0% (-4.2% to +2.2%) | same |
| step locator.pressSequentially | 42 ms (42 ms-42 ms) | 41 ms (40 ms-41 ms) | -4.7% (-4.8% to -2.4%) | same, under the floor |
| step locator.check | 34 ms (33 ms-35 ms) | 35 ms (34 ms-35 ms) | +3.0% (-2.9% to +6.2%) | same, under the floor |
| step locator.press | 33 ms (32 ms-33 ms) | 34 ms (33 ms-34 ms) | +1.5% (-1.5% to +7.8%) | same, under the floor |
| step locator.uncheck | 33 ms (32 ms-33 ms) | 33 ms (32 ms-33 ms) | 0.0% (-3.0% to +3.1%) | same |
| step locator.clear | 16 ms (15 ms-16 ms) | 15 ms (15 ms-15 ms) | 0.0% (-6.3% to 0.0%) | same |
| step locator.selectOption | 15 ms (15 ms-15 ms) | 15 ms (15 ms-15 ms) | 0.0% (0.0% to 0.0%) | same |
| step expect.toHaveCount | 8 ms (7 ms-8 ms) | 7 ms (7 ms-8 ms) | 0.0% (-19.0% to +6.1%) | same |
| step expect.toHaveValue | 7 ms (6 ms-7 ms) | 6 ms (6 ms-7 ms) | -6.5% (-21.8% to +18.3%) | same, under the floor |
| step expect.toContainText | 5 ms (4 ms-5 ms) | 5 ms (4 ms-5 ms) | +9.5% (-30.7% to +25.0%) | same, under the floor |
| step expect.toHaveText | 4 ms (3 ms-4 ms) | 4 ms (4 ms-5 ms) | +25.0% (0.0% to +63.3%) | same, under the floor |
| step expect.toBeChecked | 3 ms (2 ms-3 ms) | 2 ms (1 ms-2 ms) | -42.3% (-66.7% to -18.4%) | same, under the floor |
Counters
| Counter | base | head |
|---|---|---|
| tests skipped | 597 | 601 |
Tests outside the threshold: 0 of 607
With 607 tests compared at 95%, about 30.4 could land outside by chance.
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.