import { readdir } from "node:fs/promises"; import path from "node:path"; import { pathToFileURL } from "node:url"; import { createSelfTestContext, type SelfTestCase, type SelfTestResult } from "./harness.js"; const root = path.resolve(import.meta.dirname, "../.."); const casesDir = path.join(root, "src/selftest/cases"); const context = await createSelfTestContext(root); try { const caseFiles = (await readdir(casesDir)) .filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts")) .sort(); const results: SelfTestResult[] = []; for (const file of caseFiles) { const moduleUrl = pathToFileURL(path.join(casesDir, file)).href; const imported = await import(moduleUrl) as { default?: SelfTestCase; selfTest?: SelfTestCase }; const selfTest = imported.default ?? imported.selfTest; if (typeof selfTest !== "function") throw new Error(`self-test case ${file} must export default or selfTest function`); const result = await selfTest(context); results.push({ name: result.name ?? file.replace(/\.ts$/u, ""), tests: result.tests ?? [] }); } console.log(JSON.stringify({ ok: true, cases: results, tests: results.flatMap((result) => result.tests) })); } finally { await context.cleanup(); }