-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.cjs
40 lines (40 loc) · 1.14 KB
/
tests.cjs
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
"use strict";
const fs = require("fs");
const child_process = require("child_process");
const PATH = require("path");
function runTestsInDirectory(path) {
"use strict";
const dirents = fs.readdirSync(path, {
encoding: "utf8",
withFileTypes: true,
});
while (dirents.length) {
const dirent = dirents.pop();
if (dirent.isDirectory()) {
runTestsInDirectory(PATH.join(path, dirent.name));
} else if (dirent.isFile()) {
if (dirent.name === "index.cjs") continue;
console.group(PATH.join(path, dirent.name));
runTestOnFile(path, dirent.name);
console.groupEnd(PATH.join(path, dirent.name));
} else {
throw new Error("Not a file or directory");
}
}
}
function runTestOnFile(path, file) {
"use strict";
console.log("Testing...");
try {
child_process.execSync("node " + file, {
stdio: "ignore",
cwd: path,
encoding: "utf8",
});
} catch (e) {
console.error("Failed");
return;
}
console.log("Passed");
}
runTestsInDirectory("tests");