Skip to content

Commit

Permalink
test: augment tests for SourceTextModule
Browse files Browse the repository at this point in the history
Adds tests for a few error conditions. Also, adds tests to make sure
the dynamically generated url is correct.

PR-URL: nodejs#23573
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

PR-URL: nodejs#23572
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
aeisenberg authored and BridgeAR committed Oct 15, 2018
1 parent 14685ad commit 2160168
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/parallel/test-vm-module-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
})();
14 changes: 13 additions & 1 deletion test/parallel/test-vm-module-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 2160168

Please sign in to comment.