Skip to content

Commit 0a2e377

Browse files
committed
Overhaul the test runner
This allows us to catch up to recent changes in web-platform-tests/wpt#39203. To reduce the maintenance burden, this rewrites the test runner to be focused on, as much as possible, reusing upstream runner code. For three files this is not possible, and those are explicitly called out.
1 parent 423b9fa commit 0a2e377

File tree

4 files changed

+174
-283
lines changed

4 files changed

+174
-283
lines changed

scripts/get-latest-platform-tests.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ process.on("unhandledRejection", err => {
1818
// 1. Go to https://github.com/web-platform-tests/wpt/tree/master/url
1919
// 2. Press "y" on your keyboard to get a permalink
2020
// 3. Copy the commit hash
21-
const commitHash = "c95d15338d3d4380beffb8b1b8dda62a8d746ab9";
21+
const commitHash = "6d461b4ddb2f1b8d226ca6ae92e14bbd464731a5";
2222

2323
const urlPrefix = `https://raw.githubusercontent.com/web-platform-tests/wpt/${commitHash}/url/`;
2424
const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");
2525

26-
(fs.rmSync || fs.rmdirSync)(targetDir, { recursive: true, force: true });
27-
fs.mkdirSync(path.resolve(targetDir, "resources"), { recursive: true });
28-
29-
for (const file of [
26+
// These resources we download, but the test runner doesn't need to know about them.
27+
const resources = [
3028
"resources/percent-encoding.json",
3129
"resources/setters_tests.json",
3230
"resources/toascii.json",
3331
"resources/urltestdata.json",
34-
"resources/IdnaTestV2.json",
32+
"resources/IdnaTestV2.json"
33+
];
34+
35+
// These tests we can download and run directly in /test/web-platform.js.
36+
exports.directlyRunnableTests = [
3537
"url-searchparams.any.js",
3638
"url-setters-stripping.any.js",
3739
"url-tojson.any.js",
@@ -46,8 +48,31 @@ for (const file of [
4648
"urlsearchparams-set.any.js",
4749
"urlsearchparams-sort.any.js",
4850
"urlsearchparams-stringifier.any.js"
49-
]) {
50-
fetch(`${urlPrefix}${file}`).then(res => {
51-
res.body.pipe(fs.createWriteStream(path.resolve(targetDir, file)));
52-
});
51+
];
52+
53+
// These tests need some special handling in /test/web-platform.js, since they need to be hooked up to their resource
54+
// files in a case-by-case way. We still download them, but they're in a separately-exported array so that the runner
55+
// can distinguish.
56+
exports.resourceDependentTests = [
57+
"IdnaTestV2.window.js",
58+
"url-constructor.any.js",
59+
"url-origin.any.js",
60+
"url-setters.any.js"
61+
];
62+
63+
// These tests need their logic duplicated in /test/web-platform.js, because we can't easly shim them. They are not
64+
// downloaded, but we list them here so that it's easy to understand our categorization scheme.
65+
// - failure.html
66+
// - percent-encoding.window.js
67+
// - toascii.window.js
68+
69+
if (require.main === module) {
70+
(fs.rmSync || fs.rmdirSync)(targetDir, { recursive: true, force: true });
71+
fs.mkdirSync(path.resolve(targetDir, "resources"), { recursive: true });
72+
73+
for (const file of [...resources, ...exports.directlyRunnableTests, ...exports.resourceDependentTests]) {
74+
fetch(`${urlPrefix}${file}`).then(res => {
75+
res.body.pipe(fs.createWriteStream(path.resolve(targetDir, file)));
76+
});
77+
}
5378
}

test/testharness.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ module.exports = {
3939

4040
assert_unreached() {
4141
assert(false);
42+
},
43+
44+
subsetTestByKey(key, testRunnerFunc, func, name) {
45+
// Don't do any keying stuff.
46+
testRunnerFunc(func, name);
4247
}
4348
};

test/to-upstream.json

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)