hydrateSpans.spec.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {ReplayMemoryFrameFixture} from 'sentry-fixture/replay/replaySpanFrameData';
  2. import {ReplayRecordFixture} from 'sentry-fixture/replayRecord';
  3. import hydrateSpans from 'sentry/utils/replays/hydrateSpans';
  4. const ONE_HOUR_MS = 60 * 60 * 1000;
  5. const ONE_DAY_MS = ONE_HOUR_MS * 24;
  6. describe('hydrateSpans', () => {
  7. const replayRecord = ReplayRecordFixture({started_at: new Date('2023/12/23')});
  8. it('should set the start & end timestamps, & offsetMs for each span in the list', () => {
  9. const spans = [
  10. ReplayMemoryFrameFixture({
  11. startTimestamp: new Date('2023/12/23'),
  12. endTimestamp: new Date('2023/12/23 23:00'),
  13. }),
  14. ReplayMemoryFrameFixture({
  15. startTimestamp: new Date('2023/12/24'),
  16. endTimestamp: new Date('2023/12/24 23:00'),
  17. }),
  18. ReplayMemoryFrameFixture({
  19. startTimestamp: new Date('2023/12/25'),
  20. endTimestamp: new Date('2023/12/25 23:00'),
  21. }),
  22. ];
  23. expect(hydrateSpans(replayRecord, spans)).toStrictEqual([
  24. {
  25. op: 'memory',
  26. data: {memory: expect.any(Object)},
  27. description: '',
  28. endTimestamp: new Date('2023/12/23 23:00'),
  29. endTimestampMs: 1703307600000 + ONE_HOUR_MS * 23,
  30. offsetMs: 0,
  31. startTimestamp: new Date('2023/12/23'),
  32. timestampMs: 1703307600000,
  33. },
  34. {
  35. op: 'memory',
  36. data: {memory: expect.any(Object)},
  37. description: '',
  38. endTimestamp: new Date('2023/12/24 23:00'),
  39. endTimestampMs: 1703307600000 + ONE_DAY_MS + ONE_HOUR_MS * 23,
  40. offsetMs: ONE_DAY_MS,
  41. startTimestamp: new Date('2023/12/24'),
  42. timestampMs: 1703307600000 + ONE_DAY_MS,
  43. },
  44. {
  45. op: 'memory',
  46. data: {memory: expect.any(Object)},
  47. description: '',
  48. endTimestamp: new Date('2023/12/25 23:00'),
  49. endTimestampMs: 1703307600000 + ONE_DAY_MS * 2 + ONE_HOUR_MS * 23,
  50. offsetMs: ONE_DAY_MS * 2,
  51. startTimestamp: new Date('2023/12/25'),
  52. timestampMs: 1703307600000 + ONE_DAY_MS * 2,
  53. },
  54. ]);
  55. });
  56. it('should drop spans that cannot be parsed', () => {
  57. const spans = [{foo: 'bar'}];
  58. // @ts-expect-error: Explicitly test invalid input
  59. expect(hydrateSpans(replayRecord, spans)).toStrictEqual([]);
  60. });
  61. });