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

Function testScript

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

Source from the content-addressed store, hash-verified

11// callback.
12
13async function testScript() {
14 const ctx = createContext();
15
16 const mod1 = new SourceTextModule('export const a = 1;', {
17 context: ctx,
18 });
19 // No import statements, so must not link statically.
20 await mod1.link(common.mustNotCall());
21
22 const script2 = new Script(`
23 const promise = import("mod1");
24 if (Object.getPrototypeOf(promise) !== Promise.prototype) {
25 throw new Error('Expected promise to be created in the current context');
26 }
27 globalThis.__result = promise;
28 `, {
29 importModuleDynamically: common.mustCall((specifier, referrer) => {
30 assert.strictEqual(specifier, 'mod1');
31 assert.strictEqual(referrer, script2);
32 return mod1;
33 }),
34 });
35 script2.runInContext(ctx);
36
37 // Wait for the promise to resolve.
38 await ctx.__result;
39}
40
41async function testScriptImportFailed() {
42 const ctx = createContext();

Calls 3

runInContextMethod · 0.95
createContextFunction · 0.85
linkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…