replayDataUtils.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import {
  2. breadcrumbFactory,
  3. // breadcrumbValuesFromEvents,
  4. rrwebEventListFactory,
  5. // spanDataFromEvents,
  6. // spanEntryFactory,
  7. } from 'sentry/utils/replays/replayDataUtils';
  8. import type {ReplayRecord} from 'sentry/views/replays/types';
  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(
  36. TestStubs.Event({
  37. startedAt: new Date(0),
  38. }),
  39. [],
  40. [],
  41. rawSpans
  42. );
  43. expect(results).toMatchInlineSnapshot(`
  44. Array [
  45. Object {
  46. "color": "gray300",
  47. "data": Object {
  48. "action": "replay-init",
  49. "label": "Start recording",
  50. "url": undefined,
  51. },
  52. "description": "Default",
  53. "id": 0,
  54. "level": "info",
  55. "message": undefined,
  56. "timestamp": "1970-01-01T00:00:00.000Z",
  57. "type": "init",
  58. },
  59. Object {
  60. "category": "default",
  61. "color": "purple300",
  62. "data": Object {
  63. "action": "largest-contentful-paint",
  64. "label": "LCP",
  65. "nodeId": 2,
  66. },
  67. "description": "Debug",
  68. "id": 1,
  69. "level": "info",
  70. "timestamp": "1970-01-01T00:00:01.000Z",
  71. "type": "debug",
  72. },
  73. ]
  74. `);
  75. });
  76. it('adds navigation as a breadcrumb', () => {
  77. const rawSpans = [
  78. createSpan({
  79. op: 'foo',
  80. data: {},
  81. }),
  82. createSpan({
  83. op: 'navigation.navigate',
  84. description: 'http://test.com',
  85. }),
  86. ];
  87. const results = breadcrumbFactory(
  88. TestStubs.Event({
  89. startedAt: new Date(0),
  90. }),
  91. [],
  92. [],
  93. rawSpans
  94. );
  95. expect(results).toMatchInlineSnapshot(`
  96. Array [
  97. Object {
  98. "action": "navigate",
  99. "category": "default",
  100. "color": "green300",
  101. "data": Object {
  102. "label": "Page load",
  103. "to": "http://test.com",
  104. },
  105. "description": "Navigation",
  106. "id": 0,
  107. "level": "info",
  108. "message": "http://test.com",
  109. "timestamp": "1970-01-01T00:00:01.000Z",
  110. "type": "navigation",
  111. },
  112. ]
  113. `);
  114. });
  115. });
  116. describe('rrwebEventListFactory', () => {
  117. it('returns a list of replay events for highlights', function () {
  118. const replayRecord = {
  119. startedAt: new Date(13),
  120. finishedAt: new Date(213),
  121. } as ReplayRecord;
  122. const results = rrwebEventListFactory(replayRecord, []);
  123. expect(results).toMatchInlineSnapshot(`
  124. Array [
  125. Object {
  126. "data": Object {
  127. "tag": "replay-end",
  128. },
  129. "timestamp": 13,
  130. "type": 5,
  131. },
  132. ]
  133. `);
  134. });
  135. it('merges and sorts rrweb-events and span data', function () {
  136. const startTimestampMs = 0;
  137. const endTimestampMs = 10_000;
  138. const replayRecord = {
  139. startedAt: new Date(startTimestampMs),
  140. finishedAt: new Date(endTimestampMs),
  141. } as ReplayRecord;
  142. expect(
  143. rrwebEventListFactory(replayRecord, [
  144. {type: 0, timestamp: 5_000, data: {}},
  145. {type: 1, timestamp: 1_000, data: {}},
  146. {type: 2, timestamp: 3_000, data: {}},
  147. ])
  148. ).toEqual([
  149. {type: 1, timestamp: 0, data: {}},
  150. {type: 2, timestamp: 3_000, data: {}},
  151. {type: 0, timestamp: 5_000, data: {}},
  152. {type: 5, timestamp: 10_000, data: {tag: 'replay-end'}},
  153. ]);
  154. });
  155. });