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

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

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

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

77
constassert=require('assert');
88

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

1111
asyncfunctioncreateEmptyLinkedModule(){
1212
constm=newSourceTextModule('');
@@ -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+
awaitassert.rejects(async()=>{
212+
awaitModule.prototype[method]();
213+
},{
214+
code: 'ERR_VM_MODULE_NOT_MODULE',
215+
message: /ProvidedmoduleisnotaninstanceofModule/
216+
});
217+
});
218+
}
208219
}
209220

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

237+
functioncheckGettersErrors(){
238+
constgetters=['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: /ProvidedmoduleisnotaninstanceofModule/
246+
});
247+
});
248+
}
249+
226250
constfinished=common.mustCall();
227251

228252
(asyncfunctionmain(){
@@ -232,5 +256,6 @@ const finished = common.mustCall();
232256
awaitcheckExecution();
233257
awaitcheckInvalidOptionForEvaluate();
234258
checkInvalidCachedData();
259+
checkGettersErrors();
235260
finished();
236261
})().then(common.mustCall());

0 commit comments

Comments
 (0)