@sondr3/minitest
Version:
A low-feature, dependency-free and performant test runner inspired by Rust and Deno
50 lines • 1.26 kB
JavaScript
import { color } from "./utils.js";
export class TestRunner {
name;
fn;
ignore = false;
only = false;
success = false;
error = undefined;
constructor(name, fn, ignore, only) {
this.name = name;
this.fn = fn;
this.ignore = ignore;
this.only = only;
}
async run() {
if (this.ignore) {
this.success = true;
return this.success;
}
try {
await this.fn();
this.success = true;
}
catch (e) {
this.success = false;
this.error = e instanceof Error ? e : undefined;
}
return this.success;
}
result(quiet = false) {
if (this.ignore) {
this.report("i", color("ignored", "yellow"), quiet);
}
else if (this.success) {
this.report(".", color("ok", "green"), quiet);
}
else {
this.report("F", color("FAILED", "red"), quiet);
}
}
report(short, long, quiet) {
if (quiet) {
process.stdout.write(`${short}`);
}
else {
process.stdout.write(`test ${this.name} ... ${long}\n`);
}
}
}
//# sourceMappingURL=test_runner.js.map