blob: d273c5d26e146a58cb576a804393b5dd85b1adfb (
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
33
34
|
const isAsync = f =>
typeof f.then === 'function' &&
f[Symbol.toStringTag] === 'Promise';
const t = ({ colors, err, assert }) => ({
assert,
tap: x => {
err(`tap: ${x}\n`);
return x;
},
start: msg => {
err(`${msg}:\n`);
},
test: async (msg, fn) => {
err(`${colors.yellow("testing")}: ${msg}... `);
try {
if (isAsync(fn)) {
await fn();
} else {
fn();
}
} catch (e) {
err(`${colors.red("ERR")}.\n`);
throw e;
}
err(`${colors.green("OK")}.\n`);
},
});
export const runTests = async (conf, tests) => {
for (const testFn of tests) {
await testFn(t(conf));
}
};
|