aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--test/parallel/test-whatwg-url-custom-domainto.js (renamed from test/parallel/test-whatwg-url-domainto.js)8
-rw-r--r--test/parallel/test-whatwg-url-custom-global.js (renamed from test/parallel/test-whatwg-url-global.js)2
-rw-r--r--test/parallel/test-whatwg-url-custom-inspect.js (renamed from test/parallel/test-whatwg-url-inspect.js)3
-rw-r--r--test/parallel/test-whatwg-url-custom-parsing.js (renamed from test/parallel/test-whatwg-url-parsing.js)3
-rw-r--r--test/parallel/test-whatwg-url-custom-properties.js (renamed from test/parallel/test-whatwg-url-properties.js)3
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-append.js37
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-constructor.js69
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-delete.js46
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-entries.js (renamed from test/parallel/test-whatwg-url-searchparams-entries.js)0
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-foreach.js17
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-get.js34
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-getall.js34
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-has.js34
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-inspect.js (renamed from test/parallel/test-whatwg-url-searchparams-inspect.js)3
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-keys.js (renamed from test/parallel/test-whatwg-url-searchparams-keys.js)3
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-set.js37
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-sort.js47
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-stringifier.js17
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-values.js (renamed from test/parallel/test-whatwg-url-searchparams-values.js)3
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams.js (renamed from test/parallel/test-whatwg-url-searchparams.js)3
-rw-r--r--test/parallel/test-whatwg-url-custom-setters.js60
-rw-r--r--test/parallel/test-whatwg-url-custom-tostringtag.js (renamed from test/parallel/test-whatwg-url-tostringtag.js)3
-rw-r--r--test/parallel/test-whatwg-url-searchparams-append.js34
-rw-r--r--test/parallel/test-whatwg-url-searchparams-constructor.js66
-rw-r--r--test/parallel/test-whatwg-url-searchparams-delete.js43
-rw-r--r--test/parallel/test-whatwg-url-searchparams-foreach.js14
-rw-r--r--test/parallel/test-whatwg-url-searchparams-get.js31
-rw-r--r--test/parallel/test-whatwg-url-searchparams-getall.js31
-rw-r--r--test/parallel/test-whatwg-url-searchparams-has.js31
-rw-r--r--test/parallel/test-whatwg-url-searchparams-set.js34
-rw-r--r--test/parallel/test-whatwg-url-searchparams-sort.js42
-rw-r--r--test/parallel/test-whatwg-url-searchparams-stringifier.js14
-rw-r--r--test/parallel/test-whatwg-url-setters.js49
33 files changed, 464 insertions, 391 deletions
diff --git a/test/parallel/test-whatwg-url-domainto.js b/test/parallel/test-whatwg-url-custom-domainto.js
index fae9f800c7..556a3ff841 100644
--- a/test/parallel/test-whatwg-url-domainto.js
+++ b/test/parallel/test-whatwg-url-custom-domainto.js
@@ -1,4 +1,7 @@
'use strict';
+
+// Tests below are not from WPT.
+
const common = require('../common');
if (!common.hasIntl)
@@ -7,9 +10,8 @@ if (!common.hasIntl)
const assert = require('assert');
const { domainToASCII, domainToUnicode } = require('url');
-// Tests below are not from WPT.
-const tests = require('../fixtures/url-idna.js');
-const wptToASCIITests = require('../fixtures/url-toascii.js');
+const tests = require('../fixtures/url-idna');
+const wptToASCIITests = require('../fixtures/url-toascii');
{
const expectedError = common.expectsError(
diff --git a/test/parallel/test-whatwg-url-global.js b/test/parallel/test-whatwg-url-custom-global.js
index b4e85a49ad..c79723f049 100644
--- a/test/parallel/test-whatwg-url-global.js
+++ b/test/parallel/test-whatwg-url-custom-global.js
@@ -1,5 +1,7 @@
'use strict';
+// Tests below are not from WPT.
+
require('../common');
const assert = require('assert');
const { URL, URLSearchParams } = require('url');
diff --git a/test/parallel/test-whatwg-url-inspect.js b/test/parallel/test-whatwg-url-custom-inspect.js
index 1265428d4c..1083866d86 100644
--- a/test/parallel/test-whatwg-url-inspect.js
+++ b/test/parallel/test-whatwg-url-custom-inspect.js
@@ -1,5 +1,7 @@
'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.
@@ -10,7 +12,6 @@ const util = require('util');
const URL = require('url').URL;
const assert = require('assert');
-// Tests below are not from WPT.
const url = new URL('https://username:password@host.name:8080/path/name/?que=ry#hash');
assert.strictEqual(
diff --git a/test/parallel/test-whatwg-url-parsing.js b/test/parallel/test-whatwg-url-custom-parsing.js
index fd8570eb72..252e35c8d3 100644
--- a/test/parallel/test-whatwg-url-parsing.js
+++ b/test/parallel/test-whatwg-url-custom-parsing.js
@@ -1,5 +1,7 @@
'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.
@@ -10,7 +12,6 @@ const URL = require('url').URL;
const assert = require('assert');
const fixtures = require('../common/fixtures');
-// Tests below are not from WPT.
const tests = require(fixtures.path('url-tests'));
const originalFailures = tests.filter((test) => test.failure);
diff --git a/test/parallel/test-whatwg-url-properties.js b/test/parallel/test-whatwg-url-custom-properties.js
index 230315a70e..4a35215bc4 100644
--- a/test/parallel/test-whatwg-url-properties.js
+++ b/test/parallel/test-whatwg-url-custom-properties.js
@@ -1,12 +1,13 @@
// Flags: --expose-internals
'use strict';
+// Tests below are not from WPT.
+
require('../common');
const URL = require('url').URL;
const assert = require('assert');
const urlToOptions = require('internal/url').urlToOptions;
-// Tests below are not from WPT.
const url = new URL('http://user:pass@foo.bar.com:21/aaa/zzz?l=24#test');
const oldParams = url.searchParams; // for test of [SameObject]
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-append.js b/test/parallel/test-whatwg-url-custom-searchparams-append.js
new file mode 100644
index 0000000000..e5d3f20358
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-append.js
@@ -0,0 +1,37 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const assert = require('assert');
+const URLSearchParams = require('url').URLSearchParams;
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.append.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+ common.expectsError(() => {
+ params.append('a');
+ }, {
+ code: 'ERR_MISSING_ARGS',
+ type: TypeError,
+ message: 'The "name" and "value" arguments must be specified'
+ });
+
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ assert.throws(() => params.set(obj, 'b'), /^Error: toString$/);
+ assert.throws(() => params.set('a', obj), /^Error: toString$/);
+ assert.throws(() => params.set(sym, 'b'),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+ assert.throws(() => params.set('a', sym),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-constructor.js b/test/parallel/test-whatwg-url-custom-searchparams-constructor.js
new file mode 100644
index 0000000000..fd7cc51127
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-constructor.js
@@ -0,0 +1,69 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const assert = require('assert');
+const URLSearchParams = require('url').URLSearchParams;
+
+function makeIterableFunc(array) {
+ return Object.assign(() => {}, {
+ [Symbol.iterator]() {
+ return array[Symbol.iterator]();
+ }
+ });
+}
+
+{
+ const iterableError = common.expectsError({
+ code: 'ERR_ARG_NOT_ITERABLE',
+ type: TypeError,
+ message: 'Query pairs must be iterable'
+ });
+ const tupleError = common.expectsError({
+ code: 'ERR_INVALID_TUPLE',
+ type: TypeError,
+ message: 'Each query pair must be an iterable [name, value] tuple'
+ }, 6);
+
+ let params;
+ params = new URLSearchParams(undefined);
+ assert.strictEqual(params.toString(), '');
+ params = new URLSearchParams(null);
+ assert.strictEqual(params.toString(), '');
+ params = new URLSearchParams(
+ makeIterableFunc([['key', 'val'], ['key2', 'val2']])
+ );
+ assert.strictEqual(params.toString(), 'key=val&key2=val2');
+ params = new URLSearchParams(
+ makeIterableFunc([['key', 'val'], ['key2', 'val2']].map(makeIterableFunc))
+ );
+ assert.strictEqual(params.toString(), 'key=val&key2=val2');
+ assert.throws(() => new URLSearchParams([[1]]), tupleError);
+ assert.throws(() => new URLSearchParams([[1, 2, 3]]), tupleError);
+ assert.throws(() => new URLSearchParams({ [Symbol.iterator]: 42 }),
+ iterableError);
+ assert.throws(() => new URLSearchParams([{}]), tupleError);
+ assert.throws(() => new URLSearchParams(['a']), tupleError);
+ assert.throws(() => new URLSearchParams([null]), tupleError);
+ assert.throws(() => new URLSearchParams([{ [Symbol.iterator]: 42 }]),
+ tupleError);
+}
+
+{
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ const toStringError = /^Error: toString$/;
+ const symbolError = /^TypeError: Cannot convert a Symbol value to a string$/;
+
+ assert.throws(() => new URLSearchParams({ a: obj }), toStringError);
+ assert.throws(() => new URLSearchParams([['a', obj]]), toStringError);
+ assert.throws(() => new URLSearchParams(sym), symbolError);
+ assert.throws(() => new URLSearchParams({ [sym]: 'a' }), symbolError);
+ assert.throws(() => new URLSearchParams({ a: sym }), symbolError);
+ assert.throws(() => new URLSearchParams([[sym, 'a']]), symbolError);
+ assert.throws(() => new URLSearchParams([['a', sym]]), symbolError);
+}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-delete.js b/test/parallel/test-whatwg-url-custom-searchparams-delete.js
new file mode 100644
index 0000000000..a22345cc6e
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-delete.js
@@ -0,0 +1,46 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const assert = require('assert');
+const { URL, URLSearchParams } = require('url');
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.delete.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+ common.expectsError(() => {
+ params.delete();
+ }, {
+ code: 'ERR_MISSING_ARGS',
+ type: TypeError,
+ message: 'The "name" argument must be specified'
+ });
+
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ assert.throws(() => params.delete(obj), /^Error: toString$/);
+ assert.throws(() => params.delete(sym),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+}
+
+// https://github.com/nodejs/node/issues/10480
+// Emptying searchParams should correctly update url's query
+{
+ const url = new URL('http://domain?var=1&var=2&var=3');
+ for (const param of url.searchParams.keys()) {
+ url.searchParams.delete(param);
+ }
+ assert.strictEqual(url.searchParams.toString(), '');
+ assert.strictEqual(url.search, '');
+ assert.strictEqual(url.href, 'http://domain/');
+}
diff --git a/test/parallel/test-whatwg-url-searchparams-entries.js b/test/parallel/test-whatwg-url-custom-searchparams-entries.js
index fc30865458..fc30865458 100644
--- a/test/parallel/test-whatwg-url-searchparams-entries.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-entries.js
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-foreach.js b/test/parallel/test-whatwg-url-custom-searchparams-foreach.js
new file mode 100644
index 0000000000..3e729d2bcd
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-foreach.js
@@ -0,0 +1,17 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const { URLSearchParams } = require('url');
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.forEach.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-get.js b/test/parallel/test-whatwg-url-custom-searchparams-get.js
new file mode 100644
index 0000000000..b99a5fae97
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-get.js
@@ -0,0 +1,34 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const assert = require('assert');
+const URLSearchParams = require('url').URLSearchParams;
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.get.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+ common.expectsError(() => {
+ params.get();
+ }, {
+ code: 'ERR_MISSING_ARGS',
+ type: TypeError,
+ message: 'The "name" argument must be specified'
+ });
+
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ assert.throws(() => params.get(obj), /^Error: toString$/);
+ assert.throws(() => params.get(sym),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-getall.js b/test/parallel/test-whatwg-url-custom-searchparams-getall.js
new file mode 100644
index 0000000000..7f3c7b7610
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-getall.js
@@ -0,0 +1,34 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const assert = require('assert');
+const URLSearchParams = require('url').URLSearchParams;
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.getAll.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+ common.expectsError(() => {
+ params.getAll();
+ }, {
+ code: 'ERR_MISSING_ARGS',
+ type: TypeError,
+ message: 'The "name" argument must be specified'
+ });
+
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ assert.throws(() => params.getAll(obj), /^Error: toString$/);
+ assert.throws(() => params.getAll(sym),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-has.js b/test/parallel/test-whatwg-url-custom-searchparams-has.js
new file mode 100644
index 0000000000..2697f199bc
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-has.js
@@ -0,0 +1,34 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const assert = require('assert');
+const URLSearchParams = require('url').URLSearchParams;
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.has.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+ common.expectsError(() => {
+ params.has();
+ }, {
+ code: 'ERR_MISSING_ARGS',
+ type: TypeError,
+ message: 'The "name" argument must be specified'
+ });
+
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ assert.throws(() => params.has(obj), /^Error: toString$/);
+ assert.throws(() => params.has(sym),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+}
diff --git a/test/parallel/test-whatwg-url-searchparams-inspect.js b/test/parallel/test-whatwg-url-custom-searchparams-inspect.js
index f2493cc6cf..6cc22caea6 100644
--- a/test/parallel/test-whatwg-url-searchparams-inspect.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-inspect.js
@@ -1,11 +1,12 @@
'use strict';
+// Tests below are not from WPT.
+
require('../common');
const assert = require('assert');
const util = require('util');
const URLSearchParams = require('url').URLSearchParams;
-// Tests below are not from WPT.
const sp = new URLSearchParams('?a=a&b=b&b=c');
assert.strictEqual(util.inspect(sp),
"URLSearchParams { 'a' => 'a', 'b' => 'b', 'b' => 'c' }");
diff --git a/test/parallel/test-whatwg-url-searchparams-keys.js b/test/parallel/test-whatwg-url-custom-searchparams-keys.js
index e4428eb3e9..00800cc79c 100644
--- a/test/parallel/test-whatwg-url-searchparams-keys.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-keys.js
@@ -1,10 +1,11 @@
'use strict';
+// Tests below are not from WPT.
+
const common = require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
-// Tests below are not from WPT.
const params = new URLSearchParams('a=b&c=d');
const keys = params.keys();
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-set.js b/test/parallel/test-whatwg-url-custom-searchparams-set.js
new file mode 100644
index 0000000000..ccd3353ecd
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-set.js
@@ -0,0 +1,37 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const assert = require('assert');
+const URLSearchParams = require('url').URLSearchParams;
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.set.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+ common.expectsError(() => {
+ params.set('a');
+ }, {
+ code: 'ERR_MISSING_ARGS',
+ type: TypeError,
+ message: 'The "name" and "value" arguments must be specified'
+ });
+
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ assert.throws(() => params.append(obj, 'b'), /^Error: toString$/);
+ assert.throws(() => params.append('a', obj), /^Error: toString$/);
+ assert.throws(() => params.append(sym, 'b'),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+ assert.throws(() => params.append('a', sym),
+ /^TypeError: Cannot convert a Symbol value to a string$/);
+}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-sort.js b/test/parallel/test-whatwg-url-custom-searchparams-sort.js
new file mode 100644
index 0000000000..f8884a7e70
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-sort.js
@@ -0,0 +1,47 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+require('../common');
+const { URL, URLSearchParams } = require('url');
+const { test, assert_array_equals } = require('../common/wpt');
+
+// Test bottom-up iterative stable merge sort
+const tests = [{ input: '', output: [] }];
+const pairs = [];
+for (let i = 10; i < 100; i++) {
+ pairs.push([`a${i}`, 'b']);
+ tests[0].output.push([`a${i}`, 'b']);
+}
+tests[0].input = pairs.sort(() => Math.random() > 0.5)
+ .map((pair) => pair.join('=')).join('&');
+
+tests.push(
+ {
+ 'input': 'z=a&=b&c=d',
+ 'output': [['', 'b'], ['c', 'd'], ['z', 'a']]
+ }
+);
+
+tests.forEach((val) => {
+ test(() => {
+ const params = new URLSearchParams(val.input);
+ let i = 0;
+ params.sort();
+ for (const param of params) {
+ assert_array_equals(param, val.output[i]);
+ i++;
+ }
+ }, `Parse and sort: ${val.input}`);
+
+ test(() => {
+ const url = new URL(`?${val.input}`, 'https://example/');
+ url.searchParams.sort();
+ const params = new URLSearchParams(url.search);
+ let i = 0;
+ for (const param of params) {
+ assert_array_equals(param, val.output[i]);
+ i++;
+ }
+ }, `URL parse and sort: ${val.input}`);
+});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js b/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js
new file mode 100644
index 0000000000..d2929ae557
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js
@@ -0,0 +1,17 @@
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+const URLSearchParams = require('url').URLSearchParams;
+
+{
+ const params = new URLSearchParams();
+ common.expectsError(() => {
+ params.toString.call(undefined);
+ }, {
+ code: 'ERR_INVALID_THIS',
+ type: TypeError,
+ message: 'Value of "this" must be of type URLSearchParams'
+ });
+}
diff --git a/test/parallel/test-whatwg-url-searchparams-values.js b/test/parallel/test-whatwg-url-custom-searchparams-values.js
index e44b7f5e11..e10a9dc04f 100644
--- a/test/parallel/test-whatwg-url-searchparams-values.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-values.js
@@ -1,10 +1,11 @@
'use strict';
+// Tests below are not from WPT.
+
const common = require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
-// Tests below are not from WPT.
const params = new URLSearchParams('a=b&c=d');
const values = params.values();
diff --git a/test/parallel/test-whatwg-url-searchparams.js b/test/parallel/test-whatwg-url-custom-searchparams.js
index 0b72c08d0b..f88c3b4a83 100644
--- a/test/parallel/test-whatwg-url-searchparams.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams.js
@@ -1,11 +1,12 @@
'use strict';
+// Tests below are not from WPT.
+
const common = require('../common');
const assert = require('assert');
const { URL, URLSearchParams } = require('url');
const fixtures = require('../common/fixtures');
-// Tests below are not from WPT.
const serialized = 'a=a&a=1&a=true&a=undefined&a=null&a=%EF%BF%BD' +
'&a=%EF%BF%BD&a=%F0%9F%98%80&a=%EF%BF%BD%EF%BF%BD' +
'&a=%5Bobject+Object%5D';
diff --git a/test/parallel/test-whatwg-url-custom-setters.js b/test/parallel/test-whatwg-url-custom-setters.js
new file mode 100644
index 0000000000..99b4361831
--- /dev/null
+++ b/test/parallel/test-whatwg-url-custom-setters.js
@@ -0,0 +1,60 @@
+'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 assert = require('assert');
+const URL = require('url').URL;
+const { test, assert_equals } = require('../common/wpt');
+const fixtures = require('../common/fixtures');
+
+const additionalTestCases =
+ require(fixtures.path('url-setter-tests-additional.js'));
+
+{
+ for (const attributeToBeSet in additionalTestCases) {
+ if (attributeToBeSet === 'comment') {
+ continue;
+ }
+ const testCases = additionalTestCases[attributeToBeSet];
+ for (const testCase of testCases) {
+ let name = `Setting <${testCase.href}>.${attributeToBeSet}` +
+ ` = "${testCase.new_value}"`;
+ if ('comment' in testCase) {
+ name += ` ${testCase.comment}`;
+ }
+ test(function() {
+ const url = new URL(testCase.href);
+ url[attributeToBeSet] = testCase.new_value;
+ for (const attribute in testCase.expected) {
+ assert_equals(url[attribute], testCase.expected[attribute]);
+ }
+ }, `URL: ${name}`);
+ }
+ }
+}
+
+{
+ const url = new URL('http://example.com/');
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ const props = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(url));
+ for (const [name, { set }] of Object.entries(props)) {
+ if (set) {
+ assert.throws(() => url[name] = obj,
+ /^Error: toString$/,
+ `url.${name} = { toString() { throw ... } }`);
+ assert.throws(() => url[name] = sym,
+ /^TypeError: Cannot convert a Symbol value to a string$/,
+ `url.${name} = ${String(sym)}`);
+ }
+ }
+}
diff --git a/test/parallel/test-whatwg-url-tostringtag.js b/test/parallel/test-whatwg-url-custom-tostringtag.js
index c352503fa0..784a3ebc77 100644
--- a/test/parallel/test-whatwg-url-tostringtag.js
+++ b/test/parallel/test-whatwg-url-custom-tostringtag.js
@@ -1,10 +1,11 @@
'use strict';
+// Tests below are not from WPT.
+
require('../common');
const assert = require('assert');
const URL = require('url').URL;
-// Tests below are not from WPT.
const toString = Object.prototype.toString;
const url = new URL('http://example.org');
diff --git a/test/parallel/test-whatwg-url-searchparams-append.js b/test/parallel/test-whatwg-url-searchparams-append.js
index 03e7205fb2..342cbd5335 100644
--- a/test/parallel/test-whatwg-url-searchparams-append.js
+++ b/test/parallel/test-whatwg-url-searchparams-append.js
@@ -1,7 +1,6 @@
'use strict';
-const common = require('../common');
-const assert = require('assert');
+require('../common');
const URLSearchParams = require('url').URLSearchParams;
const { test, assert_equals, assert_true } = require('../common/wpt');
@@ -48,34 +47,3 @@ test(function() {
assert_equals(params.get('first'), '1', 'Search params object has name "first" with value "1"');
}, 'Append multiple');
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.append.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
- common.expectsError(() => {
- params.append('a');
- }, {
- code: 'ERR_MISSING_ARGS',
- type: TypeError,
- message: 'The "name" and "value" arguments must be specified'
- });
-
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- assert.throws(() => params.set(obj, 'b'), /^Error: toString$/);
- assert.throws(() => params.set('a', obj), /^Error: toString$/);
- assert.throws(() => params.set(sym, 'b'),
- /^TypeError: Cannot convert a Symbol value to a string$/);
- assert.throws(() => params.set('a', sym),
- /^TypeError: Cannot convert a Symbol value to a string$/);
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-constructor.js b/test/parallel/test-whatwg-url-searchparams-constructor.js
index b6e720cc7f..882072ba44 100644
--- a/test/parallel/test-whatwg-url-searchparams-constructor.js
+++ b/test/parallel/test-whatwg-url-searchparams-constructor.js
@@ -1,7 +1,6 @@
'use strict';
-const common = require('../common');
-const assert = require('assert');
+require('../common');
const URLSearchParams = require('url').URLSearchParams;
const {
test, assert_equals, assert_true,
@@ -190,66 +189,3 @@ test(() => {
assert_equals(params2.get("a"), "b")
}, "Custom [Symbol.iterator]")
/* eslint-enable */
-
-// Tests below are not from WPT.
-function makeIterableFunc(array) {
- return Object.assign(() => {}, {
- [Symbol.iterator]() {
- return array[Symbol.iterator]();
- }
- });
-}
-
-{
- const iterableError = common.expectsError({
- code: 'ERR_ARG_NOT_ITERABLE',
- type: TypeError,
- message: 'Query pairs must be iterable'
- });
- const tupleError = common.expectsError({
- code: 'ERR_INVALID_TUPLE',
- type: TypeError,
- message: 'Each query pair must be an iterable [name, value] tuple'
- }, 6);
-
- let params;
- params = new URLSearchParams(undefined);
- assert.strictEqual(params.toString(), '');
- params = new URLSearchParams(null);
- assert.strictEqual(params.toString(), '');
- params = new URLSearchParams(
- makeIterableFunc([['key', 'val'], ['key2', 'val2']])
- );
- assert.strictEqual(params.toString(), 'key=val&key2=val2');
- params = new URLSearchParams(
- makeIterableFunc([['key', 'val'], ['key2', 'val2']].map(makeIterableFunc))
- );
- assert.strictEqual(params.toString(), 'key=val&key2=val2');
- assert.throws(() => new URLSearchParams([[1]]), tupleError);
- assert.throws(() => new URLSearchParams([[1, 2, 3]]), tupleError);
- assert.throws(() => new URLSearchParams({ [Symbol.iterator]: 42 }),
- iterableError);
- assert.throws(() => new URLSearchParams([{}]), tupleError);
- assert.throws(() => new URLSearchParams(['a']), tupleError);
- assert.throws(() => new URLSearchParams([null]), tupleError);
- assert.throws(() => new URLSearchParams([{ [Symbol.iterator]: 42 }]),
- tupleError);
-}
-
-{
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- const toStringError = /^Error: toString$/;
- const symbolError = /^TypeError: Cannot convert a Symbol value to a string$/;
-
- assert.throws(() => new URLSearchParams({ a: obj }), toStringError);
- assert.throws(() => new URLSearchParams([['a', obj]]), toStringError);
- assert.throws(() => new URLSearchParams(sym), symbolError);
- assert.throws(() => new URLSearchParams({ [sym]: 'a' }), symbolError);
- assert.throws(() => new URLSearchParams({ a: sym }), symbolError);
- assert.throws(() => new URLSearchParams([[sym, 'a']]), symbolError);
- assert.throws(() => new URLSearchParams([['a', sym]]), symbolError);
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-delete.js b/test/parallel/test-whatwg-url-searchparams-delete.js
index 042ecb5d88..cdf3332efc 100644
--- a/test/parallel/test-whatwg-url-searchparams-delete.js
+++ b/test/parallel/test-whatwg-url-searchparams-delete.js
@@ -1,7 +1,6 @@
'use strict';
-const common = require('../common');
-const assert = require('assert');
+require('../common');
const { URL, URLSearchParams } = require('url');
const { test, assert_equals, assert_true, assert_false } =
require('../common/wpt');
@@ -58,43 +57,3 @@ test(function() {
assert_equals(url.search, '', 'url.search does not have ?');
}, 'Removing non-existent param removes ? from URL');
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.delete.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
- common.expectsError(() => {
- params.delete();
- }, {
- code: 'ERR_MISSING_ARGS',
- type: TypeError,
- message: 'The "name" argument must be specified'
- });
-
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- assert.throws(() => params.delete(obj), /^Error: toString$/);
- assert.throws(() => params.delete(sym),
- /^TypeError: Cannot convert a Symbol value to a string$/);
-}
-
-// https://github.com/nodejs/node/issues/10480
-// Emptying searchParams should correctly update url's query
-{
- const url = new URL('http://domain?var=1&var=2&var=3');
- for (const param of url.searchParams.keys()) {
- url.searchParams.delete(param);
- }
- assert.strictEqual(url.searchParams.toString(), '');
- assert.strictEqual(url.search, '');
- assert.strictEqual(url.href, 'http://domain/');
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-foreach.js b/test/parallel/test-whatwg-url-searchparams-foreach.js
index 53c35da263..833858618f 100644
--- a/test/parallel/test-whatwg-url-searchparams-foreach.js
+++ b/test/parallel/test-whatwg-url-searchparams-foreach.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const { URL, URLSearchParams } = require('url');
const { test, assert_array_equals, assert_unreached } =
require('../common/wpt');
@@ -45,15 +45,3 @@ test(function() {
}
}, "empty");
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.forEach.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-get.js b/test/parallel/test-whatwg-url-searchparams-get.js
index e14bdc7e74..94e92c18e4 100644
--- a/test/parallel/test-whatwg-url-searchparams-get.js
+++ b/test/parallel/test-whatwg-url-searchparams-get.js
@@ -1,7 +1,6 @@
'use strict';
-const common = require('../common');
-const assert = require('assert');
+require('../common');
const URLSearchParams = require('url').URLSearchParams;
const { test, assert_equals, assert_true } = require('../common/wpt');
@@ -33,31 +32,3 @@ test(function() {
assert_equals(params.get('fourth'), null, 'Search params object has no "fourth" name and value.');
}, 'More get() basics');
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.get.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
- common.expectsError(() => {
- params.get();
- }, {
- code: 'ERR_MISSING_ARGS',
- type: TypeError,
- message: 'The "name" argument must be specified'
- });
-
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- assert.throws(() => params.get(obj), /^Error: toString$/);
- assert.throws(() => params.get(sym),
- /^TypeError: Cannot convert a Symbol value to a string$/);
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-getall.js b/test/parallel/test-whatwg-url-searchparams-getall.js
index a4692c22f1..06827f37d9 100644
--- a/test/parallel/test-whatwg-url-searchparams-getall.js
+++ b/test/parallel/test-whatwg-url-searchparams-getall.js
@@ -1,7 +1,6 @@
'use strict';
-const common = require('../common');
-const assert = require('assert');
+require('../common');
const URLSearchParams = require('url').URLSearchParams;
const { test, assert_equals, assert_true, assert_array_equals } =
require('../common/wpt');
@@ -38,31 +37,3 @@ test(function() {
assert_array_equals(matches, ['one'], 'Search params object has expected name "a" values');
}, 'getAll() multiples');
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.getAll.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
- common.expectsError(() => {
- params.getAll();
- }, {
- code: 'ERR_MISSING_ARGS',
- type: TypeError,
- message: 'The "name" argument must be specified'
- });
-
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- assert.throws(() => params.getAll(obj), /^Error: toString$/);
- assert.throws(() => params.getAll(sym),
- /^TypeError: Cannot convert a Symbol value to a string$/);
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-has.js b/test/parallel/test-whatwg-url-searchparams-has.js
index 47c6b6f7ba..95e69beb4d 100644
--- a/test/parallel/test-whatwg-url-searchparams-has.js
+++ b/test/parallel/test-whatwg-url-searchparams-has.js
@@ -1,7 +1,6 @@
'use strict';
-const common = require('../common');
-const assert = require('assert');
+require('../common');
const URLSearchParams = require('url').URLSearchParams;
const { test, assert_false, assert_true } = require('../common/wpt');
@@ -36,31 +35,3 @@ test(function() {
assert_false(params.has('first'), 'Search params object has no name "first"');
}, 'has() following delete()');
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.has.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
- common.expectsError(() => {
- params.has();
- }, {
- code: 'ERR_MISSING_ARGS',
- type: TypeError,
- message: 'The "name" argument must be specified'
- });
-
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- assert.throws(() => params.has(obj), /^Error: toString$/);
- assert.throws(() => params.has(sym),
- /^TypeError: Cannot convert a Symbol value to a string$/);
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-set.js b/test/parallel/test-whatwg-url-searchparams-set.js
index 1bca12e31b..0d43678427 100644
--- a/test/parallel/test-whatwg-url-searchparams-set.js
+++ b/test/parallel/test-whatwg-url-searchparams-set.js
@@ -1,7 +1,6 @@
'use strict';
-const common = require('../common');
-const assert = require('assert');
+require('../common');
const URLSearchParams = require('url').URLSearchParams;
const { test, assert_equals, assert_true } = require('../common/wpt');
@@ -34,34 +33,3 @@ test(function() {
assert_equals(params.get('a'), '4', 'Search params object has name "a" with value "4"');
}, 'URLSearchParams.set');
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.set.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
- common.expectsError(() => {
- params.set('a');
- }, {
- code: 'ERR_MISSING_ARGS',
- type: TypeError,
- message: 'The "name" and "value" arguments must be specified'
- });
-
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- assert.throws(() => params.append(obj, 'b'), /^Error: toString$/);
- assert.throws(() => params.append('a', obj), /^Error: toString$/);
- assert.throws(() => params.append(sym, 'b'),
- /^TypeError: Cannot convert a Symbol value to a string$/);
- assert.throws(() => params.append('a', sym),
- /^TypeError: Cannot convert a Symbol value to a string$/);
-}
diff --git a/test/parallel/test-whatwg-url-searchparams-sort.js b/test/parallel/test-whatwg-url-searchparams-sort.js
index 1122f08dcc..65dd23a6da 100644
--- a/test/parallel/test-whatwg-url-searchparams-sort.js
+++ b/test/parallel/test-whatwg-url-searchparams-sort.js
@@ -61,45 +61,3 @@ test(function() {
assert_equals(url.search, "")
}, "Sorting non-existent params removes ? from URL")
/* eslint-enable */
-
-// Tests below are not from WPT.
-
-// Test bottom-up iterative stable merge sort
-const tests = [{ input: '', output: [] }];
-const pairs = [];
-for (let i = 10; i < 100; i++) {
- pairs.push([`a${i}`, 'b']);
- tests[0].output.push([`a${i}`, 'b']);
-}
-tests[0].input = pairs.sort(() => Math.random() > 0.5)
- .map((pair) => pair.join('=')).join('&');
-
-tests.push(
- {
- 'input': 'z=a&=b&c=d',
- 'output': [['', 'b'], ['c', 'd'], ['z', 'a']]
- }
-);
-
-tests.forEach((val) => {
- test(() => {
- const params = new URLSearchParams(val.input);
- let i = 0;
- params.sort();
- for (const param of params) {
- assert_array_equals(param, val.output[i]);
- i++;
- }
- }, `Parse and sort: ${val.input}`);
-
- test(() => {
- const url = new URL(`?${val.input}`, 'https://example/');
- url.searchParams.sort();
- const params = new URLSearchParams(url.search);
- let i = 0;
- for (const param of params) {
- assert_array_equals(param, val.output[i]);
- i++;
- }
- }, `URL parse and sort: ${val.input}`);
-});
diff --git a/test/parallel/test-whatwg-url-searchparams-stringifier.js b/test/parallel/test-whatwg-url-searchparams-stringifier.js
index e3bfbdcf19..e2b6faaabe 100644
--- a/test/parallel/test-whatwg-url-searchparams-stringifier.js
+++ b/test/parallel/test-whatwg-url-searchparams-stringifier.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const URLSearchParams = require('url').URLSearchParams;
const { test, assert_equals } = require('../common/wpt');
@@ -121,15 +121,3 @@ test(function() {
assert_equals(params.toString(), 'a=&a=b');
}, 'URLSearchParams.toString');
/* eslint-enable */
-
-// Tests below are not from WPT.
-{
- const params = new URLSearchParams();
- common.expectsError(() => {
- params.toString.call(undefined);
- }, {
- code: 'ERR_INVALID_THIS',
- type: TypeError,
- message: 'Value of "this" must be of type URLSearchParams'
- });
-}
diff --git a/test/parallel/test-whatwg-url-setters.js b/test/parallel/test-whatwg-url-setters.js
index 7655e4a257..a04b6c93ec 100644
--- a/test/parallel/test-whatwg-url-setters.js
+++ b/test/parallel/test-whatwg-url-setters.js
@@ -6,14 +6,10 @@ if (!common.hasIntl) {
common.skip('missing Intl');
}
-const assert = require('assert');
const URL = require('url').URL;
const { test, assert_equals } = require('../common/wpt');
const fixtures = require('../common/fixtures');
-const additionalTestCases =
- require(fixtures.path('url-setter-tests-additional.js'));
-
const request = {
response: require(fixtures.path('url-setter-tests'))
};
@@ -80,48 +76,3 @@ function runURLSettersTests(all_test_cases) {
startURLSettersTests()
/* eslint-enable */
-
-// Tests below are not from WPT.
-
-{
- for (const attributeToBeSet in additionalTestCases) {
- if (attributeToBeSet === 'comment') {
- continue;
- }
- const testCases = additionalTestCases[attributeToBeSet];
- for (const testCase of testCases) {
- let name = `Setting <${testCase.href}>.${attributeToBeSet}` +
- ` = "${testCase.new_value}"`;
- if ('comment' in testCase) {
- name += ` ${testCase.comment}`;
- }
- test(function() {
- const url = new URL(testCase.href);
- url[attributeToBeSet] = testCase.new_value;
- for (const attribute in testCase.expected) {
- assert_equals(url[attribute], testCase.expected[attribute]);
- }
- }, `URL: ${name}`);
- }
- }
-}
-
-{
- const url = new URL('http://example.com/');
- const obj = {
- toString() { throw new Error('toString'); },
- valueOf() { throw new Error('valueOf'); }
- };
- const sym = Symbol();
- const props = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(url));
- for (const [name, { set }] of Object.entries(props)) {
- if (set) {
- assert.throws(() => url[name] = obj,
- /^Error: toString$/,
- `url.${name} = { toString() { throw ... } }`);
- assert.throws(() => url[name] = sym,
- /^TypeError: Cannot convert a Symbol value to a string$/,
- `url.${name} = ${String(sym)}`);
- }
- }
-}