Skip to content

Commit 4654817

Browse files
fix(ci): match checkout-root test selectors
1 parent 9733fb4 commit 4654817

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@ import * as NodeOS from "node:os";
66
import * as NodePath from "node:path";
77
import * as NodeURL from "node:url";
88

9-
import { cachedTestTasks } from "./cached-tests.ts";
9+
import { cachedTestTasks, matchesTestPath } from "./cached-tests.ts";
1010

1111
describe("cachedTestTasks", () => {
12+
it("selects every test for a checkout-root path", () => {
13+
const root = NodePath.resolve(import.meta.dirname, "../..");
14+
for (const path of [".", root]) {
15+
expect(
16+
matchesTestPath("apps/server/src/auth/utils.test.ts", [
17+
NodePath.relative(root, NodePath.resolve(root, path)),
18+
]),
19+
).toBe(true);
20+
}
21+
expect(matchesTestPath("apps/server/src/auth/utils.test.ts", ["apps/server"])).toBe(true);
22+
expect(matchesTestPath("apps/server-other/a.test.ts", ["apps/server"])).toBe(false);
23+
});
1224
it("keeps a file's cache task stable when unrelated tests are added", () => {
1325
const first = cachedTestTasks(JSON.stringify({ files: ["src/b.test.ts"], groupSize: 1 }));
1426
const second = cachedTestTasks(

‎scripts/lib/cached-tests.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ interface CachedTestTask {
1515
};
1616
}
1717

18+
export function matchesTestPath(file: string, filters: Array<string>) {
19+
return (
20+
filters.length === 0 ||
21+
filters.some((filter) => filter === "" || file === filter || file.startsWith(`${filter}/`))
22+
);
23+
}
24+
1825
export function cachedTestTasks(
1926
raw: string | undefined,
2027
root = NodePath.resolve(import.meta.dirname, "../.."),

‎scripts/test-cached.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as NodeFS from "node:fs";
55
import * as NodePath from "node:path";
66
import * as NodeUtil from "node:util";
77

8+
import { matchesTestPath } from "./lib/cached-tests.ts";
89
import { shardedTestFiles } from "./lib/sharded-tests.ts";
910

1011
const root = NodePath.resolve(import.meta.dirname, "..");
@@ -53,8 +54,7 @@ const files = [...new Set(candidates)].filter(
5354
/\.test\.[cm]?[jt]sx?$/.test(file) &&
5455
!file.startsWith(".repos/") &&
5556
NodeFS.existsSync(NodePath.join(root, file)) &&
56-
(filters.length === 0 ||
57-
filters.some((filter) => file === filter || file.startsWith(`${filter}/`))),
57+
matchesTestPath(file, filters),
5858
);
5959
if (files.length === 0) {
6060
console.error("No test files matched");

0 commit comments

Comments
 (0)