tcmsEnded
uses node:fs
Whether every tcm a suite ran has ended, waiting up to ms for them: each says it ran (tcm-pid-<pid> in the
suite's coverage directory), and writes the code it ran there as it ends. One still running, its test having
stopped it without waiting, would be missed; one that won't end means what ran isn't known.
import fs from "node:fs"; export async function tcmsEnded(dir: string, ms: number): Promise<boolean> { const pids = fs .readdirSync(dir) .map((f) => /^tcm-pid-(\d+)$/.exec(f)?.[1]) .filter((p): p is string => !!p) .map(Number); const alive = (pid: number) => { try { process.kill(pid, 0); return true; } catch (e) { // (one that exists but isn't ours to signal is still running) return (e as NodeJS.ErrnoException).code === "EPERM"; } }; const until = Date.now() + ms; while (pids.some(alive)) { if (Date.now() > until) return false; await new Promise((r) => setTimeout(r, 50)); } return true; }