Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve coverage for Module getters #36950

Merged
merged 1 commit into from
Jan 18, 2021
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());