Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion test/parallel/test-vm-module-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

const common = require('../common');
const assert = require('assert');
const { SourceTextModule, SyntheticModule, createContext } = require('vm');
const {
Module,
SourceTextModule,
SyntheticModule,
createContext
} = require('vm');
const util = require('util');

(async function test1() {
Expand Down Expand Up @@ -107,3 +112,38 @@ const util = require('util');
assert.notStrictEqual(dep, undefined);
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
});
}