summaryrefslogtreecommitdiff
path: root/tests/runner.mjs
blob: 79bda8c74f627c012918498a1b932077fcd2ae92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { eq } from "../src/utils.mjs";

class AssertionError extends Error {}

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 t = {
	tap: x => {
		console.error("tap:", x);
		return x;
	},
	start: msg => {
		console.error(`${msg}:`);
	},
	test: (msg, fn) => {
		try {
			fn();
			console.error(`${yellow("testing")}: ${msg}... ${green("OK")}`);
		} catch (e) {
			console.error(`${yellow("testing")}: ${msg}... ${red("FAIL")}`);
			throw e;
		}
	},
};

export const runTests = async tests => {
	for (const testFn of tests) {
		await testFn(t);
	}
};