diff --git a/test/parallel/test-internal-module-map-asserts.js b/test/parallel/test-internal-module-map-asserts.js new file mode 100644 index 00000000000000..7f7b980c9a91ab --- /dev/null +++ b/test/parallel/test-internal-module-map-asserts.js @@ -0,0 +1,96 @@ +// Flags: --expose-internals +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const ModuleMap = require('internal/loader/ModuleMap'); + +// ModuleMap.get, url argument should only accept string values +{ + const errorReg = common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: /^The "url" argument must be of type string/ + }, 5); + + const moduleMap = new ModuleMap(); + + assert.throws(() => moduleMap.get({}), errorReg); + + assert.throws(() => moduleMap.get([]), errorReg); + + assert.throws(() => moduleMap.get(true), errorReg); + + assert.throws(() => moduleMap.get(1), errorReg); + + assert.throws(() => moduleMap.get(() => {}), errorReg); +} + +// ModuleMap.has, url argument should only accept string values +{ + const errorReg = common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: /^The "url" argument must be of type string/ + }, 5); + + const moduleMap = new ModuleMap(); + + assert.throws(() => moduleMap.has({}), errorReg); + + assert.throws(() => moduleMap.has([]), errorReg); + + assert.throws(() => moduleMap.has(true), errorReg); + + assert.throws(() => moduleMap.has(1), errorReg); + + assert.throws(() => moduleMap.has(() => {}), errorReg); +} + +// ModuleMap.set, url argument should only accept string values +{ + const errorReg = common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: /^The "url" argument must be of type string/ + }, 5); + + // As long as the assertion of "job" argument is done after the assertion of + // "url" argument this test suite is ok. Tried to mock the "job" parameter, + // but I think it's useless, and was not simple to mock... + const job = undefined; + + const moduleMap = new ModuleMap(); + + assert.throws(() => moduleMap.set({}, job), errorReg); + + assert.throws(() => moduleMap.set([], job), errorReg); + + assert.throws(() => moduleMap.set(true, job), errorReg); + + assert.throws(() => moduleMap.set(1, job), errorReg); + + assert.throws(() => moduleMap.set(() => {}, job), errorReg); +} + + +// ModuleMap.set, job argument should only accept ModuleJob values +{ + const errorReg = common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: /^The "job" argument must be of type ModuleJob/ + }, 5); + + const moduleMap = new ModuleMap(); + + assert.throws(() => moduleMap.set('', {}), errorReg); + + assert.throws(() => moduleMap.set('', []), errorReg); + + assert.throws(() => moduleMap.set('', true), errorReg); + + assert.throws(() => moduleMap.set('', 1), errorReg); + + assert.throws(() => moduleMap.set('', () => {}), errorReg); +} diff --git a/test/parallel/test-whatwg-url-searchparams-sort.js b/test/parallel/test-whatwg-url-searchparams-sort.js index 0e01c627eea6e4..1122f08dcc0434 100644 --- a/test/parallel/test-whatwg-url-searchparams-sort.js +++ b/test/parallel/test-whatwg-url-searchparams-sort.js @@ -40,10 +40,10 @@ const { test, assert_equals, assert_array_equals } = require('../common/wpt'); assert_array_equals(param, val.output[i]) i++ } - }, "Parse and sort: " + val.input) + }, `Parse and sort: ${val.input}`) test(() => { - let url = new URL("?" + val.input, "https://example/") + let url = new URL(`?${val.input}`, "https://example/") url.searchParams.sort() let params = new URLSearchParams(url.search), i = 0 @@ -51,7 +51,7 @@ const { test, assert_equals, assert_array_equals } = require('../common/wpt'); assert_array_equals(param, val.output[i]) i++ } - }, "URL parse and sort: " + val.input) + }, `URL parse and sort: ${val.input}`) }) test(function() { @@ -90,7 +90,7 @@ tests.forEach((val) => { assert_array_equals(param, val.output[i]); i++; } - }, 'Parse and sort: ' + val.input); + }, `Parse and sort: ${val.input}`); test(() => { const url = new URL(`?${val.input}`, 'https://example/'); @@ -101,5 +101,5 @@ tests.forEach((val) => { assert_array_equals(param, val.output[i]); i++; } - }, 'URL parse and sort: ' + val.input); + }, `URL parse and sort: ${val.input}`); });