From f5db04dcbdaf64b95bd6ca670224d2a9aec31a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 24 Jun 2018 20:23:36 +0200 Subject: [PATCH] workers: add test for messagePort.onmessage PR-URL: https://github.com/nodejs/node/pull/21510 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Yuta Hiroto Reviewed-By: Trivikram Kamat Reviewed-By: Weijia Wang Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-worker-onmessage.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/parallel/test-worker-onmessage.js diff --git a/test/parallel/test-worker-onmessage.js b/test/parallel/test-worker-onmessage.js new file mode 100644 index 00000000000000..895536c15038be --- /dev/null +++ b/test/parallel/test-worker-onmessage.js @@ -0,0 +1,18 @@ +// Flags: --experimental-worker +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { Worker, isMainThread, parentPort } = require('worker_threads'); + +if (isMainThread) { + const w = new Worker(__filename); + w.on('message', common.mustCall((message) => { + assert.strictEqual(message, 4); + w.terminate(); + })); + w.postMessage(2); +} else { + parentPort.onmessage = common.mustCall((message) => { + parentPort.postMessage(message * 2); + }); +}