test: check for invalid module type in vm.js
PR-URL: https://github.com/nodejs/node/pull/24161 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
8e3c5b59bf
commit
dde9b3a0d3
@ -68,16 +68,34 @@ async function testInvalid() {
|
||||
await result.catch(common.mustCall((e) => {
|
||||
assert.strictEqual(e.code, 'ERR_VM_MODULE_NOT_MODULE');
|
||||
}));
|
||||
|
||||
const s = new Script('import("foo")', {
|
||||
importModuleDynamically: common.mustCall((specifier, wrap) => {
|
||||
return undefined;
|
||||
}),
|
||||
});
|
||||
let threw = false;
|
||||
try {
|
||||
await s.runInThisContext();
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
assert.strictEqual(e.code, 'ERR_VM_MODULE_NOT_MODULE');
|
||||
}
|
||||
assert(threw);
|
||||
}
|
||||
|
||||
async function testInvalidimportModuleDynamically() {
|
||||
assert.throws(
|
||||
() => new Script(
|
||||
'import("foo")',
|
||||
{ importModuleDynamically: false }),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
}
|
||||
|
||||
const done = common.mustCallAtLeast(3);
|
||||
(async function() {
|
||||
await testNoCallback();
|
||||
done();
|
||||
|
||||
await test();
|
||||
done();
|
||||
|
||||
await testInvalid();
|
||||
done();
|
||||
await testInvalidimportModuleDynamically();
|
||||
}()).then(common.mustCall());
|
||||
|
Loading…
x
Reference in New Issue
Block a user