Skip to content

Commit 81d824b

Browse files
joyeecheungtargos
authored andcommitted
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: #22442 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent 1e9d3e6 commit 81d824b

33 files changed

+464
-391
lines changed

test/parallel/test-whatwg-url-domainto.js test/parallel/test-whatwg-url-custom-domainto.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'use strict';
2+
3+
// Tests below are not from WPT.
4+
25
const common = require('../common');
36

47
if (!common.hasIntl)
@@ -7,9 +10,8 @@ if (!common.hasIntl)
710
const assert = require('assert');
811
const { domainToASCII, domainToUnicode } = require('url');
912

10-
// Tests below are not from WPT.
11-
const tests = require('../fixtures/url-idna.js');
12-
const wptToASCIITests = require('../fixtures/url-toascii.js');
13+
const tests = require('../fixtures/url-idna');
14+
const wptToASCIITests = require('../fixtures/url-toascii');
1315

1416
{
1517
const expectedError = common.expectsError(

test/parallel/test-whatwg-url-global.js test/parallel/test-whatwg-url-custom-global.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
// Tests below are not from WPT.
4+
35
require('../common');
46
const assert = require('assert');
57
const { URL, URLSearchParams } = require('url');

test/parallel/test-whatwg-url-inspect.js test/parallel/test-whatwg-url-custom-inspect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
// Tests below are not from WPT.
4+
35
const common = require('../common');
46
if (!common.hasIntl) {
57
// A handful of the tests fail when ICU is not included.
@@ -10,7 +12,6 @@ const util = require('util');
1012
const URL = require('url').URL;
1113
const assert = require('assert');
1214

13-
// Tests below are not from WPT.
1415
const url = new URL('https://username:[email protected]:8080/path/name/?que=ry#hash');
1516

1617
assert.strictEqual(

test/parallel/test-whatwg-url-parsing.js test/parallel/test-whatwg-url-custom-parsing.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
// Tests below are not from WPT.
4+
35
const common = require('../common');
46
if (!common.hasIntl) {
57
// A handful of the tests fail when ICU is not included.
@@ -10,7 +12,6 @@ const URL = require('url').URL;
1012
const assert = require('assert');
1113
const fixtures = require('../common/fixtures');
1214

13-
// Tests below are not from WPT.
1415
const tests = require(fixtures.path('url-tests'));
1516

1617
const originalFailures = tests.filter((test) => test.failure);

test/parallel/test-whatwg-url-properties.js test/parallel/test-whatwg-url-custom-properties.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Flags: --expose-internals
22
'use strict';
33

4+
// Tests below are not from WPT.
5+
46
require('../common');
57
const URL = require('url').URL;
68
const assert = require('assert');
79
const urlToOptions = require('internal/url').urlToOptions;
810

9-
// Tests below are not from WPT.
1011
const url = new URL('http://user:[email protected]:21/aaa/zzz?l=24#test');
1112
const oldParams = url.searchParams; // for test of [SameObject]
1213

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
// Tests below are not from WPT.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const URLSearchParams = require('url').URLSearchParams;
8+
9+
{
10+
const params = new URLSearchParams();
11+
common.expectsError(() => {
12+
params.append.call(undefined);
13+
}, {
14+
code: 'ERR_INVALID_THIS',
15+
type: TypeError,
16+
message: 'Value of "this" must be of type URLSearchParams'
17+
});
18+
common.expectsError(() => {
19+
params.append('a');
20+
}, {
21+
code: 'ERR_MISSING_ARGS',
22+
type: TypeError,
23+
message: 'The "name" and "value" arguments must be specified'
24+
});
25+
26+
const obj = {
27+
toString() { throw new Error('toString'); },
28+
valueOf() { throw new Error('valueOf'); }
29+
};
30+
const sym = Symbol();
31+
assert.throws(() => params.set(obj, 'b'), /^Error: toString$/);
32+
assert.throws(() => params.set('a', obj), /^Error: toString$/);
33+
assert.throws(() => params.set(sym, 'b'),
34+
/^TypeError: Cannot convert a Symbol value to a string$/);
35+
assert.throws(() => params.set('a', sym),
36+
/^TypeError: Cannot convert a Symbol value to a string$/);
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
// Tests below are not from WPT.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const URLSearchParams = require('url').URLSearchParams;
8+
9+
function makeIterableFunc(array) {
10+
return Object.assign(() => {}, {
11+
[Symbol.iterator]() {
12+
return array[Symbol.iterator]();
13+
}
14+
});
15+
}
16+
17+
{
18+
const iterableError = common.expectsError({
19+
code: 'ERR_ARG_NOT_ITERABLE',
20+
type: TypeError,
21+
message: 'Query pairs must be iterable'
22+
});
23+
const tupleError = common.expectsError({
24+
code: 'ERR_INVALID_TUPLE',
25+
type: TypeError,
26+
message: 'Each query pair must be an iterable [name, value] tuple'
27+
}, 6);
28+
29+
let params;
30+
params = new URLSearchParams(undefined);
31+
assert.strictEqual(params.toString(), '');
32+
params = new URLSearchParams(null);
33+
assert.strictEqual(params.toString(), '');
34+
params = new URLSearchParams(
35+
makeIterableFunc([['key', 'val'], ['key2', 'val2']])
36+
);
37+
assert.strictEqual(params.toString(), 'key=val&key2=val2');
38+
params = new URLSearchParams(
39+
makeIterableFunc([['key', 'val'], ['key2', 'val2']].map(makeIterableFunc))
40+
);
41+
assert.strictEqual(params.toString(), 'key=val&key2=val2');
42+
assert.throws(() => new URLSearchParams([[1]]), tupleError);
43+
assert.throws(() => new URLSearchParams([[1, 2, 3]]), tupleError);
44+
assert.throws(() => new URLSearchParams({ [Symbol.iterator]: 42 }),
45+
iterableError);
46+
assert.throws(() => new URLSearchParams([{}]), tupleError);
47+
assert.throws(() => new URLSearchParams(['a']), tupleError);
48+
assert.throws(() => new URLSearchParams([null]), tupleError);
49+
assert.throws(() => new URLSearchParams([{ [Symbol.iterator]: 42 }]),
50+
tupleError);
51+
}
52+
53+
{
54+
const obj = {
55+
toString() { throw new Error('toString'); },
56+
valueOf() { throw new Error('valueOf'); }
57+
};
58+
const sym = Symbol();
59+
const toStringError = /^Error: toString$/;
60+
const symbolError = /^TypeError: Cannot convert a Symbol value to a string$/;
61+
62+
assert.throws(() => new URLSearchParams({ a: obj }), toStringError);
63+
assert.throws(() => new URLSearchParams([['a', obj]]), toStringError);
64+
assert.throws(() => new URLSearchParams(sym), symbolError);
65+
assert.throws(() => new URLSearchParams({ [sym]: 'a' }), symbolError);
66+
assert.throws(() => new URLSearchParams({ a: sym }), symbolError);
67+
assert.throws(() => new URLSearchParams([[sym, 'a']]), symbolError);
68+
assert.throws(() => new URLSearchParams([['a', sym]]), symbolError);
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
// Tests below are not from WPT.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const { URL, URLSearchParams } = require('url');
8+
9+
{
10+
const params = new URLSearchParams();
11+
common.expectsError(() => {
12+
params.delete.call(undefined);
13+
}, {
14+
code: 'ERR_INVALID_THIS',
15+
type: TypeError,
16+
message: 'Value of "this" must be of type URLSearchParams'
17+
});
18+
common.expectsError(() => {
19+
params.delete();
20+
}, {
21+
code: 'ERR_MISSING_ARGS',
22+
type: TypeError,
23+
message: 'The "name" argument must be specified'
24+
});
25+
26+
const obj = {
27+
toString() { throw new Error('toString'); },
28+
valueOf() { throw new Error('valueOf'); }
29+
};
30+
const sym = Symbol();
31+
assert.throws(() => params.delete(obj), /^Error: toString$/);
32+
assert.throws(() => params.delete(sym),
33+
/^TypeError: Cannot convert a Symbol value to a string$/);
34+
}
35+
36+
// https://github.com/nodejs/node/issues/10480
37+
// Emptying searchParams should correctly update url's query
38+
{
39+
const url = new URL('http://domain?var=1&var=2&var=3');
40+
for (const param of url.searchParams.keys()) {
41+
url.searchParams.delete(param);
42+
}
43+
assert.strictEqual(url.searchParams.toString(), '');
44+
assert.strictEqual(url.search, '');
45+
assert.strictEqual(url.href, 'http://domain/');
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
// Tests below are not from WPT.
4+
5+
const common = require('../common');
6+
const { URLSearchParams } = require('url');
7+
8+
{
9+
const params = new URLSearchParams();
10+
common.expectsError(() => {
11+
params.forEach.call(undefined);
12+
}, {
13+
code: 'ERR_INVALID_THIS',
14+
type: TypeError,
15+
message: 'Value of "this" must be of type URLSearchParams'
16+
});
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
// Tests below are not from WPT.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const URLSearchParams = require('url').URLSearchParams;
8+
9+
{
10+
const params = new URLSearchParams();
11+
common.expectsError(() => {
12+
params.get.call(undefined);
13+
}, {
14+
code: 'ERR_INVALID_THIS',
15+
type: TypeError,
16+
message: 'Value of "this" must be of type URLSearchParams'
17+
});
18+
common.expectsError(() => {
19+
params.get();
20+
}, {
21+
code: 'ERR_MISSING_ARGS',
22+
type: TypeError,
23+
message: 'The "name" argument must be specified'
24+
});
25+
26+
const obj = {
27+
toString() { throw new Error('toString'); },
28+
valueOf() { throw new Error('valueOf'); }
29+
};
30+
const sym = Symbol();
31+
assert.throws(() => params.get(obj), /^Error: toString$/);
32+
assert.throws(() => params.get(sym),
33+
/^TypeError: Cannot convert a Symbol value to a string$/);
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
// Tests below are not from WPT.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const URLSearchParams = require('url').URLSearchParams;
8+
9+
{
10+
const params = new URLSearchParams();
11+
common.expectsError(() => {
12+
params.getAll.call(undefined);
13+
}, {
14+
code: 'ERR_INVALID_THIS',
15+
type: TypeError,
16+
message: 'Value of "this" must be of type URLSearchParams'
17+
});
18+
common.expectsError(() => {
19+
params.getAll();
20+
}, {
21+
code: 'ERR_MISSING_ARGS',
22+
type: TypeError,
23+
message: 'The "name" argument must be specified'
24+
});
25+
26+
const obj = {
27+
toString() { throw new Error('toString'); },
28+
valueOf() { throw new Error('valueOf'); }
29+
};
30+
const sym = Symbol();
31+
assert.throws(() => params.getAll(obj), /^Error: toString$/);
32+
assert.throws(() => params.getAll(sym),
33+
/^TypeError: Cannot convert a Symbol value to a string$/);
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
// Tests below are not from WPT.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const URLSearchParams = require('url').URLSearchParams;
8+
9+
{
10+
const params = new URLSearchParams();
11+
common.expectsError(() => {
12+
params.has.call(undefined);
13+
}, {
14+
code: 'ERR_INVALID_THIS',
15+
type: TypeError,
16+
message: 'Value of "this" must be of type URLSearchParams'
17+
});
18+
common.expectsError(() => {
19+
params.has();
20+
}, {
21+
code: 'ERR_MISSING_ARGS',
22+
type: TypeError,
23+
message: 'The "name" argument must be specified'
24+
});
25+
26+
const obj = {
27+
toString() { throw new Error('toString'); },
28+
valueOf() { throw new Error('valueOf'); }
29+
};
30+
const sym = Symbol();
31+
assert.throws(() => params.has(obj), /^Error: toString$/);
32+
assert.throws(() => params.has(sym),
33+
/^TypeError: Cannot convert a Symbol value to a string$/);
34+
}

test/parallel/test-whatwg-url-searchparams-inspect.js test/parallel/test-whatwg-url-custom-searchparams-inspect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict';
22

3+
// Tests below are not from WPT.
4+
35
require('../common');
46
const assert = require('assert');
57
const util = require('util');
68
const URLSearchParams = require('url').URLSearchParams;
79

8-
// Tests below are not from WPT.
910
const sp = new URLSearchParams('?a=a&b=b&b=c');
1011
assert.strictEqual(util.inspect(sp),
1112
"URLSearchParams { 'a' => 'a', 'b' => 'b', 'b' => 'c' }");

test/parallel/test-whatwg-url-searchparams-keys.js test/parallel/test-whatwg-url-custom-searchparams-keys.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict';
22

3+
// Tests below are not from WPT.
4+
35
const common = require('../common');
46
const assert = require('assert');
57
const URLSearchParams = require('url').URLSearchParams;
68

7-
// Tests below are not from WPT.
89
const params = new URLSearchParams('a=b&c=d');
910
const keys = params.keys();
1011

0 commit comments

Comments
 (0)