Skip to content

Commit b6c815c

Browse files
Andrew Kuzmenkotargos
Andrew Kuzmenko
authored andcommitted
test: cover vm with negative tests
Test the impossibility of creating an abstract instance of the Module. Test of SyntheticModule to throw exception if invalid params in constructor PR-URL: #31028 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 57f29b7 commit b6c815c

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

test/parallel/test-vm-module-basic.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
const common = require('../common');
66
const assert = require('assert');
7-
const { SourceTextModule, SyntheticModule, createContext } = require('vm');
7+
const {
8+
Module,
9+
SourceTextModule,
10+
SyntheticModule,
11+
createContext
12+
} = require('vm');
813
const util = require('util');
914

1015
(async function test1() {
@@ -107,3 +112,38 @@ const util = require('util');
107112
assert.notStrictEqual(dep, undefined);
108113
assert.strictEqual(dep, m.dependencySpecifiers);
109114
}
115+
116+
// Check the impossibility of creating an abstract instance of the Module.
117+
{
118+
common.expectsError(() => new Module(), {
119+
message: 'Module is not a constructor',
120+
type: TypeError
121+
});
122+
}
123+
124+
// Check to throws invalid exportNames
125+
{
126+
common.expectsError(() => new SyntheticModule(undefined, () => {}, {}), {
127+
message: 'The "exportNames" argument must be an Array of strings.' +
128+
' Received undefined',
129+
type: TypeError
130+
});
131+
}
132+
133+
// Check to throws invalid evaluateCallback
134+
{
135+
common.expectsError(() => new SyntheticModule([], undefined, {}), {
136+
message: 'The "evaluateCallback" argument must be of type function.' +
137+
' Received undefined',
138+
type: TypeError
139+
});
140+
}
141+
142+
// Check to throws invalid options
143+
{
144+
common.expectsError(() => new SyntheticModule([], () => {}, null), {
145+
message: 'The "options" argument must be of type object.' +
146+
' Received null',
147+
type: TypeError
148+
});
149+
}

0 commit comments

Comments
 (0)