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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
ea6a4576ae
commit
ee14a64537
@ -4,7 +4,12 @@
|
|||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const { SourceTextModule, SyntheticModule, createContext } = require('vm');
|
const {
|
||||||
|
Module,
|
||||||
|
SourceTextModule,
|
||||||
|
SyntheticModule,
|
||||||
|
createContext
|
||||||
|
} = require('vm');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
(async function test1() {
|
(async function test1() {
|
||||||
@ -107,3 +112,38 @@ const util = require('util');
|
|||||||
assert.notStrictEqual(dep, undefined);
|
assert.notStrictEqual(dep, undefined);
|
||||||
assert.strictEqual(dep, m.dependencySpecifiers);
|
assert.strictEqual(dep, m.dependencySpecifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the impossibility of creating an abstract instance of the Module.
|
||||||
|
{
|
||||||
|
common.expectsError(() => new Module(), {
|
||||||
|
message: 'Module is not a constructor',
|
||||||
|
type: TypeError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to throws invalid exportNames
|
||||||
|
{
|
||||||
|
common.expectsError(() => new SyntheticModule(undefined, () => {}, {}), {
|
||||||
|
message: 'The "exportNames" argument must be an Array of strings.' +
|
||||||
|
' Received undefined',
|
||||||
|
type: TypeError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to throws invalid evaluateCallback
|
||||||
|
{
|
||||||
|
common.expectsError(() => new SyntheticModule([], undefined, {}), {
|
||||||
|
message: 'The "evaluateCallback" argument must be of type function.' +
|
||||||
|
' Received undefined',
|
||||||
|
type: TypeError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to throws invalid options
|
||||||
|
{
|
||||||
|
common.expectsError(() => new SyntheticModule([], () => {}, null), {
|
||||||
|
message: 'The "options" argument must be of type object.' +
|
||||||
|
' Received null',
|
||||||
|
type: TypeError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user