-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathinternal-test-projects.mts
More file actions
37 lines (35 loc) · 1.46 KB
/
Copy pathinternal-test-projects.mts
File metadata and controls
37 lines (35 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { existsSync, readdirSync, readFileSync } from "node:fs";
import { resolve } from "node:path";
export function getInternalTestProjects(monorepoRoot: string) {
return readdirSync(resolve(monorepoRoot, "internal-packages"))
.sort()
.flatMap((directory) => {
const root = resolve(monorepoRoot, "internal-packages", directory);
const manifestPath = resolve(root, "package.json");
if (!existsSync(manifestPath)) return [];
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
if (!manifest.name?.startsWith("@internal/") || !manifest.scripts?.test) return [];
// Keep custom test commands from being bypassed if a package changes later.
if (
!/^vitest(?: run)?(?: --sequence.concurrent=false)?(?: --no-file-parallelism)?$/.test(
manifest.scripts.test
)
) {
throw new Error(`Unsupported test command for ${manifest.name}: ${manifest.scripts.test}`);
}
return [{ root, name: manifest.name as string }];
});
}
// Report replay needs the same names and roots to reconstruct Vitest's test IDs.
// Inline projects avoid loading package configs or installing workspace dependencies.
export function getInternalTestReportConfig(monorepoRoot: string) {
return {
test: {
projects: getInternalTestProjects(monorepoRoot).map(({ root, name }) => ({
extends: false as const,
configFile: false as const,
test: { root, name },
})),
},
};
}