From d0d57a6da92ece63a2cdd42f32e6ce4b1a44b980 Mon Sep 17 00:00:00 2001 From: Julien Wajsberg Date: Mon, 25 Mar 2019 11:48:10 +0100 Subject: [PATCH] Work around a change in the worker_threads module Fixes #1879 --- src/utils/__mocks__/worker-factory.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utils/__mocks__/worker-factory.js b/src/utils/__mocks__/worker-factory.js index 63934de0b7..baed7c5377 100644 --- a/src/utils/__mocks__/worker-factory.js +++ b/src/utils/__mocks__/worker-factory.js @@ -23,7 +23,19 @@ class NodeWorker { message: mixed, transfer?: Array ) { - this._instance.postMessage({ data: message }, transfer); + let payload = message; + + // Starting with node v11.12, postMessage sends the payload using the same + // semantics than Web Workers. This code adds the support for older node + // versions. We can remove this thin compatibility layer when we stop + // supporting these node versions. + const nodeVersion = process.versions.node; + const [major, minor] = nodeVersion.split('.'); + + if (+major < 11 || (+major === 11 && +minor < 12)) { + payload = { data: message }; + } + this._instance.postMessage(payload, transfer); } onMessage = (message: Object) => {