diff --git a/lib/worker_threads.js b/lib/worker_threads.js index 828edb6bffc..2fe1a872464 100644 --- a/lib/worker_threads.js +++ b/lib/worker_threads.js @@ -17,5 +17,6 @@ module.exports = { MessageChannel, threadId, Worker, - parentPort: null + parentPort: null, + workerData: null, }; diff --git a/test/fixtures/worker-data.mjs b/test/fixtures/worker-data.mjs new file mode 100644 index 00000000000..1ec884aadb1 --- /dev/null +++ b/test/fixtures/worker-data.mjs @@ -0,0 +1,3 @@ +import { workerData, parentPort } from 'worker_threads'; + +parentPort.postMessage(workerData); diff --git a/test/parallel/test-worker-mjs-workerdata.js b/test/parallel/test-worker-mjs-workerdata.js new file mode 100644 index 00000000000..c107730ea4b --- /dev/null +++ b/test/parallel/test-worker-mjs-workerdata.js @@ -0,0 +1,16 @@ +'use strict'; +const common = require('../common'); +const fixtures = require('../common/fixtures'); +const assert = require('assert'); +const { Worker } = require('worker_threads'); + +const workerData = 'Hello from main thread'; + +const worker = new Worker(fixtures.path('worker-data.mjs'), { + workerData, + execArgv: ['--experimental-modules'] +}); + +worker.on('message', common.mustCall((message) => { + assert.strictEqual(message, workerData); +}));