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

Function main

test/es-module/test-vm-main-context-default-loader-eval.js:40–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38assert.strictEqual(typeof USE_MAIN_CONTEXT_DEFAULT_LOADER, 'symbol');
39
40async function main() {
41 tmpdir.refresh();
42 process.chdir(tmpdir.path);
43
44 //
45 {
46 const options = {
47 importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
48 };
49 const ctx = createContext({}, options);
50 const s = new Script('Promise.resolve("import(\'./message.mjs\')").then(eval)', {
51 importModuleDynamically: common.mustNotCall(),
52 });
53 await assert.rejects(s.runInContext(ctx), { code: 'ERR_MODULE_NOT_FOUND' });
54 }
55
56 const moduleUrl = fixtures.fileURL('es-modules', 'message.mjs');
57 fs.copyFileSync(moduleUrl, tmpdir.resolve('message.mjs'));
58 {
59 const options = {
60 importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
61 };
62 const ctx = createContext({}, options);
63 const moduleUrl = fixtures.fileURL('es-modules', 'message.mjs');
64 const namespace = await import(moduleUrl.href);
65 const script = new Script('Promise.resolve("import(\'./message.mjs\')").then(eval)', {
66 importModuleDynamically: common.mustNotCall(),
67 });
68 const result = await script.runInContext(ctx);
69 assert.deepStrictEqual(result, namespace);
70 }
71}
72
73main().then(common.mustCall());

Calls 6

runInContextMethod · 0.95
createContextFunction · 0.85
chdirMethod · 0.80
refreshMethod · 0.45
copyFileSyncMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…