summaryrefslogtreecommitdiff
path: root/test/parallel/test-whatwg-url-custom-parsing.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-08-22 03:27:56 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-08-25 08:57:23 +0800
commit6dd694c1257ded6d8a9f3b48e8c9027c3986a285 (patch)
tree4c37b2936495c352676be7caaff33c9cb89c7ab8 /test/parallel/test-whatwg-url-custom-parsing.js
parent16cffb0d4890bf4b4ff8ad0bbd7731105fabe845 (diff)
downloadandroid-node-v8-6dd694c1257ded6d8a9f3b48e8c9027c3986a285.tar.gz
android-node-v8-6dd694c1257ded6d8a9f3b48e8c9027c3986a285.tar.bz2
android-node-v8-6dd694c1257ded6d8a9f3b48e8c9027c3986a285.zip
test: move custom WHATWG URL tests into separate files
To enable automatic update of WPT, move all our custom WHATWG URL tests that are not present in the upstream into files starting with `test-whatwg-url-custom-`, so it's easier to identify test cases that can be upstreamed and test cases that should be rolled into our repo (possibly with automation). PR-URL: https://github.com/nodejs/node/pull/22442 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'test/parallel/test-whatwg-url-custom-parsing.js')
-rw-r--r--test/parallel/test-whatwg-url-custom-parsing.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/test/parallel/test-whatwg-url-custom-parsing.js b/test/parallel/test-whatwg-url-custom-parsing.js
new file mode 100644
index 0000000000..252e35c8d3
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-parsing.js
@@ -0,0 +1,85 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+if (!common.hasIntl) {
+ // A handful of the tests fail when ICU is not included.
+ common.skip('missing Intl');
+}
+
+const URL = require('url').URL;
+const assert = require('assert');
+const fixtures = require('../common/fixtures');
+
+const tests = require(fixtures.path('url-tests'));
+
+const originalFailures = tests.filter((test) => test.failure);
+
+const typeFailures = [
+ { input: '' },
+ { input: 'test' },
+ { input: undefined },
+ { input: 0 },
+ { input: true },
+ { input: false },
+ { input: null },
+ { input: new Date() },
+ { input: new RegExp() },
+ { input: 'test', base: null },
+ { input: 'http://nodejs.org', base: null },
+ { input: () => {} }
+];
+
+// See https://github.com/w3c/web-platform-tests/pull/10955
+// > If `failure` is true, parsing `about:blank` against `base`
+// > must give failure. This tests that the logic for converting
+// > base URLs into strings properly fails the whole parsing
+// > algorithm if the base URL cannot be parsed.
+const aboutBlankFailures = originalFailures
+ .map((test) => ({
+ input: 'about:blank',
+ base: test.input,
+ failure: true
+ }));
+
+const failureTests = originalFailures
+ .concat(typeFailures)
+ .concat(aboutBlankFailures);
+
+const expectedError = common.expectsError(
+ { code: 'ERR_INVALID_URL', type: TypeError }, failureTests.length);
+
+for (const test of failureTests) {
+ assert.throws(
+ () => new URL(test.input, test.base),
+ (error) => {
+ if (!expectedError(error))
+ return false;
+
+ // The input could be processed, so we don't do strict matching here
+ const match = (`${error}`).match(/Invalid URL: (.*)$/);
+ if (!match) {
+ return false;
+ }
+ return error.input === match[1];
+ });
+}
+
+const additional_tests =
+ require(fixtures.path('url-tests-additional.js'));
+
+for (const test of additional_tests) {
+ const url = new URL(test.url);
+ if (test.href) assert.strictEqual(url.href, test.href);
+ if (test.origin) assert.strictEqual(url.origin, test.origin);
+ if (test.protocol) assert.strictEqual(url.protocol, test.protocol);
+ if (test.username) assert.strictEqual(url.username, test.username);
+ if (test.password) assert.strictEqual(url.password, test.password);
+ if (test.hostname) assert.strictEqual(url.hostname, test.hostname);
+ if (test.host) assert.strictEqual(url.host, test.host);
+ if (test.port !== undefined) assert.strictEqual(url.port, test.port);
+ if (test.pathname) assert.strictEqual(url.pathname, test.pathname);
+ if (test.search) assert.strictEqual(url.search, test.search);
+ if (test.hash) assert.strictEqual(url.hash, test.hash);
+}