forked from jsdom/jsdom
/
run-wpts.js
177 lines (153 loc) · 5.85 KB
/
run-wpts.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"use strict";
const path = require("path");
const fs = require("fs");
const jsYAML = require("js-yaml");
const { Minimatch } = require("minimatch");
const { describe, specify, before, after } = require("mocha-sugar-free");
const { readManifest, getPossibleTestFilePaths } = require("./wpt-manifest-utils.js");
const startWPTServer = require("./start-wpt-server.js");
const { resolveReason } = require("./utils.js");
const validInnerReasons = new Set([
"fail",
"fail-with-canvas",
"needs-node10",
"needs-node11",
"needs-node12"
]);
const validReasons = new Set([
"fail",
"fail-slow",
"fail-with-canvas",
"timeout",
"flaky",
"needs-node10",
"needs-node11",
"needs-node12",
"needs-canvas"
]);
const manifestFilename = path.resolve(__dirname, "wpt-manifest.json");
const manifest = readManifest(manifestFilename);
const possibleTestFilePaths = getPossibleTestFilePaths(manifest);
const toRunFilename = path.resolve(__dirname, "to-run.yaml");
const toRunString = fs.readFileSync(toRunFilename, { encoding: "utf-8" });
const toRunDocs = jsYAML.loadAll(toRunString, null, { filename: toRunFilename, schema: jsYAML.DEFAULT_SAFE_SCHEMA });
const minimatchers = new Map();
checkToRun();
let wptServerURL, serverProcess;
const runSingleWPT = require("./run-single-wpt.js")(() => wptServerURL);
before({ timeout: 30 * 1000 }, async () => {
const { urls, subprocess } = await startWPTServer({ toUpstream: false });
wptServerURL = urls[0];
serverProcess = subprocess;
});
after(() => {
serverProcess.kill("SIGINT");
});
describe("web-platform-tests", () => {
for (const toRunDoc of toRunDocs) {
describe(toRunDoc.DIR, () => {
for (const testFilePath of possibleTestFilePaths) {
if (testFilePath.startsWith(toRunDoc.DIR + "/")) {
const matchingPattern = expectationsInDoc(toRunDoc).find(pattern => {
const matcher = minimatchers.get(toRunDoc.DIR + "/" + pattern);
return matcher.match(testFilePath);
});
const testFile = testFilePath.slice((toRunDoc.DIR + "/").length);
let reason, data;
if (matchingPattern) {
// The array case is when the failure affects the whole test file
// (ex.: testharness timeout or error, uncaught exception, etc.)
reason = toRunDoc[matchingPattern][0];
if (!Array.isArray(toRunDoc[matchingPattern])) {
// The non-array case is when some subtests in the test file pass,
// but others fail, and testharness status is OK.
data = toRunDoc[matchingPattern];
}
} else if (toRunDoc.DIR.startsWith("html/canvas/")) {
reason = "needs-canvas";
}
switch (resolveReason(reason)) {
case "skip": {
specify.skip(`[${reason}] ${testFile}`);
break;
}
case "expect-fail": {
const failReason = reason !== "fail" ? `: ${reason}` : "";
runSingleWPT(testFilePath, `[expected fail${failReason}] ${testFile}`, true);
break;
}
default: {
let failCount = 0;
if (data) {
failCount = Object.values(data)
.filter(([innerReason]) => resolveReason(innerReason) === "expect-fail").length;
}
let prefix = "";
if (failCount > 0) {
prefix = `[expected ${failCount} failure${failCount > 1 ? "s" : ""}] `;
}
runSingleWPT(testFilePath, `${prefix}${testFile}`, data || false);
}
}
}
}
});
}
});
function checkToRun() {
let lastDir = "";
for (const doc of toRunDocs) {
if (doc.DIR.startsWith("/")) {
throw new Error(`DIR entries must not start with a slash: saw "${doc.DIR}"`);
}
if (doc.DIR.endsWith("/")) {
throw new Error(`DIR entries must not end with a slash: saw "${doc.DIR}"`);
}
if (!fs.existsSync(path.resolve(__dirname, "tests", doc.DIR))) {
throw new Error(`The directory "${doc.DIR}" does not exist`);
}
if (doc.DIR < lastDir) {
throw new Error(`Bad lexicographical directory sorting in to-run.yaml: ${doc.DIR} should come before ${lastDir}`);
}
lastDir = doc.DIR;
let lastPattern = "";
for (const pattern of expectationsInDoc(doc)) {
if (pattern.startsWith("/")) {
throw new Error(`Expectation patterns must not start with a slash: saw "${pattern}"`);
}
if (pattern < lastPattern) {
throw new Error("Bad lexicographical expectation pattern sorting in to-run.yaml: " + pattern +
" should come before " + lastPattern);
}
lastPattern = pattern;
const data = doc[pattern];
if (Array.isArray(data)) {
const reason = data[0];
if (!validReasons.has(reason)) {
throw new Error(`Bad reason "${reason}" for expectation "${pattern}"`);
}
} else {
for (const [subtest, [innerReason]] of Object.entries(data)) {
if (!validInnerReasons.has(innerReason)) {
if (!validReasons.has(innerReason)) {
throw new Error(`Bad reason "${innerReason}" for expectation "${pattern}" and subtest "${subtest}"`);
} else {
throw new Error(`Reason "${innerReason}" is only supported for files, not subtests (expectation "${
pattern}", subtest "${subtest}")`);
}
}
}
}
const matcher = new Minimatch(doc.DIR + "/" + pattern);
if (!possibleTestFilePaths.some(filename => matcher.match(filename))) {
throw new Error(`Expectation pattern "${pattern}" does not match any test files`);
}
minimatchers.set(doc.DIR + "/" + pattern, matcher);
}
}
}
function expectationsInDoc(doc) {
const keys = Object.keys(doc);
keys.shift(); // get rid of the DIR key
return keys;
}