import assert from "node:assert/strict"; import process from "node:process"; const red = s => `\x1b[31m${s}\x1b[0m`; const green = s => `\x1b[32m${s}\x1b[0m`; const yellow = s => `\x1b[33m${s}\x1b[0m`; const isAsync = f => typeof f.then === 'function' && f[Symbol.toStringTag] === 'Promise'; const t = { assert, tap: x => { process.stderr.write(`tap: ${x}\n`); return x; }, start: msg => { process.stderr.write(`${msg}:\n`); }, test: async (msg, fn) => { process.stderr.write(`${yellow("testing")}: ${msg}... `); try { if (isAsync(fn)) { await fn(); } else { fn(); } } catch (e) { process.stderr.write(`${red("ERR")}.\n}`); throw e; } process.stderr.write(`${green("OK")}.\n`); }, }; const runTests = async tests => { for (const testFn of tests) { await testFn(t); } }; const main = async (path = process.argv[2]) => { const module = await import("../" + path); await runTests(module.allTests); }; await main();