Repository navigation
Description
Describe the bug
With sequence.shuffle.files enabled, the same seed gives different file orders between runs, even with one worker.
I use file shuffling to find tests that depend on another test's state. I expected the seed to let me reproduce the order after a failure.
Minimal reproduction uses 32 trivial tests across 16 directories, with this config:
export default {
test: {
include: ['cases/**/*.test.js'],
maxWorkers: 1,
isolate: false,
sequence: {
shuffle: { files: true },
seed: 1,
},
reporters: ['./order-reporter.mjs'],
},
}The reporter prints each file from onTestModuleStart. The first four files from two consecutive runs:
Run 1 Run 2
d3/f1.test.js d3/f1.test.js
d12/f0.test.js d11/f0.test.js
d12/f1.test.js d11/f1.test.js
d7/f1.test.js d7/f1.test.js
Ten runs gave ten different orders. The files, config and seed were unchanged.
This appears to come from RandomSequencer.sort, which passes the glob results straight to shuffle(files, sequence.seed). The glob result order can vary, so the seed alone does not determine the final order.
I tried sorting the files by module ID before the shuffle. All ten runs then produced the same order.
Reproduction
https://github.com/zeevox/vitest-shuffle-seed-repro
git clone https://github.com/zeevox/vitest-shuffle-seed-repro.git
cd vitest-shuffle-seed-repro
bun install --frozen-lockfile
bun run reproduceThis runs the same tests ten times with seed 1 and prints each file order. All tests pass. The expected result is one distinct order.
The result depends on filesystem timing. Repeat the command if the order stays the same.
System Info
System:
OS: macOS 27.2
CPU: (15) arm64 Apple M5 Pro
Memory: 13.17 GB / 48.00 GB
Shell: 5.3.20 - /opt/homebrew/bin/bash
Binaries:
Node: 24.21.0 - ~/.local/share/mise/installs/node/24/bin/node
Yarn: 1.22.22 - ~/.local/share/mise/installs/node/24/bin/yarn
npm: 12.1.0 - ~/.local/share/mise/installs/node/24/bin/npm
pnpm: 12.3.4 - ~/.local/share/mise/installs/node/24/bin/pnpm
bun: 1.4.2 - ~/.local/share/mise/shims/bun
Deno: 2.9.7 - /opt/homebrew/bin/deno
Browsers:
Chrome: 154.0.8037.58
Firefox: 156.0.1
Safari: 27.2
npmPackages:
vitest: 5.0.1 => 5.0.1
Vite 8.3.0 (from the lockfile). Vitest runs under Node.js; Bun installs dependencies and invokes the scripts.
Used Package Manager
bun
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Activity
pavstev commentedon Nov 3, 2026
I reproduced this on
main(v5.1.0) with 32 files in 16 directories,maxWorkers: 1,isolate: falseandseed: 1: ten runs gave nine different file orders. The fix I tested sorts a copy of the specs by project name,moduleIdand pool inRandomSequencer.sortbeforeshuffle; with it, 20 runs gave one order, and so did ten runs with two projects and six runs with--shard=1/2. Two new unit tests intest/unit/test/sequencers.test.tsfail onmainand pass with the fix, and the full unit suite plus the shard, cache and group-order e2e tests still pass. The one side effect is that a given seed now gives a different order than in older versions, so the fixed-seed expectation in that file changes. @sheremet-va, you reviewed this approach in #11350, would you add theapprovedlabel so I can open the PR?