ReactTestComponent.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.test = exports.serialize = exports.default = void 0;
  6. var _markup = require('./lib/markup');
  7. var global = (function () {
  8. if (typeof globalThis !== 'undefined') {
  9. return globalThis;
  10. } else if (typeof global !== 'undefined') {
  11. return global;
  12. } else if (typeof self !== 'undefined') {
  13. return self;
  14. } else if (typeof window !== 'undefined') {
  15. return window;
  16. } else {
  17. return Function('return this')();
  18. }
  19. })();
  20. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  21. const testSymbol =
  22. typeof Symbol === 'function' && Symbol.for
  23. ? Symbol.for('react.test.json')
  24. : 0xea71357;
  25. const getPropKeys = object => {
  26. const {props} = object;
  27. return props
  28. ? Object.keys(props)
  29. .filter(key => props[key] !== undefined)
  30. .sort()
  31. : [];
  32. };
  33. const serialize = (object, config, indentation, depth, refs, printer) =>
  34. ++depth > config.maxDepth
  35. ? (0, _markup.printElementAsLeaf)(object.type, config)
  36. : (0, _markup.printElement)(
  37. object.type,
  38. object.props
  39. ? (0, _markup.printProps)(
  40. getPropKeys(object),
  41. object.props,
  42. config,
  43. indentation + config.indent,
  44. depth,
  45. refs,
  46. printer
  47. )
  48. : '',
  49. object.children
  50. ? (0, _markup.printChildren)(
  51. object.children,
  52. config,
  53. indentation + config.indent,
  54. depth,
  55. refs,
  56. printer
  57. )
  58. : '',
  59. config,
  60. indentation
  61. );
  62. exports.serialize = serialize;
  63. const test = val => val && val.$$typeof === testSymbol;
  64. exports.test = test;
  65. const plugin = {
  66. serialize,
  67. test
  68. };
  69. var _default = plugin;
  70. exports.default = _default;