Summary
rules_vitest's Bazel test sequencer currently computes shard ranges using:
const shardSize = Math.ceil(files.length / shardCount);
const shardStart = shardSize * shardIndex;
const shardEnd = shardSize * (shardIndex + 1);
This can produce an empty trailing shard even when there are at least as many test files as Bazel shards.
For example, with 10 test files and 6 shards:
shardSize = ceil(10 / 6) = 2
shard 0 => files[0:2]
shard 1 => files[2:4]
shard 2 => files[4:6]
shard 3 => files[6:8]
shard 4 => files[8:10]
shard 5 => files[10:12] // empty
That last shard exits with Vitest's "No test files found" failure.
Expected Behavior
When files.length >= shardCount, every shard should receive at least one test file.
Actual Behavior
The final shard gets zero files and the Bazel test fails even though there are more test files than shards.
Repro
git clone https://github.com/fremtind/rules_vitest.git
cd rules_vitest
git checkout v0.2.3
Replace example/sharding/BUILD.bazel with:
load("@fremtind_rules_vitest//vitest:defs.bzl", "vitest_test")
vitest_test(
name = "test",
config = "vitest.config.js",
data = [
"index.js",
"index_01.test.js",
"index_02.test.js",
"index_03.test.js",
"index_04.test.js",
"index_05.test.js",
"index_06.test.js",
"index_07.test.js",
"index_08.test.js",
"index_09.test.js",
"index_10.test.js",
],
node_modules = "//:node_modules",
shard_count = 6,
)
Generate 10 trivial test files:
for i in $(seq -w 1 10); do
cat > "example/sharding/index_${i}.test.js" <<'EOF'
const { test, expect } = await import("vitest");
test("runs", () => {
expect(1).toBe(1);
});
EOF
done
Run:
bazel test //example/sharding:test
Result
One of the shards receives no test files and fails with output like:
No test files found, exiting with code 1
The target fails even though there are 10 test files and only 6 shards.
Environment
Observed with:
rules_vitest v0.2.3
Vitest 4.x
Bazel test sharding enabled via shard_count
Summary
rules_vitest's Bazel test sequencer currently computes shard ranges using:This can produce an empty trailing shard even when there are at least as many test files as Bazel shards.
For example, with 10 test files and 6 shards:
That last shard exits with Vitest's "No test files found" failure.
Expected Behavior
When
files.length >= shardCount, every shard should receive at least one test file.Actual Behavior
The final shard gets zero files and the Bazel test fails even though there are more test files than shards.
Repro
git clone https://github.com/fremtind/rules_vitest.git cd rules_vitest git checkout v0.2.3Replace
example/sharding/BUILD.bazelwith:Generate 10 trivial test files:
Run:
bazel test //example/sharding:testResult
One of the shards receives no test files and fails with output like:
The target fails even though there are 10 test files and only 6 shards.
Environment
Observed with: