summaryrefslogtreecommitdiff
path: root/tests/node-driver.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/node-driver.js')
-rw-r--r--tests/node-driver.js43
1 files changed, 11 insertions, 32 deletions
diff --git a/tests/node-driver.js b/tests/node-driver.js
index 3393dca..5da5526 100644
--- a/tests/node-driver.js
+++ b/tests/node-driver.js
@@ -1,50 +1,29 @@
import assert from "node:assert/strict";
import process from "node:process";
+import { runTests } from "./driver.js";
+
+const err = x => process.stderr.write(x);
+
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 = {
+const conf = {
+ err,
assert,
- tap: x => {
- process.stderr.write(`tap: ${x}\n`);
- return x;
- },
- start: msg => {
- process.stderr.write(`${msg}:\n`);
+ colors: {
+ red,
+ green,
+ yellow,
},
- 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 runTests(conf, module.allTests);
};