replayDataUtils.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {
  2. breadcrumbFactory,
  3. // breadcrumbValuesFromEvents,
  4. // replayTimestamps,
  5. rrwebEventListFactory,
  6. // spanDataFromEvents,
  7. // spanEntryFactory,
  8. } from 'sentry/utils/replays/replayDataUtils';
  9. describe('breadcrumbFactory', () => {
  10. function createSpan(extra: {
  11. op: string;
  12. data?: Record<string, any>;
  13. description?: string;
  14. }) {
  15. return {
  16. startTimestamp: 1,
  17. endTimestamp: 2,
  18. data: {},
  19. ...extra,
  20. };
  21. }
  22. it('adds LCP as a breadcrumb', () => {
  23. const rawSpans = [
  24. createSpan({
  25. op: 'foo',
  26. data: {},
  27. }),
  28. createSpan({
  29. op: 'largest-contentful-paint',
  30. data: {
  31. nodeId: 2,
  32. },
  33. }),
  34. ];
  35. const results = breadcrumbFactory(0, TestStubs.Event(), [], [], rawSpans);
  36. expect(results).toMatchInlineSnapshot(`
  37. Array [
  38. Object {
  39. "color": "gray300",
  40. "data": Object {
  41. "action": "replay-init",
  42. "label": "Start recording",
  43. "url": undefined,
  44. },
  45. "description": "Default",
  46. "id": 0,
  47. "level": "info",
  48. "message": undefined,
  49. "timestamp": "1970-01-01T00:00:00.000Z",
  50. "type": "init",
  51. },
  52. Object {
  53. "category": "default",
  54. "color": "purple300",
  55. "data": Object {
  56. "action": "largest-contentful-paint",
  57. "label": "LCP",
  58. "nodeId": 2,
  59. },
  60. "description": "Debug",
  61. "id": 1,
  62. "level": "info",
  63. "timestamp": "1970-01-01T00:00:01.000Z",
  64. "type": "debug",
  65. },
  66. ]
  67. `);
  68. });
  69. it('adds navigation as a breadcrumb', () => {
  70. const rawSpans = [
  71. createSpan({
  72. op: 'foo',
  73. data: {},
  74. }),
  75. createSpan({
  76. op: 'navigation.navigate',
  77. description: 'http://test.com',
  78. }),
  79. ];
  80. const results = breadcrumbFactory(0, TestStubs.Event(), [], [], rawSpans);
  81. expect(results).toMatchInlineSnapshot(`
  82. Array [
  83. Object {
  84. "action": "navigate",
  85. "category": "default",
  86. "color": "green300",
  87. "data": Object {
  88. "label": "Page load",
  89. "to": "http://test.com",
  90. },
  91. "description": "Navigation",
  92. "id": 0,
  93. "level": "info",
  94. "message": "http://test.com",
  95. "timestamp": "1970-01-01T00:00:01.000Z",
  96. "type": "navigation",
  97. },
  98. ]
  99. `);
  100. });
  101. });
  102. describe('rrwebEventListFactory', () => {
  103. it('returns a list of replay events for highlights', function () {
  104. const results = rrwebEventListFactory(0, 0, []);
  105. expect(results).toMatchInlineSnapshot(`
  106. Array [
  107. Object {
  108. "data": Object {
  109. "tag": "replay-end",
  110. },
  111. "timestamp": 0,
  112. "type": 5,
  113. },
  114. ]
  115. `);
  116. });
  117. it('merges and sorts rrweb-events and span data', function () {
  118. const startTimestampMs = 0;
  119. const endTimestampMs = 10_000;
  120. expect(
  121. rrwebEventListFactory(startTimestampMs, endTimestampMs, [
  122. {type: 0, timestamp: 5_000, data: {}},
  123. {type: 1, timestamp: 1_000, data: {}},
  124. {type: 2, timestamp: 3_000, data: {}},
  125. ])
  126. ).toEqual([
  127. {type: 1, timestamp: 0, data: {}},
  128. {type: 2, timestamp: 3_000, data: {}},
  129. {type: 0, timestamp: 5_000, data: {}},
  130. {type: 5, timestamp: 10_000, data: {tag: 'replay-end'}},
  131. ]);
  132. });
  133. });