Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
test: improve coverage of ModuleMap.js
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#15924
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
jphblais authored and addaleax committed Oct 26, 2017
1 parent 0a2c09c commit 32a05d3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/parallel/test-internal-module-map-asserts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
const assert = require('assert');
const ModuleMap = require('internal/loader/ModuleMap');

// ModuleMap.get, ModuleMap.has and ModuleMap.set should only accept string
// values as url argument.
{
const errorReg = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "url" argument must be of type string/
}, 15);

const moduleMap = new ModuleMap();

// As long as the assertion of "job" argument is done after the assertion of
// "url" argument this test suite is ok. Tried to mock the "job" parameter,
// but I think it's useless, and was not simple to mock...
const job = undefined;

[{}, [], true, 1, () => {}].forEach((value) => {
assert.throws(() => moduleMap.get(value), errorReg);
assert.throws(() => moduleMap.has(value), errorReg);
assert.throws(() => moduleMap.set(value, job), errorReg);
});
}

// ModuleMap.set, job argument should only accept ModuleJob values.
{
const errorReg = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "job" argument must be of type ModuleJob/
}, 5);

const moduleMap = new ModuleMap();

[{}, [], true, 1, () => {}].forEach((value) => {
assert.throws(() => moduleMap.set('', value), errorReg);
});
}

0 comments on commit 32a05d3

Please sign in to comment.