import { mkdtemp, readdir, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { basename, join } from "node:path"; import { fileURLToPath } from "node:url"; import { spawnSync } from "node:child_process"; import { build } from "esbuild"; const directory = fileURLToPath(new URL(".", import.meta.url)); const output = await mkdtemp(join(tmpdir(), "yawn-fxnode-rg-tests-")); try { const entries = (await readdir(directory)) .filter((name) => name.endsWith(".test.ts")) .sort() .map((name) => join(directory, name)); await build({ entryPoints: entries, outdir: output, entryNames: "[name]", outExtension: { ".js": ".mjs" }, bundle: true, format: "esm", platform: "node", target: "node20", sourcemap: "inline", }); const tests = entries.map((entry) => join(output, `${basename(entry, ".ts")}.mjs`), ); const result = spawnSync(process.execPath, ["--test", ...tests], { stdio: "inherit", }); if (result.error) throw result.error; process.exitCode = result.status ?? 1; } finally { await rm(output, { force: true, recursive: true }); }