1
0
forked from rosa/hakurei

cmd/pkgserver: expose verbose StreamReporter flag via CLI

This commit is contained in:
Kat
2026-03-22 05:15:58 +11:00
parent 1ab3b697e5
commit 8541fdd1f4

View File

@@ -1,7 +1,46 @@
#!/usr/bin/env node
// Many editors have terminal emulators built in, so running tests with NodeJS
// provides faster iteration, especially for those acclimated to test-driven
// development.
import "./all_tests.js";
import { StreamReporter, TESTS } from "./test.js";
TESTS.run(new StreamReporter({ writeln: console.log }));
// TypeScript doesn't like process and Deno as their type definitions aren't
// installed, but doesn't seem to complain if they're accessed through
// globalThis.
const process: any = globalThis.process;
const Deno: any = globalThis.Deno;
function getArgs(): string[] {
if (process) {
const [runtime, program, ...args] = process.argv;
return args;
}
if (Deno) return Deno.args;
return [];
}
function exit(code?: number): never {
if (Deno) Deno.exit(code);
if (process) process.exit(code);
throw `exited with code ${code ?? 0}`;
}
const args = getArgs();
let verbose = false;
if (args.length > 1) {
console.error("Too many arguments");
exit(1);
}
if (args.length === 1) {
if (args[0] === "-v" || args[0] === "--verbose" || args[0] === "-verbose") {
verbose = true;
} else if (args[0] !== "--") {
console.error(`Unknown argument '${args[0]}'`);
exit(1);
}
}
TESTS.run(new StreamReporter({ writeln: console.log }, verbose));