1'use strict';
2const common = require('../../common');
3const assert = require('assert');
4const { Worker } = require('worker_threads');
5
6const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
7const binding = require(bindingPath);
8assert.strictEqual(binding.hello(), 'world');
9console.log('binding.hello() =', binding.hello());
10
11// Test multiple loading of the same module.
12delete require.cache[bindingPath];
13const rebinding = require(bindingPath);
14assert.strictEqual(rebinding.hello(), 'world');
15assert.notStrictEqual(binding.hello, rebinding.hello);
16
17// Test that workers can load addons declared using NAPI_MODULE_INIT().
18new Worker(`
19const { parentPort } = require('worker_threads');
20const msg = require(${JSON.stringify(bindingPath)}).hello();
21parentPort.postMessage(msg)`, { eval: true })
22  .on('message', common.mustCall((msg) => assert.strictEqual(msg, 'world')));
23