Skip to content

Commit

Permalink
vm: increase code coverage of source_text_module.js
Browse files Browse the repository at this point in the history
PR-URL: #28350
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
kball authored and targos committed Aug 2, 2019
1 parent 2142b6d commit b282c85
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/parallel/test-vm-module-dynamic-namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

// Flags: --experimental-vm-modules --expose-internals
//
const common = require('../common');

const assert = require('assert');

const { types } = require('util');
const { SourceTextModule, wrapMap } = require('internal/vm/source_text_module');

const { importModuleDynamicallyCallback } =
require('internal/process/esm_loader');

async function getNamespace() {
const m = new SourceTextModule('');
await m.link(() => 0);
m.instantiate();
await m.evaluate();
return m.namespace;
}

(async () => {
const namespace = await getNamespace();
const m = new SourceTextModule('export const A = "A";', {
importModuleDynamically: common.mustCall((specifier, wrap) => {
return namespace;
})
});
await m.link(() => 0);
m.instantiate();
await m.evaluate();
const ns = await importModuleDynamicallyCallback(wrapMap.get(m));
assert.ok(types.isModuleNamespaceObject(ns));
})().then(common.mustCall());

0 comments on commit b282c85

Please sign in to comment.