Skip to content

Commit dd9864b

Browse files
alyssaqBridgeAR
authored andcommitted
test: check for invalid module type in vm.js
PR-URL: #24161 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 957ceaa commit dd9864b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

test/parallel/test-vm-module-dynamic-import.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,34 @@ async function testInvalid() {
6868
await result.catch(common.mustCall((e) => {
6969
assert.strictEqual(e.code, 'ERR_VM_MODULE_NOT_MODULE');
7070
}));
71+
72+
const s = new Script('import("foo")', {
73+
importModuleDynamically: common.mustCall((specifier, wrap) => {
74+
return undefined;
75+
}),
76+
});
77+
let threw = false;
78+
try {
79+
await s.runInThisContext();
80+
} catch (e) {
81+
threw = true;
82+
assert.strictEqual(e.code, 'ERR_VM_MODULE_NOT_MODULE');
83+
}
84+
assert(threw);
85+
}
86+
87+
async function testInvalidimportModuleDynamically() {
88+
assert.throws(
89+
() => new Script(
90+
'import("foo")',
91+
{ importModuleDynamically: false }),
92+
{ code: 'ERR_INVALID_ARG_TYPE' }
93+
);
7194
}
7295

73-
const done = common.mustCallAtLeast(3);
7496
(async function() {
7597
await testNoCallback();
76-
done();
77-
7898
await test();
79-
done();
80-
8199
await testInvalid();
82-
done();
100+
await testInvalidimportModuleDynamically();
83101
}()).then(common.mustCall());

0 commit comments

Comments
 (0)