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.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/node-driver.js b/tests/node-driver.js
new file mode 100644
index 0000000..3393dca
--- /dev/null
+++ b/tests/node-driver.js
@@ -0,0 +1,52 @@
+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();