|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | + |
| 5 | +import { describe, expect, test } from 'vitest'; |
| 6 | +import { resetSdkMock } from '../mocks/resetSdkMock'; |
| 7 | +import { useFakeTimers } from '../utils/use-fake-timers'; |
| 8 | + |
| 9 | +useFakeTimers(); |
| 10 | + |
| 11 | +describe('Integration | getRecordingMode()', () => { |
| 12 | + test('returns "session" when session sampling is enabled', async () => { |
| 13 | + const { integration } = await resetSdkMock({ |
| 14 | + replayOptions: { |
| 15 | + stickySession: false, |
| 16 | + }, |
| 17 | + sentryOptions: { |
| 18 | + replaysSessionSampleRate: 1.0, |
| 19 | + }, |
| 20 | + }); |
| 21 | + expect(integration.getRecordingMode()).toBe('session'); |
| 22 | + }); |
| 23 | + |
| 24 | + test('returns "buffer" when buffering is enabled', async () => { |
| 25 | + const { integration, replay } = await resetSdkMock({ |
| 26 | + replayOptions: { |
| 27 | + stickySession: false, |
| 28 | + }, |
| 29 | + sentryOptions: { |
| 30 | + replaysSessionSampleRate: 1.0, |
| 31 | + }, |
| 32 | + }); |
| 33 | + replay.stop(); |
| 34 | + replay.startBuffering(); |
| 35 | + expect(integration.getRecordingMode()).toBe('buffer'); |
| 36 | + }); |
| 37 | + |
| 38 | + test('returns undefined when replay is stopped', async () => { |
| 39 | + const { integration, replay } = await resetSdkMock({ |
| 40 | + replayOptions: { |
| 41 | + stickySession: false, |
| 42 | + }, |
| 43 | + sentryOptions: { |
| 44 | + replaysSessionSampleRate: 1.0, |
| 45 | + }, |
| 46 | + }); |
| 47 | + replay.stop(); |
| 48 | + expect(integration.getRecordingMode()).toBeUndefined(); |
| 49 | + }); |
| 50 | + |
| 51 | + test('returns undefined when session sampling is disabled', async () => { |
| 52 | + const { integration } = await resetSdkMock({ |
| 53 | + replayOptions: { stickySession: false }, |
| 54 | + sentryOptions: { |
| 55 | + replaysSessionSampleRate: 0.0, |
| 56 | + replaysOnErrorSampleRate: 0.0, |
| 57 | + }, |
| 58 | + }); |
| 59 | + expect(integration.getRecordingMode()).toBeUndefined(); |
| 60 | + }); |
| 61 | + |
| 62 | + test('returns "buffer" when session rate is 0 and onError rate is 1', async () => { |
| 63 | + const { integration } = await resetSdkMock({ |
| 64 | + replayOptions: { stickySession: false }, |
| 65 | + sentryOptions: { |
| 66 | + replaysSessionSampleRate: 0.0, |
| 67 | + replaysOnErrorSampleRate: 1.0, |
| 68 | + }, |
| 69 | + }); |
| 70 | + expect(integration.getRecordingMode()).toBe('buffer'); |
| 71 | + }); |
| 72 | + |
| 73 | + test('returns "session" when both sampling rates are 1', async () => { |
| 74 | + const { integration } = await resetSdkMock({ |
| 75 | + replayOptions: { stickySession: false }, |
| 76 | + sentryOptions: { |
| 77 | + replaysSessionSampleRate: 1.0, |
| 78 | + replaysOnErrorSampleRate: 1.0, |
| 79 | + }, |
| 80 | + }); |
| 81 | + expect(integration.getRecordingMode()).toBe('session'); |
| 82 | + }); |
| 83 | +}); |
0 commit comments