From 2aac39998e31d3052e118fedfabe3092a5615802 Mon Sep 17 00:00:00 2001 From: Rob Paton Date: Fri, 6 Oct 2017 11:48:41 -0700 Subject: [PATCH] test: increase coverage for ModuleMap Add test for ModuleMap set with ModuleJob but bad url. PR-URL: https://github.com/nodejs/node/pull/16045 Reviewed-By: Stephen Belanger Reviewed-By: Bradley Farias Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung --- test/es-module/test-esm-loader-modulemap.js | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/es-module/test-esm-loader-modulemap.js diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js new file mode 100644 index 0000000000..58c76ce960 --- /dev/null +++ b/test/es-module/test-esm-loader-modulemap.js @@ -0,0 +1,56 @@ +'use strict'; +// Flags: --expose-internals + +// This test ensures that the type checking of ModuleMap throws +// errors appropriately + +const common = require('../common'); + +const { URL } = require('url'); +const Loader = require('internal/loader/Loader'); +const ModuleMap = require('internal/loader/ModuleMap'); +const ModuleJob = require('internal/loader/ModuleJob'); +const { createDynamicModule } = require('internal/loader/ModuleWrap'); + +const stubModuleUrl = new URL('file://tmp/test'); +const stubModule = createDynamicModule(['default'], stubModuleUrl); +const loader = new Loader(); +const moduleMap = new ModuleMap(); +const moduleJob = new ModuleJob(loader, stubModule.module, + () => new Promise(() => {})); + +common.expectsError( + () => moduleMap.get(1), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "url" argument must be of type string' + } +); + +common.expectsError( + () => moduleMap.set(1, moduleJob), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "url" argument must be of type string' + } +); + +common.expectsError( + () => moduleMap.set('somestring', 'notamodulejob'), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "job" argument must be of type ModuleJob' + } +); + +common.expectsError( + () => moduleMap.has(1), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "url" argument must be of type string' + } +);