Skip to content

Commit 71c9f18

Browse files
fix(ci): preserve Vitest spec files in cached shards
1 parent 4654817 commit 71c9f18

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎scripts/lib/cached-tests.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ describe("cachedTestTasks", () => {
4848
}
4949
});
5050

51+
it("accepts spec files discovered by Vitest", () => {
52+
const tasks = cachedTestTasks(JSON.stringify({ files: ["src/example.spec.ts"], groupSize: 1 }));
53+
expect(
54+
Object.values(tasks).some((task) => task.command === "vp test run 'src/example.spec.ts'"),
55+
).toBe(true);
56+
});
57+
5158
it("does not add tasks without an explicit request", () => {
5259
expect(cachedTestTasks(undefined)).toEqual({});
5360
});

‎scripts/lib/cached-tests.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function cachedTestTasks(
5050
typeof file !== "string" ||
5151
NodePath.isAbsolute(file) ||
5252
file.split(/[\\/]/).includes("..") ||
53-
!/\.test\.[cm]?[jt]sx?$/.test(file)
53+
!/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(file)
5454
) {
5555
throw new Error("Cached tests must be test files inside the checkout");
5656
}

‎scripts/lib/sharded-tests.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ it("uses the configured sequencer and discovers every file exactly once", async
2626
return files.sort((a,b)=>a.moduleId.localeCompare(b.moduleId)).filter((_,i)=>i%count===index-1);
2727
}
2828
}
29-
export default {test:{include:["included/*.test.ts"],sequence:{sequencer:Sequencer}}};`,
29+
export default {test:{include:["included/*.{test,spec}.ts"],sequence:{sequencer:Sequencer}}};`,
3030
);
3131
await NodeFSP.mkdir(NodePath.join(root, "included"));
3232
for (const file of [
3333
"included/a.test.ts",
3434
"included/b.test.ts",
3535
"included/c.test.ts",
36+
"included/d.spec.ts",
3637
"excluded.test.ts",
3738
]) {
3839
await NodeFSP.writeFile(NodePath.join(root, file), "export {};");
@@ -42,8 +43,11 @@ it("uses the configured sequencer and discovers every file exactly once", async
4243
expect(first).toEqual(
4344
["a", "c"].map((file) => NodePath.join(root, `included/${file}.test.ts`)),
4445
);
45-
expect(second).toEqual([NodePath.join(root, "included/b.test.ts")]);
46-
expect(new Set([...first, ...second]).size).toBe(3);
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);
4751
await expect(shardedTestFiles(root, "0/2")).rejects.toThrow("Shard must be");
4852
} finally {
4953
await NodeFSP.rm(root, { recursive: true, force: true });

‎scripts/test-cached.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ const candidates = values.shard
4949
{ cwd: root, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 },
5050
).split("\0");
5151
const filters = positionals.map((path) => NodePath.relative(root, NodePath.resolve(path)));
52-
const files = [...new Set(candidates)].filter(
53-
(file) =>
54-
/\.test\.[cm]?[jt]sx?$/.test(file) &&
55-
!file.startsWith(".repos/") &&
56-
NodeFS.existsSync(NodePath.join(root, file)) &&
57-
matchesTestPath(file, filters),
58-
);
52+
const isSelectable = (file: string) =>
53+
/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(file) &&
54+
!file.startsWith(".repos/") &&
55+
NodeFS.existsSync(NodePath.join(root, file)) &&
56+
matchesTestPath(file, filters);
57+
if (values.shard) {
58+
const rejected = candidates.filter((file) => !isSelectable(file));
59+
if (rejected.length)
60+
throw new Error(`Discovered tests cannot be selected: ${rejected.join(", ")}`);
61+
}
62+
const files = [...new Set(candidates)].filter(isSelectable);
5963
if (files.length === 0) {
6064
console.error("No test files matched");
6165
process.exit(values.shard ? 0 : 1);

0 commit comments

Comments
 (0)