Skip to content

Commit 3b90bd0

Browse files
jphblaisBridgeAR
authored andcommitted
test: improve coverage of ModuleMap.js
PR-URL: #15924 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent f05a2d8 commit 3b90bd0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const ModuleMap = require('internal/loader/ModuleMap');
7+
8+
// ModuleMap.get, ModuleMap.has and ModuleMap.set should only accept string
9+
// values as url argument.
10+
{
11+
const errorReg = common.expectsError({
12+
code: 'ERR_INVALID_ARG_TYPE',
13+
type: TypeError,
14+
message: /^The "url" argument must be of type string/
15+
}, 15);
16+
17+
const moduleMap = new ModuleMap();
18+
19+
// As long as the assertion of "job" argument is done after the assertion of
20+
// "url" argument this test suite is ok. Tried to mock the "job" parameter,
21+
// but I think it's useless, and was not simple to mock...
22+
const job = undefined;
23+
24+
[{}, [], true, 1, () => {}].forEach((value) => {
25+
assert.throws(() => moduleMap.get(value), errorReg);
26+
assert.throws(() => moduleMap.has(value), errorReg);
27+
assert.throws(() => moduleMap.set(value, job), errorReg);
28+
});
29+
}
30+
31+
// ModuleMap.set, job argument should only accept ModuleJob values.
32+
{
33+
const errorReg = common.expectsError({
34+
code: 'ERR_INVALID_ARG_TYPE',
35+
type: TypeError,
36+
message: /^The "job" argument must be of type ModuleJob/
37+
}, 5);
38+
39+
const moduleMap = new ModuleMap();
40+
41+
[{}, [], true, 1, () => {}].forEach((value) => {
42+
assert.throws(() => moduleMap.set('', value), errorReg);
43+
});
44+
}

0 commit comments

Comments
 (0)