Skip to content

Commit 07d195a

Browse files
Andrew KuzmenkoBethGriggs
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 <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent b450917 commit 07d195a

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

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

Lines changed: 41 additions & 1 deletion
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)