Skip to content

Commit ffe4d7b

Browse files
robtpatoncjihrig
authored andcommitted
test: increase coverage for ModuleMap
Add test for ModuleMap set with ModuleJob but bad url. PR-URL: #16045 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 433745e commit ffe4d7b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
// Flags: --expose-internals
3+
4+
// This test ensures that the type checking of ModuleMap throws
5+
// errors appropriately
6+
7+
constcommon=require('../common');
8+
9+
const{URL}=require('url');
10+
constLoader=require('internal/loader/Loader');
11+
constModuleMap=require('internal/loader/ModuleMap');
12+
constModuleJob=require('internal/loader/ModuleJob');
13+
const{ createDynamicModule }=require('internal/loader/ModuleWrap');
14+
15+
conststubModuleUrl=newURL('file://tmp/test');
16+
conststubModule=createDynamicModule(['default'],stubModuleUrl);
17+
constloader=newLoader();
18+
constmoduleMap=newModuleMap();
19+
constmoduleJob=newModuleJob(loader,stubModule.module,
20+
()=>newPromise(()=>{}));
21+
22+
common.expectsError(
23+
()=>moduleMap.get(1),
24+
{
25+
code: 'ERR_INVALID_ARG_TYPE',
26+
type: TypeError,
27+
message: 'The "url" argument must be of type string'
28+
}
29+
);
30+
31+
common.expectsError(
32+
()=>moduleMap.set(1,moduleJob),
33+
{
34+
code: 'ERR_INVALID_ARG_TYPE',
35+
type: TypeError,
36+
message: 'The "url" argument must be of type string'
37+
}
38+
);
39+
40+
common.expectsError(
41+
()=>moduleMap.set('somestring','notamodulejob'),
42+
{
43+
code: 'ERR_INVALID_ARG_TYPE',
44+
type: TypeError,
45+
message: 'The "job" argument must be of type ModuleJob'
46+
}
47+
);
48+
49+
common.expectsError(
50+
()=>moduleMap.has(1),
51+
{
52+
code: 'ERR_INVALID_ARG_TYPE',
53+
type: TypeError,
54+
message: 'The "url" argument must be of type string'
55+
}
56+
);

0 commit comments

Comments
(0)