Files
arah2/web/test/runner.mjs
araharah-executor 9376cabca2 feat(03-01): stand up web/ npm workspace with Wave-0 hand-rolled test runner (D-01, D-02, D-11, D-14)
- web/ workspace: TS + Vite shell (maplibre-gl 6.15.0, vite 8.3.5, TS 5.9.3; no UI framework, no Telegram SDK script tag)
- tsconfig mirrors bot/ strictness byte-for-byte except the three authorized keys (DOM lib, vite/client types, resolveJsonModule)
- test/runner.mjs + harness.mjs copied verbatim from bot/test/ (body-identical past header)
- root package.json: web workspace + web:* delegate scripts
- web/src/main.ts entry module created (tsc include:['src'] needs ≥1 input; 03-02/03-03 mount here)
2026-10-22 23:24:41 +08:00

48 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
/*
* runner.mjs — hand-rolled zero-dependency test runner (D-02, D-11).
*
* Auto-discovers *.test.mjs in this directory (sorted), dynamic-imports
* them, and drains the harness registry. A suite that fails to LOAD is
* recorded as one failing case — the run never crashes mid-way.
* Same hand-rolled shape as theme/scripts/audit.test.mjs (Phase 1)
* and bot/test/ (Phase 2) — copied verbatim, workspace-agnostic.
*/
import { readdirSync } from "node:fs";
import { registry } from "./harness.mjs";
const dir = import.meta.dirname;
const suites = readdirSync(dir)
.filter((f) => f.endsWith(".test.mjs"))
.sort();
for (const file of suites) {
try {
await import(`./${file}`);
} catch (loadErr) {
registry.push({
name: `suite load failed: ${file}`,
fn: () => {
throw loadErr;
},
});
}
}
let passedCount = 0;
let failedCount = 0;
for (const { name, fn } of registry) {
try {
await fn();
passedCount++;
console.log(`PASS ${name}`);
} catch (err) {
failedCount++;
console.log(`FAIL ${name}`);
console.error(` ${err && err.stack ? err.stack : String(err)}`);
}
}
console.log(`[runner] ${passedCount} passed, ${failedCount} failed`);
process.exitCode = failedCount > 0 ? 1 : 0;