|
| 1 | +import { vi } from 'vitest'; |
| 2 | + |
| 3 | +import { getClient } from '@sentry/core'; |
| 4 | +import type { Transport } from '@sentry/types'; |
| 5 | + |
| 6 | +import { DEFAULT_FLUSH_MIN_DELAY, SESSION_IDLE_EXPIRE_DURATION } from '../../src/constants'; |
| 7 | +import type { Replay } from '../../src/integration'; |
| 8 | +import type { ReplayContainer } from '../../src/replay'; |
| 9 | +import { BASE_TIMESTAMP } from '../index'; |
| 10 | +import { resetSdkMock } from '../mocks/resetSdkMock'; |
| 11 | +import { useFakeTimers } from '../utils/use-fake-timers'; |
| 12 | + |
| 13 | +useFakeTimers(); |
| 14 | + |
| 15 | +describe('Integration | start', () => { |
| 16 | + let replay: ReplayContainer; |
| 17 | + let integration: Replay; |
| 18 | + |
| 19 | + beforeEach(async () => { |
| 20 | + ({ replay, integration } = await resetSdkMock({ |
| 21 | + replayOptions: { |
| 22 | + stickySession: false, |
| 23 | + }, |
| 24 | + sentryOptions: { |
| 25 | + replaysSessionSampleRate: 0.0, |
| 26 | + }, |
| 27 | + })); |
| 28 | + |
| 29 | + const mockTransport = getClient()?.getTransport()?.send as vi.MockedFunction<Transport['send']>; |
| 30 | + mockTransport?.mockClear(); |
| 31 | + await vi.runAllTimersAsync(); |
| 32 | + }); |
| 33 | + |
| 34 | + afterEach(async () => { |
| 35 | + integration.stop(); |
| 36 | + |
| 37 | + await vi.runAllTimersAsync(); |
| 38 | + vi.setSystemTime(new Date(BASE_TIMESTAMP)); |
| 39 | + }); |
| 40 | + |
| 41 | + it('sends replay when calling `start()` after [SESSION_IDLE_EXPIRE_DURATION]ms', async () => { |
| 42 | + await vi.advanceTimersByTimeAsync(SESSION_IDLE_EXPIRE_DURATION + 1); |
| 43 | + |
| 44 | + integration.start(); |
| 45 | + |
| 46 | + await vi.advanceTimersByTimeAsync(DEFAULT_FLUSH_MIN_DELAY); |
| 47 | + |
| 48 | + expect(replay).toHaveLastSentReplay({ |
| 49 | + recordingPayloadHeader: { segment_id: 0 }, |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments