Skip to content

Commit f43fc6b

Browse files
juanarboltargos
authored andcommitted
test: improve coverage for Module getters
PR-URL: #36950 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent a45d280 commit f43fc6b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

test/parallel/test-vm-module-errors.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const common = require('../common');
66

77
const assert = require('assert');
88

9-
const { SourceTextModule, createContext } = require('vm');
9+
const { SourceTextModule, createContext, Module } = require('vm');
1010

1111
async function createEmptyLinkedModule() {
1212
const m = new SourceTextModule('');
@@ -205,6 +205,17 @@ async function checkInvalidOptionForEvaluate() {
205205
"Received type string ('a-string')",
206206
code: 'ERR_INVALID_ARG_TYPE'
207207
});
208+
209+
{
210+
['link', 'evaluate'].forEach(async (method) => {
211+
await assert.rejects(async () => {
212+
await Module.prototype[method]();
213+
}, {
214+
code: 'ERR_VM_MODULE_NOT_MODULE',
215+
message: /Provided module is not an instance of Module/
216+
});
217+
});
218+
}
208219
}
209220

210221
function checkInvalidCachedData() {
@@ -223,6 +234,19 @@ function checkInvalidCachedData() {
223234
});
224235
}
225236

237+
function checkGettersErrors() {
238+
const getters = ['identifier', 'context', 'namespace', 'status', 'error'];
239+
getters.forEach((getter) => {
240+
assert.throws(() => {
241+
// eslint-disable-next-line no-unused-expressions
242+
Module.prototype[getter];
243+
}, {
244+
code: 'ERR_VM_MODULE_NOT_MODULE',
245+
message: /Provided module is not an instance of Module/
246+
});
247+
});
248+
}
249+
226250
const finished = common.mustCall();
227251

228252
(async function main() {
@@ -232,5 +256,6 @@ const finished = common.mustCall();
232256
await checkExecution();
233257
await checkInvalidOptionForEvaluate();
234258
checkInvalidCachedData();
259+
checkGettersErrors();
235260
finished();
236261
})().then(common.mustCall());

0 commit comments

Comments
 (0)