From 84eaaf4819ba004d3c3cab1e1918bd7283a428d4 Mon Sep 17 00:00:00 2001 From: Matt C Date: Mon, 20 Aug 2018 19:08:01 +0100 Subject: [PATCH] Tests now work Also they'll work in the node API too now --- src/core/operations/FromMessagePack.mjs | 5 +++-- src/core/operations/ToMessagePack.mjs | 8 ++++++-- test/tests/operations/Code.mjs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/operations/FromMessagePack.mjs b/src/core/operations/FromMessagePack.mjs index 727a31d7..20aa1f9f 100644 --- a/src/core/operations/FromMessagePack.mjs +++ b/src/core/operations/FromMessagePack.mjs @@ -28,13 +28,14 @@ class FromMessagePack extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {JSON} */ run(input, args) { try { - return notepack.decode(input); + const buf = Buffer.from(new Uint8Array(input)); + return notepack.decode(buf); } catch (err) { throw new OperationError(`Could not decode MessagePack to JSON: ${err}`); } diff --git a/src/core/operations/ToMessagePack.mjs b/src/core/operations/ToMessagePack.mjs index 30cb3ca7..f12dea77 100644 --- a/src/core/operations/ToMessagePack.mjs +++ b/src/core/operations/ToMessagePack.mjs @@ -34,10 +34,14 @@ class ToMessagePack extends Operation { */ run(input, args) { try { - return notepack.encode(input); + if (ENVIRONMENT_IS_WORKER()) { + return notepack.encode(input); + } else { + return notepack.encode(input).buffer; + } } catch (err) { throw new OperationError(`Could not encode JSON to MessagePack: ${err}`); - } + } } } diff --git a/test/tests/operations/Code.mjs b/test/tests/operations/Code.mjs index 77645442..795821f0 100644 --- a/test/tests/operations/Code.mjs +++ b/test/tests/operations/Code.mjs @@ -350,7 +350,7 @@ TestRegister.addTests([ { name: "From MessagePack: no content", input: "", - expectedOutput: "Could not decode MessagePack to JSON: RangeError: offset is outside the bounds of the DataView", + expectedOutput: "Could not decode MessagePack to JSON: Error: Could not parse", recipeConfig: [ { "op": "From Hex",