| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1e9d3e6 commit 81d824b
33 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | + | ||
| 3 | + // Tests below are not from WPT. | ||
| 4 | + | ||
| 2 | 5 | const common = require('../common'); | |
| 3 | 6 | ||
| 4 | 7 | if (!common.hasIntl) | |
@@ -7,9 +10,8 @@ if (!common.hasIntl) | |||
| 7 | 10 | const assert = require('assert'); | |
| 8 | 11 | const { domainToASCII, domainToUnicode } = require('url'); | |
| 9 | 12 | ||
| 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'); | ||
| 13 | 15 | ||
| 14 | 16 | { | |
| 15 | 17 | const expectedError = common.expectsError( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + // Tests below are not from WPT. | ||
| 4 | + | ||
| 3 | 5 | require('../common'); | |
| 4 | 6 | const assert = require('assert'); | |
| 5 | 7 | const { URL, URLSearchParams } = require('url'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + // Tests below are not from WPT. | ||
| 4 | + | ||
| 3 | 5 | const common = require('../common'); | |
| 4 | 6 | if (!common.hasIntl) { | |
| 5 | 7 | // A handful of the tests fail when ICU is not included. | |
@@ -10,7 +12,6 @@ const util = require('util'); | |||
| 10 | 12 | const URL = require('url').URL; | |
| 11 | 13 | const assert = require('assert'); | |
| 12 | 14 | ||
| 13 | - // Tests below are not from WPT. | ||
| 14 | 15 | const url = new URL('https://username:password@host.name:8080/path/name/?que=ry#hash'); | |
| 15 | 16 | ||
| 16 | 17 | assert.strictEqual( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + // Tests below are not from WPT. | ||
| 4 | + | ||
| 3 | 5 | const common = require('../common'); | |
| 4 | 6 | if (!common.hasIntl) { | |
| 5 | 7 | // A handful of the tests fail when ICU is not included. | |
@@ -10,7 +12,6 @@ const URL = require('url').URL; | |||
| 10 | 12 | const assert = require('assert'); | |
| 11 | 13 | const fixtures = require('../common/fixtures'); | |
| 12 | 14 | ||
| 13 | - // Tests below are not from WPT. | ||
| 14 | 15 | const tests = require(fixtures.path('url-tests')); | |
| 15 | 16 | ||
| 16 | 17 | const originalFailures = tests.filter((test) => test.failure); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,13 @@ | |||
| 1 | 1 | // Flags: --expose-internals | |
| 2 | 2 | 'use strict'; | |
| 3 | 3 | ||
| 4 | + // Tests below are not from WPT. | ||
| 5 | + | ||
| 4 | 6 | require('../common'); | |
| 5 | 7 | const URL = require('url').URL; | |
| 6 | 8 | const assert = require('assert'); | |
| 7 | 9 | const urlToOptions = require('internal/url').urlToOptions; | |
| 8 | 10 | ||
| 9 | - // Tests below are not from WPT. | ||
| 10 | 11 | const url = new URL('http://user:pass@foo.bar.com:21/aaa/zzz?l=24#test'); | |
| 11 | 12 | const oldParams = url.searchParams; // for test of [SameObject] | |
| 12 | 13 | ||
| Original file line number | Diff line number | Diff 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 number | Diff line number | Diff 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 number | Diff line number | Diff 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 number | Diff line number | Diff 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments