Skip to content

Commit

Permalink
test: check for invalid module type in vm.js
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
alyssaq authored and BridgeAR committed Nov 13, 2018
1 parent 957ceaa commit dd9864b
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions test/parallel/test-vm-module-dynamic-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

0 comments on commit dd9864b

Please sign in to comment.