From 82e91df5c1d3789492eb17bc2a7f7ce5294e6d8f Mon Sep 17 00:00:00 2001 From: Rob Paton Date: Fri, 6 Oct 2017 11:48:41 -0700 Subject: [PATCH 1/8] test: increase coverage for ModuleMap --- test/es-module/test-esm-loader-modulemap.js | 14 ++++++++++++++ 1 file changed, 14 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 00000000000000..3ea1ca4429a479 --- /dev/null +++ b/test/es-module/test-esm-loader-modulemap.js @@ -0,0 +1,14 @@ +'use strict'; +// Flags: --expose-internals + +// This tests ensures that the type checking of ModuleMap throws errors appropriately + +const assert = require('assert'); + +const ModuleMap = require('internal/loader/ModuleMap'); + +const moduleMap = new ModuleMap(); + +assert.throws(() => { + moduleMap.get(1); +}); From f121d97c37db677eb8002982831c21e4e4ca761f Mon Sep 17 00:00:00 2001 From: Rob Paton Date: Fri, 6 Oct 2017 12:14:09 -0700 Subject: [PATCH 2/8] Started adding tests --- test/es-module/test-esm-loader-modulemap.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index 3ea1ca4429a479..027b47a77819ad 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -11,4 +11,18 @@ const moduleMap = new ModuleMap(); assert.throws(() => { moduleMap.get(1); +}, 'TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string'); + +assert.doesNotThrow(() => { + moduleMap.get('somestring'); }); + +assert.throws(() => { + moduleMap.has(1); +}, 'TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string'); + +assert.doesNotThrow(() => { + moduleMap.has('somestring'); +}); + + From 8ec3e59700936e61cfae2ed8d433300175b01022 Mon Sep 17 00:00:00 2001 From: Christopher Sidebottom Date: Fri, 6 Oct 2017 12:11:55 -0700 Subject: [PATCH 3/8] add test for ModuleMap set with ModuleJob but bad url --- test/es-module/test-esm-loader-modulemap.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index 027b47a77819ad..c8a39ab97a7935 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -4,10 +4,18 @@ // This tests ensures that the type checking of ModuleMap throws errors appropriately const assert = require('assert'); +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); assert.throws(() => { moduleMap.get(1); @@ -25,4 +33,7 @@ assert.doesNotThrow(() => { moduleMap.has('somestring'); }); +assert.throws(() => { + moduleMap.set(1, moduleJob); +}, 'TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string'); From 3f3608f927165c491b92a2f34751ffcfef92428c Mon Sep 17 00:00:00 2001 From: Rob Paton Date: Fri, 6 Oct 2017 12:24:45 -0700 Subject: [PATCH 4/8] Finished tests --- test/es-module/test-esm-loader-modulemap.js | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index c8a39ab97a7935..6b1f4bda210e6d 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -19,21 +19,32 @@ const moduleJob = new ModuleJob(loader, stubModule.module); assert.throws(() => { moduleMap.get(1); -}, 'TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string'); +}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "url" argument must be of type string/); assert.doesNotThrow(() => { moduleMap.get('somestring'); }); assert.throws(() => { - moduleMap.has(1); -}, 'TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string'); + moduleMap.set(1, moduleJob); +}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "url" argument must be of type string/); assert.doesNotThrow(() => { - moduleMap.has('somestring'); + moduleMap.set('somestring', moduleJob); }); assert.throws(() => { - moduleMap.set(1, moduleJob); -}, 'TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string'); + moduleMap.set('somestring', 'notamodulejob'); +}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "job" argument must be of type ModuleJob/); + +assert.doesNotThrow(() => { + moduleMap.set('somestring', moduleJob); +}); +assert.throws(() => { + moduleMap.has(1); +}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "url" argument must be of type string/); + +assert.doesNotThrow(() => { + moduleMap.has('somestring'); +}); From f5cd4c5d528894a641f8d21ccb14cf1810917514 Mon Sep 17 00:00:00 2001 From: Rob Paton Date: Fri, 6 Oct 2017 13:23:48 -0700 Subject: [PATCH 5/8] Fix typo --- test/es-module/test-esm-loader-modulemap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index 6b1f4bda210e6d..ab965129b18b87 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -1,7 +1,7 @@ 'use strict'; // Flags: --expose-internals -// This tests ensures that the type checking of ModuleMap throws errors appropriately +// This test ensures that the type checking of ModuleMap throws errors appropriately const assert = require('assert'); const { URL } = require('url'); From 5ead8e0d90e3d4ac3b6b1306ad3b586e127f1347 Mon Sep 17 00:00:00 2001 From: Rob Paton Date: Fri, 13 Oct 2017 10:52:59 +0100 Subject: [PATCH 6/8] Use common for asserting errors are thrown --- test/es-module/test-esm-loader-modulemap.js | 68 +++++++++++---------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index ab965129b18b87..11de2e9e8a1ead 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -3,9 +3,9 @@ // This test ensures that the type checking of ModuleMap throws errors appropriately -const assert = require('assert'); const { URL } = require('url'); +const common = require('../common'); const Loader = require('internal/loader/Loader'); const ModuleMap = require('internal/loader/ModuleMap'); const ModuleJob = require('internal/loader/ModuleJob'); @@ -17,34 +17,38 @@ const loader = new Loader(); const moduleMap = new ModuleMap(); const moduleJob = new ModuleJob(loader, stubModule.module); -assert.throws(() => { - moduleMap.get(1); -}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "url" argument must be of type string/); - -assert.doesNotThrow(() => { - moduleMap.get('somestring'); -}); - -assert.throws(() => { - moduleMap.set(1, moduleJob); -}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "url" argument must be of type string/); - -assert.doesNotThrow(() => { - moduleMap.set('somestring', moduleJob); -}); - -assert.throws(() => { - moduleMap.set('somestring', 'notamodulejob'); -}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "job" argument must be of type ModuleJob/); - -assert.doesNotThrow(() => { - moduleMap.set('somestring', moduleJob); -}); - -assert.throws(() => { - moduleMap.has(1); -}, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "url" argument must be of type string/); - -assert.doesNotThrow(() => { - moduleMap.has('somestring'); -}); +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' + } +); From 0f9db3e3afaaae7432401f0fb8af559fb3458aaf Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 15 Oct 2017 15:39:47 -0700 Subject: [PATCH 7/8] [Squash] Address nits --- test/es-module/test-esm-loader-modulemap.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index 11de2e9e8a1ead..4186b5b36b1ca7 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -1,11 +1,12 @@ 'use strict'; // Flags: --expose-internals -// This test ensures that the type checking of ModuleMap throws errors appropriately - -const { URL } = require('url'); +// 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'); From 9888535e31d9fe9dc5af437eb440439c69b59d0f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 1 Nov 2017 06:51:38 -0700 Subject: [PATCH 8/8] squash; add third argument --- test/es-module/test-esm-loader-modulemap.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index 4186b5b36b1ca7..58c76ce960657c 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -16,7 +16,8 @@ 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); +const moduleJob = new ModuleJob(loader, stubModule.module, + () => new Promise(() => {})); common.expectsError( () => moduleMap.get(1),