-
Notifications
You must be signed in to change notification settings - Fork 42
/
wpt.ts
70 lines (61 loc) · 1.78 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
import { walkSync } from "https://deno.land/std@0.75.0/fs/walk.ts";
import {
dirname,
fromFileUrl,
join,
} from "https://deno.land/std@0.75.0/path/mod.ts";
import { run } from "./wpt-runner.ts";
import type { Backend } from "./wpt-runner.ts";
const wptDirRoot = join(dirname(fromFileUrl(import.meta.url)), "../wpt");
const wptNodeTests = wptDirRoot + "/dom/nodes";
const wptTraversalTests = wptDirRoot + "/dom/traversal";
const wptCollectionTests = wptDirRoot + "/dom/collections";
const include = new RegExp([
"ChildNode-",
"Document-",
"Comment-",
"Element-",
"getElementsByClassName-",
"Node-",
"ParentNode-",
"Text-",
].join("|"));
const exclude = new RegExp([
"-namespace",
"TreeWalker",
"ProcessingInstruction",
"CDATA", // TODO: maybe implement CDATA support
"createEvent",
"nodes/Node-cloneNode-on-inactive-document-crash", // Tests iframe which won't be implemented
"nodes/DOMImplementation-createHTMLDocument-with-null-browsing-context-crash", // Uses iframe
].join("|"));
export function test(backend: Backend) {
// WPT tests are only explicitly run
if (!Deno.args.find((arg) => ["-w", "--wpt"].includes(arg))) {
return;
}
const testFiles: string[] = [];
const limit = Infinity;
let count = 0;
for (const testDir of [wptNodeTests]) {
for (const entry of walkSync(testDir)) {
const { path } = entry;
if (path.endsWith(".html") && include.test(path) && !exclude.test(path)) {
testFiles.push(path);
count++;
if (count === limit) {
break;
}
}
}
}
for (const test of testFiles) {
const name = test
.replace(/.+dom\//, "")
.replace(".html", "")
.replace(/\s+/g, " ");
Deno.test(name, async () => {
await run(test, wptDirRoot, backend);
});
}
}