-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
1e9d3e6
commit 81d824b
Showing
33 changed files
with
464 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
test/parallel/test-whatwg-url-global.js → ...parallel/test-whatwg-url-custom-global.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:[email protected]:8080/path/name/?que=ry#hash'); | ||
|
||
assert.strictEqual( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
test/parallel/test-whatwg-url-properties.js → ...llel/test-whatwg-url-custom-properties.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:[email protected]:21/aaa/zzz?l=24#test'); | ||
const oldParams = url.searchParams; // for test of [SameObject] | ||
|
||
|
37 changes: 37 additions & 0 deletions
37
test/parallel/test-whatwg-url-custom-searchparams-append.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$/); | ||
} |
69 changes: 69 additions & 0 deletions
69
test/parallel/test-whatwg-url-custom-searchparams-constructor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
46 changes: 46 additions & 0 deletions
46
test/parallel/test-whatwg-url-custom-searchparams-delete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/'); | ||
} |
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
test/parallel/test-whatwg-url-custom-searchparams-foreach.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$/); | ||
} |
34 changes: 34 additions & 0 deletions
34
test/parallel/test-whatwg-url-custom-searchparams-getall.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$/); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$/); | ||
} |
3 changes: 2 additions & 1 deletion
3
...l/test-whatwg-url-searchparams-inspect.js → ...whatwg-url-custom-searchparams-inspect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...llel/test-whatwg-url-searchparams-keys.js → ...st-whatwg-url-custom-searchparams-keys.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.