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

Function run

test/addons/esm/test-esm.mjs:14–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12const require = createRequire(import.meta.url);
13
14export async function run() {
15 // binding.node
16 {
17 const bindingPath = require.resolve(`./build/${buildType}/binding.node`);
18 // Test with order of import+require
19 const { default: binding, 'module.exports': exports } = await import(pathToFileURL(bindingPath));
20 assert.strictEqual(binding, exports);
21 assert.strictEqual(binding.hello(), 'world');
22
23 const bindingRequire = require(bindingPath);
24 assert.strictEqual(binding, bindingRequire);
25 assert.strictEqual(binding.hello, bindingRequire.hello);
26
27 // Test multiple loading of the same addon.
28 // ESM cache can not be removed.
29 delete require.cache[bindingPath];
30 const { default: rebinding } = await import(pathToFileURL(bindingPath));
31 assert.strictEqual(rebinding.hello(), 'world');
32 assert.strictEqual(binding.hello, rebinding.hello);
33 }
34}

Calls 4

pathToFileURLFunction · 0.50
requireFunction · 0.50
resolveMethod · 0.45
helloMethod · 0.45

Tested by

no test coverage detected