The best way to control Claude Code, Codex and more from any computer or phone
| 1 | // @effect-diagnostics nodeBuiltinImport:off - verifies Vitest discovery in a disposable project. |
| 2 | import { expect, it } from "vite-plus/test"; |
| 3 | import * as NodeFSP from "node:fs/promises"; |
| 4 | import * as NodeOS from "node:os"; |
| 5 | import * as NodePath from "node:path"; |
| 6 | import { shardedTestFiles } from "./sharded-tests.ts"; |
| 7 | |
| 8 | it("uses the configured sequencer and discovers every file exactly once", async () => { |
| 9 | const root = await NodeFSP.realpath( |
| 10 | await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "test-shards-")), |
| 11 | ); |
| 12 | try { |
| 13 | await NodeFSP.mkdir(NodePath.join(root, "node_modules")); |
| 14 | await NodeFSP.symlink( |
| 15 | NodePath.resolve(import.meta.dirname, "../../node_modules/vite-plus"), |
| 16 | NodePath.join(root, "node_modules/vite-plus"), |
| 17 | "dir", |
| 18 | ); |
| 19 | await NodeFSP.writeFile(NodePath.join(root, "package.json"), '{"type":"module"}'); |
| 20 | await NodeFSP.writeFile( |
| 21 | NodePath.join(root, "vite.config.ts"), |
| 22 | `import {BaseSequencer} from "vite-plus/test/node"; |
| 23 | class Sequencer extends BaseSequencer { |
| 24 | async shard(files) { |
| 25 | const {index,count}=this.ctx.config.shard; |
| 26 | return files.sort((a,b)=>a.moduleId.localeCompare(b.moduleId)).filter((_,i)=>i%count===index-1); |
| 27 | } |
| 28 | } |
| 29 | export default {test:{include:["included/*.{test,spec}.ts"],sequence:{sequencer:Sequencer}}};`, |
| 30 | ); |
| 31 | await NodeFSP.mkdir(NodePath.join(root, "included")); |
| 32 | for (const file of [ |
| 33 | "included/a.test.ts", |
| 34 | "included/b.test.ts", |
| 35 | "included/c.test.ts", |
| 36 | "included/d.spec.ts", |
| 37 | "excluded.test.ts", |
| 38 | ]) { |
| 39 | await NodeFSP.writeFile(NodePath.join(root, file), "export {};"); |
| 40 | } |
| 41 | const first = await shardedTestFiles(root, "1/2"); |
| 42 | const second = await shardedTestFiles(root, "2/2"); |
| 43 | expect(first).toEqual( |
| 44 | ["a", "c"].map((file) => NodePath.join(root, `included/${file}.test.ts`)), |
| 45 | ); |
| 46 | expect(second).toEqual([ |
| 47 | NodePath.join(root, "included/b.test.ts"), |
| 48 | NodePath.join(root, "included/d.spec.ts"), |
| 49 | ]); |
| 50 | expect(new Set([...first, ...second]).size).toBe(4); |
| 51 | await expect(shardedTestFiles(root, "0/2")).rejects.toThrow("Shard must be"); |
| 52 | } finally { |
| 53 | await NodeFSP.rm(root, { recursive: true, force: true }); |
| 54 | } |
| 55 | }); |