master
Colby Knox v0.12.7 263875b
// Runs every test/*.test.mjs in its own process, one after another, and
// reports each file's result. Unlike a chain of `&&`, a failing file does not
// hide the files after it. Exits 1 when any file fails.
//
//   node test/run-all.mjs              every file
//   node test/run-all.mjs orbit help   only the named files
import { spawnSync } from "node:child_process";
import { readdirSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const DIR = dirname(fileURLToPath(import.meta.url));
const only = process.argv.slice(2);
const files = readdirSync(DIR).filter(f => f.endsWith(".test.mjs")).sort()
  .filter(f => !only.length || only.includes(f.replace(/\.test\.mjs$/, "")));
if (!files.length) { console.error(`no test files match ${only.join(" ")}`); process.exit(2); }

const results = [];
for (const f of files) {
  console.log(`\n=== ${f}`);
  const t0 = Date.now();
  const r = spawnSync(process.execPath, [join(DIR, f)], { stdio: "inherit" });
  results.push({ f, code: r.status ?? 1, s: ((Date.now() - t0) / 1000).toFixed(0) });
}
console.log("\n=== summary");
for (const r of results) console.log(`  ${r.code === 0 ? "ok  " : "FAIL"} ${r.f} (${r.s} s${r.code ? `, exit ${r.code}` : ""})`);
const failed = results.filter(r => r.code !== 0).length;
console.log(`${results.length - failed} of ${results.length} files passed`);
process.exit(failed ? 1 : 0);