Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - Vitest discovery runs outside the application runtime.
2import * as NodePath from "node:path";
3import { createVitest } from "vite-plus/test/node";
4
5export async function shardedTestFiles(root: string, shard: string) {
6 const match = /^(\d+)\/(\d+)$/.exec(shard);
7 const index = Number(match?.[1]);
8 const count = Number(match?.[2]);
9 if (!Number.isSafeInteger(index) || !Number.isSafeInteger(count) || index < 1 || index > count) {
10 throw new Error("Shard must be index/count with 1 <= index <= count");
11 }
12 const context = await createVitest("test", { root, watch: false, shard });
13 try {
14 const files = await context.globTestSpecifications();
15 const sequencer = new context.config.sequence.sequencer(context);
16 const selected = await sequencer.shard(files);
17 return selected.map((file) => NodePath.resolve(file.moduleId));
18 } finally {
19 await context.close();
20 }
21}