Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b6c815c

Browse filesBrowse files
Andrew Kuzmenkotargos
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 57f29b7 commit b6c815c
Copy full SHA for b6c815c

File tree

Expand file treeCollapse file tree

1 file changed

+41
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+41
-1
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-vm-module-basic.js
+41-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.