@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 21 lines 940 Bytes
Raw
1 // @effect-diagnostics nodeBuiltinImport:off - Vitest discovery runs outside the application runtime.
2 import * as NodePath from "node:path";
3 import { createVitest } from "vite-plus/test/node";
4
5 export 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 }