-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-runner.ts
54 lines (46 loc) · 1.15 KB
/
test-runner.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import tape from "tape";
import glob from "glob";
import { pathToFileURL } from "url";
import dotenv from "dotenv";
dotenv.config();
const runner = (function () {
const termination = /^1\.\./;
const start = /^#/;
const failure = /^not ok/;
let current = "";
let terminated = false;
let file = "";
function error(d: string) {
if (current) {
console.error(`\n# ${file}`);
console.error(current);
}
console.error(d);
current = "";
}
function log(d: string) {
d = d.trim();
if (termination.test(d)) terminated = true;
else if (terminated) console.log(d);
else if (start.test(d)) current = d;
else if (failure.test(d)) error(d);
}
function load(f: string) {
tape("__", t => {
file = f;
t.end();
});
file = f;
return import(pathToFileURL(file).href);
}
console.log();
return { load, log };
})();
tape.createStream().on("data", d => {
runner.log(d);
});
tape("__runner__", async t => {
const files = glob.sync(process.argv[2] ?? "src/**/*.test.ts");
for (const file of files) await runner.load(file);
t.end();
});