1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.compareArrayBuffers = compareArrayBuffers;
|
---|
7 |
|
---|
8 | // this are dev dependencies
|
---|
9 | var diff = require("jest-diff");
|
---|
10 |
|
---|
11 | var _require = require("jest-diff/build/constants"),
|
---|
12 | NO_DIFF_MESSAGE = _require.NO_DIFF_MESSAGE;
|
---|
13 |
|
---|
14 | var _require2 = require("@webassemblyjs/wasm-parser"),
|
---|
15 | decode = _require2.decode;
|
---|
16 |
|
---|
17 | var oldConsoleLog = console.log;
|
---|
18 |
|
---|
19 | function compareArrayBuffers(l, r) {
|
---|
20 | /**
|
---|
21 | * Decode left
|
---|
22 | */
|
---|
23 | var bufferL = "";
|
---|
24 |
|
---|
25 | console.log = function () {
|
---|
26 | for (var _len = arguments.length, texts = new Array(_len), _key = 0; _key < _len; _key++) {
|
---|
27 | texts[_key] = arguments[_key];
|
---|
28 | }
|
---|
29 |
|
---|
30 | return bufferL += texts.join("") + "\n";
|
---|
31 | };
|
---|
32 |
|
---|
33 | try {
|
---|
34 | decode(l, {
|
---|
35 | dump: true
|
---|
36 | });
|
---|
37 | } catch (e) {
|
---|
38 | console.error(bufferL);
|
---|
39 | console.error(e);
|
---|
40 | throw e;
|
---|
41 | }
|
---|
42 | /**
|
---|
43 | * Decode right
|
---|
44 | */
|
---|
45 |
|
---|
46 |
|
---|
47 | var bufferR = "";
|
---|
48 |
|
---|
49 | console.log = function () {
|
---|
50 | for (var _len2 = arguments.length, texts = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
---|
51 | texts[_key2] = arguments[_key2];
|
---|
52 | }
|
---|
53 |
|
---|
54 | return bufferR += texts.join("") + "\n";
|
---|
55 | };
|
---|
56 |
|
---|
57 | try {
|
---|
58 | decode(r, {
|
---|
59 | dump: true
|
---|
60 | });
|
---|
61 | } catch (e) {
|
---|
62 | console.error(bufferR);
|
---|
63 | console.error(e);
|
---|
64 | throw e;
|
---|
65 | }
|
---|
66 |
|
---|
67 | console.log = oldConsoleLog;
|
---|
68 | var out = diff(bufferL, bufferR);
|
---|
69 |
|
---|
70 | if (out !== null && out !== NO_DIFF_MESSAGE) {
|
---|
71 | throw new Error("\n" + out);
|
---|
72 | }
|
---|
73 | } |
---|