From c077c21ab899dfefe691f7b563fe9a4e73471523 Mon Sep 17 00:00:00 2001 From: legendecas Date: Fri, 15 Feb 2019 16:14:11 +0800 Subject: [PATCH] test,worker: posting undefined/null message to message port Related: https://github.com/nodejs/node/issues/26122 PR-URL: https://github.com/nodejs/node/pull/26123 Reviewed-By: Anna Henningsen Reviewed-By: Denys Otrishko Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-worker-onmessage.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-worker-onmessage.js b/test/parallel/test-worker-onmessage.js index f315b0d2019a9a..3ed10755cece28 100644 --- a/test/parallel/test-worker-onmessage.js +++ b/test/parallel/test-worker-onmessage.js @@ -7,13 +7,20 @@ const { Worker, parentPort } = require('worker_threads'); if (!process.env.HAS_STARTED_WORKER) { process.env.HAS_STARTED_WORKER = 1; const w = new Worker(__filename); + const expectation = [ 4, undefined, null ]; + const actual = []; w.on('message', common.mustCall((message) => { - assert.strictEqual(message, 4); - w.terminate(); - })); + actual.push(message); + if (actual.length === expectation.length) { + assert.deepStrictEqual(expectation, actual); + w.terminate(); + } + }, expectation.length)); w.postMessage(2); } else { parentPort.onmessage = common.mustCall((message) => { parentPort.postMessage(message.data * 2); + parentPort.postMessage(undefined); + parentPort.postMessage(null); }); }