diff --git a/test/parallel/test-vm-module-basic.js b/test/parallel/test-vm-module-basic.js index ffe376ccc2b1b1..8cf687c2bb23a8 100644 --- a/test/parallel/test-vm-module-basic.js +++ b/test/parallel/test-vm-module-basic.js @@ -50,3 +50,16 @@ const { SourceTextModule, createContext } = require('vm'); await m.evaluate({ timeout: 500 }) .then(() => assert(false), () => {}); })(); + +// Check the generated url for each module +(async () => { + const context1 = createContext({ }); + const context2 = createContext({ }); + + const m1 = new SourceTextModule('1', { context: context1 }); + assert.strictEqual(m1.url, 'vm:module(0)'); + const m2 = new SourceTextModule('2', { context: context1 }); + assert.strictEqual(m2.url, 'vm:module(1)'); + const m3 = new SourceTextModule('3', { context: context2 }); + assert.strictEqual(m3.url, 'vm:module(0)'); +})(); diff --git a/test/parallel/test-vm-module-errors.js b/test/parallel/test-vm-module-errors.js index a6b2a6e797a1bb..05022160832a53 100644 --- a/test/parallel/test-vm-module-errors.js +++ b/test/parallel/test-vm-module-errors.js @@ -43,7 +43,8 @@ async function checkArgType() { }); for (const invalidOptions of [ - 0, 1, null, true, 'str', () => {}, { url: 0 }, Symbol.iterator + 0, 1, null, true, 'str', () => {}, { url: 0 }, Symbol.iterator, + { context: null }, { context: 'hucairz' }, { context: {} } ]) { common.expectsError(() => { new SourceTextModule('', invalidOptions); @@ -231,6 +232,17 @@ async function checkLinking() { }); } +common.expectsError(() => { + new SourceTextModule('', { + importModuleDynamically: 'hucairz' + }); +}, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options.importModuleDynamically"' + + ' property must be of type function. Received type string' +}); + // Check the JavaScript engine deals with exceptions correctly async function checkExecution() { await (async () => {