-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunTest.ts
60 lines (53 loc) · 1.5 KB
/
runTest.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
55
56
57
58
59
60
import { emptyDir } from "../dev_deps.ts";
const watcher = Deno.watchFs([
"./src/",
"./test/",
], { recursive: true });
const runCmd = async (cmd: string[]) => {
const p = Deno.run({ cmd, stdout: "piped", stderr: "piped" });
const status = await p.status();
const output = await p.output();
const error = await p.stderrOutput();
p.close();
return {
output: new TextDecoder().decode(output),
error: new TextDecoder().decode(error),
code: status.code,
};
};
// Debounce runner
let timeout: number | undefined;
const runTest = (path: string) => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(async () => {
console.log(">>>>> runTest", path);
await emptyDir("./.coverage/");
const test = await runCmd(["deno", "test", "--allow-net", "--coverage=./.coverage", "./test/"]);
console.log(test.output);
if (test.code !== 0) {
console.log(test.error);
return;
}
const cov = await runCmd([
"deno",
"coverage",
"./.coverage/",
"--lcov",
"--exclude=/test|scripts/",
]);
await Deno.writeTextFile("./.coverage/coverageFile.lcov", cov.output);
await runCmd(["genhtml", "-o", "./.coverage/", "./.coverage/coverageFile.lcov"]);
}, 100);
};
for await (const event of watcher) {
// console.log(">>>>> event", event);
const { kind, paths } = event;
if (["modify", "create", "delete"].includes(kind) && paths[0]) {
const [path] = paths;
if (path.endsWith(".ts")) {
runTest(path);
}
}
}