-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.mjs
More file actions
68 lines (55 loc) · 1.82 KB
/
run-tests.mjs
File metadata and controls
68 lines (55 loc) · 1.82 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { spawn } from "node:child_process";
import path from "node:path";
import { mkdirSync, readdirSync, rmSync } from "node:fs";
import { fileURLToPath } from "node:url";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)));
const validationRoot =
process.env.AUTOLABOS_VALIDATION_WORKSPACE_ROOT || getDefaultValidationWorkspaceRoot(repoRoot);
const testTmpRoot = path.join(validationRoot, ".tmp");
mkdirSync(testTmpRoot, { recursive: true });
for (const entry of readdirSync(testTmpRoot)) {
rmSync(path.join(testTmpRoot, entry), { recursive: true, force: true });
}
process.env.TMPDIR = testTmpRoot;
process.env.TMP = testTmpRoot;
process.env.TEMP = testTmpRoot;
const rawArgs = process.argv.slice(2);
const rootArgs = rawArgs.filter((arg) => arg !== "--runInBand");
const hasFilteredArgs = rootArgs.length > 0;
if (rawArgs.includes("--runInBand")) {
console.warn("[test] Ignoring unsupported --runInBand for Vitest.");
}
const vitestExit = await runCommand("vitest", ["run", ...rootArgs]);
if (vitestExit !== 0) {
process.exit(vitestExit);
}
if (hasFilteredArgs) {
process.exit(0);
}
const webExit = await runCommand("npm", ["--prefix", "web", "run", "test"]);
process.exit(webExit);
function runCommand(command, args) {
return new Promise((resolve) => {
const child = spawn(resolveCommand(command), args, {
stdio: "inherit",
env: process.env
});
child.on("exit", (code, signal) => {
if (signal) {
resolve(1);
return;
}
resolve(code ?? 0);
});
child.on("error", () => resolve(1));
});
}
function resolveCommand(command) {
if (process.platform === "win32") {
return `${command}.cmd`;
}
return command;
}
function getDefaultValidationWorkspaceRoot(projectRoot) {
return path.join(path.dirname(projectRoot), ".autolabos-validation");
}