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

Function main

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

Source from the content-addressed store, hash-verified

71}
72
73async function main() {
74 {
75 // Importing with absolute path as filename.
76 tmpdir.refresh();
77 const filename = tmpdir.resolve('index.js');
78 const options = {
79 filename,
80 importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
81 };
82 await testNotFoundErrors(options);
83 await testLoader(options);
84 }
85
86 {
87 // Importing with file:// URL as filename.
88 tmpdir.refresh();
89 // We use a search parameter to bypass caching.
90 const filename = url.pathToFileURL(tmpdir.resolve('index.js')).href + '?t=1';
91 const options = {
92 filename,
93 importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
94 };
95 await testNotFoundErrors(options);
96 await testLoader(options);
97 }
98
99 {
100 // For undefined or non-path/URL filenames, import() should resolve to the cwd.
101 tmpdir.refresh();
102 process.chdir(tmpdir.path);
103 const undefinedOptions = {
104 importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
105 };
106 const nonPathOptions = {
107 filename: 'non-path',
108 importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
109 };
110 // Run the error tests first to avoid caching.
111 await testNotFoundErrors(undefinedOptions);
112 await testNotFoundErrors(nonPathOptions);
113
114 await testLoader(undefinedOptions);
115 await testLoader(nonPathOptions);
116 }
117}
118
119main().then(common.mustCall());

Calls 6

testNotFoundErrorsFunction · 0.85
testLoaderFunction · 0.85
pathToFileURLMethod · 0.80
chdirMethod · 0.80
refreshMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…