From 32047f604cae5e7c08a082127014ef44d4e4f042 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Blais Date: Fri, 6 Oct 2017 13:01:05 -0400 Subject: [PATCH 1/2] test: replace string concatenation with template literals --- test/parallel/test-whatwg-url-searchparams-sort.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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}`); }); From 705a09f246952932c869a90eccf720ba2957f9ca Mon Sep 17 00:00:00 2001 From: Jean-Philippe Blais Date: Sat, 7 Oct 2017 00:33:19 -0400 Subject: [PATCH 2/2] test: improve coverage of lib/internal/loader/ModuleMap.js --- .../test-internal-module-map-asserts.js | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 test/parallel/test-internal-module-map-asserts.js 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); +}