Skip to content

Commit

Permalink
test: improve coverage for Module getters
Browse files Browse the repository at this point in the history
PR-URL: #36950
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
juanarbol authored and targos committed Jun 11, 2021
1 parent a45d280 commit f43fc6b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/parallel/test-vm-module-errors.js
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());

0 comments on commit f43fc6b

Please sign in to comment.