compare.js 1.4 KB

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