-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunAllTests.js
More file actions
59 lines (48 loc) · 1.4 KB
/
runAllTests.js
File metadata and controls
59 lines (48 loc) · 1.4 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
import { readdirSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import { spawn } from "child_process";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const testDir = __dirname;
const selfName = "runAllTests.js";
function discoverTests() {
return readdirSync(testDir)
.filter((file) => file.endsWith(".js") && file !== selfName)
.sort();
}
function runTest(file) {
return new Promise((resolve, reject) => {
console.log(`\n[RUN] node ${file}`);
const child = spawn(process.execPath, [join(testDir, file)], {
cwd: testDir,
env: process.env,
stdio: "inherit",
});
child.on("exit", (code) => {
if (code !== 0) {
reject(new Error(`${file} exited with code ${code}`));
} else {
resolve();
}
});
child.on("error", (err) => reject(err));
});
}
async function main() {
const tests = discoverTests();
if (!tests.length) {
console.log("[WARN] No test files found in test-case");
return;
}
console.log("[INFO] Running test-case scripts sequentially...");
console.log("[INFO] Files:", tests.join(", "));
for (const file of tests) {
await runTest(file);
}
console.log("\n[SUCCESS] All test-case scripts completed");
}
main().catch((err) => {
console.error("[ERROR] Test run failed:", err?.message || err);
process.exit(1);
});