MCPcopy Create free account
hub / github.com/nodejs/node / runURLTests

Function runURLTests

test/fixtures/wpt/url/url-constructor.any.js:8–51  ·  view source on GitHub ↗
(urlTests)

Source from the content-addressed store, hash-verified

6// META: variant=?exclude=(file|javascript|mailto)
7
8function runURLTests(urlTests) {
9 for (const expected of urlTests) {
10 // Skip comments
11 if (typeof expected === "string")
12 continue;
13
14 const base = expected.base !== null ? expected.base : undefined;
15
16 function getKey(expected) {
17 if (expected.protocol) {
18 return expected.protocol.replace(":", "");
19 }
20 if (expected.failure) {
21 return expected.input.split(":")[0];
22 }
23 return "other";
24 }
25
26 subsetTestByKey(getKey(expected), test, function() {
27 if (expected.failure) {
28 assert_throws_js(TypeError, function() {
29 new URL(expected.input, base);
30 });
31 return;
32 }
33
34 const url = new URL(expected.input, base);
35 assert_equals(url.href, expected.href, "href")
36 assert_equals(url.protocol, expected.protocol, "protocol")
37 assert_equals(url.username, expected.username, "username")
38 assert_equals(url.password, expected.password, "password")
39 assert_equals(url.host, expected.host, "host")
40 assert_equals(url.hostname, expected.hostname, "hostname")
41 assert_equals(url.port, expected.port, "port")
42 assert_equals(url.pathname, expected.pathname, "pathname")
43 assert_equals(url.search, expected.search, "search")
44 if ("searchParams" in expected) {
45 assert_true("searchParams" in url)
46 assert_equals(url.searchParams.toString(), expected.searchParams, "searchParams")
47 }
48 assert_equals(url.hash, expected.hash, "hash")
49 }, `Parsing: <${expected.input}> ${base ? "against <" + base + ">" : "without base"}`)
50 }
51}
52
53promise_test(() => Promise.all([
54 fetch("resources/urltestdata.json").then(res => res.json()),

Callers

nothing calls this directly

Calls 6

subsetTestByKeyFunction · 0.85
getKeyFunction · 0.70
assert_throws_jsFunction · 0.50
assert_equalsFunction · 0.50
assert_trueFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected