aboutsummaryrefslogtreecommitdiff
path: root/test/node-api/1_hello_world/test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/node-api/1_hello_world/test.js')
-rw-r--r--test/node-api/1_hello_world/test.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/node-api/1_hello_world/test.js b/test/node-api/1_hello_world/test.js
index d1d67d34f6..dd28e26a56 100644
--- a/test/node-api/1_hello_world/test.js
+++ b/test/node-api/1_hello_world/test.js
@@ -1,6 +1,8 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
+const { Worker } = require('worker_threads');
+
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
const binding = require(bindingPath);
assert.strictEqual(binding.hello(), 'world');
@@ -11,3 +13,10 @@ delete require.cache[bindingPath];
const rebinding = require(bindingPath);
assert.strictEqual(rebinding.hello(), 'world');
assert.notStrictEqual(binding.hello, rebinding.hello);
+
+// Test that workers can load addons declared using NAPI_MODULE_INIT().
+new Worker(`
+const { parentPort } = require('worker_threads');
+const msg = require(${JSON.stringify(bindingPath)}).hello();
+parentPort.postMessage(msg)`, { eval: true })
+ .on('message', common.mustCall((msg) => assert.strictEqual(msg, 'world')));