From 32a05d3e35b61db028a3d056ed6993bc37f8fef8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Blais Date: Sat, 7 Oct 2017 00:33:19 -0400 Subject: [PATCH] test: improve coverage of ModuleMap.js PR-URL: https://github.com/nodejs/node/pull/15924 Reviewed-By: Vse Mozhet Byt Reviewed-By: Refael Ackermann Reviewed-By: Ruben Bridgewater --- .../test-internal-module-map-asserts.js | 44 +++++++++++++++++++ 1 file changed, 44 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 0000000000..99be2efedd --- /dev/null +++ b/test/parallel/test-internal-module-map-asserts.js @@ -0,0 +1,44 @@ +// Flags: --expose-internals +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const ModuleMap = require('internal/loader/ModuleMap'); + +// ModuleMap.get, ModuleMap.has and ModuleMap.set should only accept string +// values as url argument. +{ + const errorReg = common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: /^The "url" argument must be of type string/ + }, 15); + + const moduleMap = new ModuleMap(); + + // 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; + + [{}, [], true, 1, () => {}].forEach((value) => { + assert.throws(() => moduleMap.get(value), errorReg); + assert.throws(() => moduleMap.has(value), errorReg); + assert.throws(() => moduleMap.set(value, 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(); + + [{}, [], true, 1, () => {}].forEach((value) => { + assert.throws(() => moduleMap.set('', value), errorReg); + }); +}