hydrateSpans.spec.tsx 2.1 KB

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