11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst bindingPath = require.resolve(`./build/${common.buildType}/binding`); 71cb0ef41Sopenharmony_ciconst binding = require(bindingPath); 81cb0ef41Sopenharmony_ciassert.strictEqual(binding.hello(), 'world'); 91cb0ef41Sopenharmony_ciconsole.log('binding.hello() =', binding.hello()); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci// Test multiple loading of the same module. 121cb0ef41Sopenharmony_cidelete require.cache[bindingPath]; 131cb0ef41Sopenharmony_ciconst rebinding = require(bindingPath); 141cb0ef41Sopenharmony_ciassert.strictEqual(rebinding.hello(), 'world'); 151cb0ef41Sopenharmony_ciassert.notStrictEqual(binding.hello, rebinding.hello); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci// Test that workers can load addons declared using NAPI_MODULE_INIT(). 181cb0ef41Sopenharmony_cinew Worker(` 191cb0ef41Sopenharmony_ciconst { parentPort } = require('worker_threads'); 201cb0ef41Sopenharmony_ciconst msg = require(${JSON.stringify(bindingPath)}).hello(); 211cb0ef41Sopenharmony_ciparentPort.postMessage(msg)`, { eval: true }) 221cb0ef41Sopenharmony_ci .on('message', common.mustCall((msg) => assert.strictEqual(msg, 'world'))); 23