You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compare.js 1.3KB

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