import { spawnSync } from "node:child_process"; import { existsSync, readdirSync } from "node:fs"; import { constants } from "node:os"; import { join } from "node:path"; import { fileURLToPath } from "node:url"; const root = fileURLToPath(new URL("..", import.meta.url)); const testsDir = join(root, "tests"); function collectTests(dir) { return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { const path = join(dir, entry.name); if (entry.isDirectory()) { return collectTests(path); } return /\.test\.tsx?$/.test(entry.name) ? [path] : []; }); } const files = existsSync(testsDir) ? collectTests(testsDir).sort() : []; if (files.length === 0) { console.error("No web tests found under apps/web/tests"); process.exit(1); } const result = spawnSync(process.execPath, ["--import", "tsx", "--test", ...files], { cwd: root, stdio: "inherit" }); if (result.status !== null) { process.exit(result.status); } const signalNumber = result.signal ? constants.signals[result.signal] : undefined; process.exit(typeof signalNumber === "number" ? 128 + signalNumber : 1);