Skip to content

Commit ab914ed

Browse files
committed
Add new setter tests
1 parent 8a94299 commit ab914ed

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

scripts/get-latest-platform-tests.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ const request = require("request");
1515
// 1. Go to https://github.com/w3c/web-platform-tests/blob/master/url/urltestdata.json
1616
// 2. Press "y" on your keyboard to get a permalink
1717
// 3. Copy the commit hash
18-
const commitHash = "a8e267d32ff41ee2963e4ad6d8f4af5bdd414595";
18+
const commitHash = "7d202a76b90fccb246c6aaee42fa5b251e2f649e";
1919

2020
const sourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/urltestdata.json`;
21+
const setterSourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/setters_tests.json`;
2122

2223
const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");
2324

2425
request.get(sourceURL)
2526
.pipe(fs.createWriteStream(path.resolve(targetDir, "urltestdata.json")));
27+
28+
request.get(setterSourceURL)
29+
.pipe(fs.createWriteStream(path.resolve(targetDir, "setters_tests.json")));

test/web-platform.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"use strict";
22
const assert = require("assert");
33
const URL = require("..").URL;
4-
const testCases = require("./web-platform-tests/urltestdata.json");
5-
const additionalTestCases = require("./to-upstream.json");
4+
const parsingTestCases = require("./web-platform-tests/urltestdata.json");
5+
const additionalParsingTestCases = require("./to-upstream.json");
6+
const setterTestData = require("./web-platform-tests/setters_tests.json");
67

78
function testURL(expected) {
89
return () => {
@@ -32,24 +33,49 @@ function testURL(expected) {
3233
};
3334
}
3435

35-
describe("Web Platform Tests", () => {
36-
for (const expected of testCases) {
36+
function testSetterCase(testCase, propertyName) {
37+
return () => {
38+
const url = new URL(testCase.href);
39+
url[propertyName] = testCase.new_value;
40+
41+
for (const expectedProperty in testCase.expected) {
42+
assert.equal(url[expectedProperty], testCase.expected[expectedProperty]);
43+
}
44+
};
45+
}
46+
47+
describe("Web Platform Tests: parsing", () => {
48+
for (const expected of parsingTestCases) {
3749
if (typeof expected === "string") {
3850
// It's a "comment"; skip it.
3951
continue;
4052
}
4153

42-
it("Parsing: <" + expected.input + "> against <" + expected.base + ">", testURL(expected));
54+
specify(`<${expected.input}> against <${expected.base}>`, testURL(expected));
55+
}
56+
});
57+
58+
describe("Web Platform Tests: setters", () => {
59+
for (const key of Object.keys(setterTestData)) {
60+
if (key === "comment") {
61+
continue;
62+
}
63+
64+
describe(key, () => {
65+
for (const testCase of setterTestData[key]) {
66+
specify(`<${testCase.href}>.${key} = "${testCase.new_value}" ${testCase.comment || ""}`, testSetterCase(testCase, key));
67+
}
68+
});
4369
}
4470
});
4571

46-
describe("To-upstream tests", () => {
47-
for (const expected of additionalTestCases) {
72+
describe("To-upstream tests: parsing", () => {
73+
for (const expected of additionalParsingTestCases) {
4874
if (typeof expected === "string") {
4975
// It's a "comment"; skip it.
5076
continue;
5177
}
5278

53-
it("Parsing: <" + expected.input + "> against <" + expected.base + ">", testURL(expected));
79+
specify("<" + expected.input + "> against <" + expected.base + ">", testURL(expected));
5480
}
5581
});

0 commit comments

Comments
 (0)