@@ -13,17 +13,30 @@ const path = require('path');
1313const assert = require('assert');
1414const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
1515
16+ function verifyURL(url, test) {
17+ if (test.href) assert.strictEqual(url.href, test.href);
18+ if (test.origin) assert.strictEqual(url.origin, test.origin);
19+ if (test.protocol) assert.strictEqual(url.protocol, test.protocol);
20+ if (test.username) assert.strictEqual(url.username, test.username);
21+ if (test.password) assert.strictEqual(url.password, test.password);
22+ if (test.hostname) assert.strictEqual(url.hostname, test.hostname);
23+ if (test.host) assert.strictEqual(url.host, test.host);
24+ if (test.port !== undefined) assert.strictEqual(url.port, test.port);
25+ if (test.pathname) assert.strictEqual(url.pathname, test.pathname);
26+ if (test.search) assert.strictEqual(url.search, test.search);
27+ if (test.hash) assert.strictEqual(url.hash, test.hash);
28+ }
29+
1630for (const test of tests) {
1731 if (typeof test === 'string')
1832 continue;
1933
2034 if (test.failure) {
21- assert.throws(() => new URL(test.input, test.base), /Invalid URL/);
35+ assert.throws(() => new URL(test.input, test.base),
36+ /^TypeError: Invalid URL$/);
2237 } else {
23- assert.doesNotThrow(() => {
24- const url = new URL(test.input, test.base);
25- assert.strictEqual(url.href, test.href);
26- });
38+ const url = new URL(test.input, test.base);
39+ verifyURL(url, test);
2740 }
2841}
2942
@@ -115,18 +128,10 @@ const additional_tests = [
115128 }
116129];
117130
118- additional_tests.forEach((test) => {
119- const u = new URL(test.url);
120- if (test.protocol) assert.strictEqual(test.protocol, u.protocol);
121- if (test.username) assert.strictEqual(test.username, u.username);
122- if (test.password) assert.strictEqual(test.password, u.password);
123- if (test.hostname) assert.strictEqual(test.hostname, u.hostname);
124- if (test.host) assert.strictEqual(test.host, u.host);
125- if (test.port !== undefined) assert.strictEqual(test.port, u.port);
126- if (test.pathname) assert.strictEqual(test.pathname, u.pathname);
127- if (test.search) assert.strictEqual(test.search, u.search);
128- if (test.hash) assert.strictEqual(test.hash, u.hash);
129- });
131+ for (const test of additional_tests) {
132+ const url = new URL(test.url);
133+ verifyURL(url, test);
134+ }
130135
131136// test inspect
132137const allTests = additional_tests.slice();
0 commit comments