36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { spawnSync } from "node:child_process";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const testsRoot = path.join(root, "web", "tests");
|
|
|
|
function collect(directory) {
|
|
const files = [];
|
|
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
const file = path.join(directory, entry.name);
|
|
if (entry.isDirectory()) files.push(...collect(file));
|
|
else if (entry.isFile() && entry.name.endsWith(".test.mjs")) files.push(file);
|
|
}
|
|
return files.sort();
|
|
}
|
|
|
|
const tests = collect(testsRoot);
|
|
for (const [index, file] of tests.entries()) {
|
|
const relative = path.relative(path.join(root, "web"), file).replaceAll(path.sep, "/");
|
|
process.stdout.write(`unit-file ${index + 1}/${tests.length} ${relative}\n`);
|
|
const result = spawnSync(process.execPath, ["--test", "--test-concurrency=1", relative], {
|
|
cwd: path.join(root, "web"),
|
|
stdio: "inherit",
|
|
env: process.env,
|
|
});
|
|
if (result.status !== 0) {
|
|
process.stderr.write(`unit-file-failed ${relative} exit=${result.status ?? 1}\n`);
|
|
process.exitCode = result.status ?? 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (process.exitCode === undefined) process.stdout.write(`unit-suite-ok files=${tests.length}\n`);
|