瀏覽代碼

Tests now work

Also they'll work in the node API too now
Matt C 7 年之前
父節點
當前提交
84eaaf4819
共有 3 個文件被更改,包括 10 次插入5 次删除
  1. 3 2
      src/core/operations/FromMessagePack.mjs
  2. 6 2
      src/core/operations/ToMessagePack.mjs
  3. 1 1
      test/tests/operations/Code.mjs

+ 3 - 2
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}`);
         }

+ 6 - 2
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}`);
-        }   
+        }
     }
 
 }

+ 1 - 1
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",