Skip to content

Commit

Permalink
test: increase coverage for ModuleMap
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
robtpaton authored and gibfahn committed Nov 14, 2017
1 parent 4e848d4 commit b3032d2
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/es-module/test-esm-loader-modulemap.js
Original file line number Diff line number Diff line change
@@ -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'
}
);

0 comments on commit b3032d2

Please sign in to comment.