镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
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
27 changes: 26 additions & 1 deletion test/parallel/test-vm-module-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const common = require('../common');

const assert = require('assert');

const { SourceTextModule, createContext } = require('vm');
const { SourceTextModule, createContext, Module } = require('vm');

async function createEmptyLinkedModule() {
const m = new SourceTextModule('');
Expand Down Expand Up @@ -205,6 +205,17 @@ async function checkInvalidOptionForEvaluate() {
"Received type string ('a-string')",
code: 'ERR_INVALID_ARG_TYPE'
});

{
['link', 'evaluate'].forEach(async (method) => {
await assert.rejects(async () => {
await Module.prototype[method]();
}, {
code: 'ERR_VM_MODULE_NOT_MODULE',
message: /Provided module is not an instance of Module/
});
});
}
}

function checkInvalidCachedData() {
Expand All @@ -223,6 +234,19 @@ function checkInvalidCachedData() {
});
}

function checkGettersErrors() {
const getters = ['identifier', 'context', 'namespace', 'status', 'error'];
getters.forEach((getter) => {
assert.throws(() => {
// eslint-disable-next-line no-unused-expressions
Module.prototype[getter];
}, {
code: 'ERR_VM_MODULE_NOT_MODULE',
message: /Provided module is not an instance of Module/
});
});
}

const finished = common.mustCall();

(async function main() {
Expand All @@ -232,5 +256,6 @@ const finished = common.mustCall();
await checkExecution();
await checkInvalidOptionForEvaluate();
checkInvalidCachedData();
checkGettersErrors();
finished();
})().then(common.mustCall());