Skip to content

feat(test): add --shard flag to split a test run across machines#35057

Merged
bartlomieju merged 2 commits into
mainfrom
feat/test-shard
Jun 16, 2026
Merged

feat(test): add --shard flag to split a test run across machines#35057
bartlomieju merged 2 commits into
mainfrom
feat/test-shard

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Jun 9, 2026

Copy link
Copy Markdown
Member

Large test suites are commonly split across CI machines, which Vitest, Jest,
and Playwright all support with a --shard flag. deno test had no
equivalent, so the whole suite had to run on one machine.

This adds deno test --shard=<index>/<count> (1-based index). The discovered
test files are sorted for a stable order, then split into <count>
consecutive, balanced groups, and only the files for <index> are run. Every
file lands in exactly one shard and group sizes differ by at most one. The
selection happens before any --shuffle, so a given shard runs the same files
on every machine regardless of the shuffle seed. Invalid values
(index > count, index or count of 0, missing /) are rejected at
flag-parse time.

Sharding is a pre-filter on the discovered file list, independent of how files
are executed, so it composes cleanly with filtering and any future test-runner
isolation/pooling changes.

Over-sharding is intentionally lenient: if count exceeds the number of
discovered files, the empty shards run zero tests and exit successfully rather
than erroring. This is the behavior that fixed-shard-count CI setups want
(Vitest instead errors and requires --passWithNoTests).

For now the shard is selected at run time, after the module graph for the full
suite has already been built and type-checked, so every machine still pays the
graph-build and type-check cost for the whole suite and only test execution is
parallelized. Moving the shard pre-filter ahead of type-checking, so each
machine only loads and checks its own subset, is a natural follow-up.

This intentionally does not include cross-shard result merging (a combined
summary across shards); each shard reports its own subset and fails its own CI
job, and a merge step pairs naturally with the json reporter as a follow-up.

`deno test --shard=<index>/<count>` runs only the test files belonging to
the given 1-based shard, so a suite can be split across machines (as in
Vitest, Jest, and Playwright). The discovered files are sorted for a stable
order and split into <count> consecutive, balanced groups; the selection
happens before any --shuffle so it is deterministic across machines.
@bartlomieju bartlomieju added this to the 2.9.0 milestone Jun 9, 2026
@bartlomieju
bartlomieju marked this pull request as ready for review June 15, 2026 12:13
@bartlomieju
bartlomieju enabled auto-merge (squash) June 16, 2026 06:58
@bartlomieju
bartlomieju merged commit 3afd027 into main Jun 16, 2026
268 of 270 checks passed
@bartlomieju
bartlomieju deleted the feat/test-shard branch June 16, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant