MCPcopy Index your code
hub / github.com/nodejs/node / testModule

Function testModule

test/parallel/test-vm-module-dynamic-import-promise.js:68–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66}
67
68async function testModule() {
69 const ctx = createContext();
70
71 const mod1 = new SourceTextModule('export const a = 1;', {
72 context: ctx,
73 });
74 // No import statements, so must not link statically.
75 await mod1.link(common.mustNotCall());
76
77 const mod2 = new SourceTextModule(`
78 const promise = import("mod1");
79 if (Object.getPrototypeOf(promise) !== Promise.prototype) {
80 throw new Error('Expected promise to be created in the current context');
81 }
82 await promise;
83 `, {
84 context: ctx,
85 importModuleDynamically: common.mustCall((specifier, referrer) => {
86 assert.strictEqual(specifier, 'mod1');
87 assert.strictEqual(referrer, mod2);
88 return mod1;
89 }),
90 });
91 // No import statements, so must not link statically.
92 await mod2.link(common.mustNotCall());
93 await mod2.evaluate();
94}
95
96async function testModuleImportFailed() {
97 const ctx = createContext();

Calls 3

createContextFunction · 0.85
linkMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…