-
Notifications
You must be signed in to change notification settings - Fork 2
/
wpt.ts
82 lines (68 loc) · 2 KB
/
wpt.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { readJson } from "./deps.ts";
import { runTests } from "./lib/runner.ts";
import build from "./build.ts";
const ignore = await readJson("./ignore.json") as string[];
console.log(`use deno version: ${Deno.version.deno}`);
const decoder = new TextDecoder("utf-8");
async function main() {
switch (Deno.args[0]) {
case "serve":
const p = Deno.run({
cmd: [
"deno",
"run",
"--allow-net",
"--allow-read",
"https://deno.land/std/http/file_server.ts",
],
stdout: "inherit",
});
await p.status();
break;
case "run":
const specs = [];
for await (const dirEntry of Deno.readDir("./spec")) {
specs.push(dirEntry);
}
const specsSorted = specs.sort((x, y) => x.name! > y.name! ? 1 : -1);
for (const spec of specsSorted) {
if (!spec.isDirectory || ignore.includes(spec.name!)) {
console.log(spec.name);
continue;
}
const specPath = `./spec/${spec.name}`;
const files: Deno.DirEntry[] = [];
for await (const dirEntry of Deno.readDir(specPath)) {
if (dirEntry.name!.substr(-7) === ".any.js") {
files.push(dirEntry);
}
}
for (const file of files) {
const filePath = `./spec/${spec.name}/${file.name}`;
const content = await Deno.readFile(filePath);
const code: string = decoder.decode(content);
setup(`${spec.name}›${file.name}›`);
eval(code);
}
}
runTests(true);
break;
case "test":
if (!Deno.args[1]) {
console.log("Please input a file name. Usage: wpt test <filename>");
Deno.exit(1);
}
const content = await Deno.readFile(Deno.args[1]);
const code: string = decoder.decode(content);
setup();
eval(code);
runTests(false);
break;
case "build":
await build();
break;
default:
console.log(Deno.args);
}
}
main();