| 
 | 1 | +'use strict';  | 
 | 2 | +// Flags: --expose-internals  | 
 | 3 | + | 
 | 4 | +// This test ensures that the type checking of ModuleMap throws  | 
 | 5 | +// errors appropriately  | 
 | 6 | + | 
 | 7 | +const common = require('../common');  | 
 | 8 | + | 
 | 9 | +const { URL } = require('url');  | 
 | 10 | +const Loader = require('internal/loader/Loader');  | 
 | 11 | +const ModuleMap = require('internal/loader/ModuleMap');  | 
 | 12 | +const ModuleJob = require('internal/loader/ModuleJob');  | 
 | 13 | +const { createDynamicModule } = require('internal/loader/ModuleWrap');  | 
 | 14 | + | 
 | 15 | +const stubModuleUrl = new URL('file://tmp/test');  | 
 | 16 | +const stubModule = createDynamicModule(['default'], stubModuleUrl);  | 
 | 17 | +const loader = new Loader();  | 
 | 18 | +const moduleMap = new ModuleMap();  | 
 | 19 | +const moduleJob = new ModuleJob(loader, stubModule.module,  | 
 | 20 | +                                () => new Promise(() => {}));  | 
 | 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