feat(test): add --shard flag to split a test run across machines#35057
Merged
Conversation
`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
marked this pull request as ready for review
June 15, 2026 12:13
bartlomieju
enabled auto-merge (squash)
June 16, 2026 06:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Large test suites are commonly split across CI machines, which Vitest, Jest,
and Playwright all support with a
--shardflag.deno testhad noequivalent, so the whole suite had to run on one machine.
This adds
deno test --shard=<index>/<count>(1-based index). The discoveredtest files are sorted for a stable order, then split into
<count>consecutive, balanced groups, and only the files for
<index>are run. Everyfile 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 fileson every machine regardless of the shuffle seed. Invalid values
(
index > count,indexorcountof 0, missing/) are rejected atflag-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
countexceeds the number ofdiscovered 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.