|
| 1 | +import { mockSdk } from '@test'; |
| 2 | + |
| 3 | +import { Replay } from '../../src'; |
| 4 | + |
| 5 | +let replay: Replay; |
| 6 | + |
| 7 | +beforeEach(() => { |
| 8 | + jest.resetModules(); |
| 9 | +}); |
| 10 | + |
| 11 | +describe('blockAllMedia', () => { |
| 12 | + it('sets the correct configuration when `blockAllMedia` is disabled', async () => { |
| 13 | + ({ replay } = await mockSdk({ replayOptions: { blockAllMedia: false } })); |
| 14 | + |
| 15 | + expect(replay.recordingOptions.blockSelector).toBe('[data-sentry-block]'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('sets the correct configuration when `blockSelector` is empty and `blockAllMedia` is enabled', async () => { |
| 19 | + ({ replay } = await mockSdk({ replayOptions: { blockSelector: '' } })); |
| 20 | + |
| 21 | + expect(replay.recordingOptions.blockSelector).toMatchInlineSnapshot( |
| 22 | + '"img,image,svg,path,rect,area,video,object,picture,embed,map,audio"', |
| 23 | + ); |
| 24 | + }); |
| 25 | + |
| 26 | + it('preserves `blockSelector` when `blockAllMedia` is enabled', async () => { |
| 27 | + ({ replay } = await mockSdk({ |
| 28 | + replayOptions: { blockSelector: '[data-test-blockSelector]' }, |
| 29 | + })); |
| 30 | + |
| 31 | + expect(replay.recordingOptions.blockSelector).toMatchInlineSnapshot( |
| 32 | + '"[data-test-blockSelector],img,image,svg,path,rect,area,video,object,picture,embed,map,audio"', |
| 33 | + ); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('replaysSampleRate', () => { |
| 38 | + it('works with defining settings in integration', async () => { |
| 39 | + ({ replay } = await mockSdk({ replayOptions: { sessionSampleRate: 0.5 } })); |
| 40 | + |
| 41 | + expect(replay.options.sessionSampleRate).toBe(0.5); |
| 42 | + }); |
| 43 | + |
| 44 | + it('works with defining settings in SDK', async () => { |
| 45 | + try { |
| 46 | + ({ replay } = await mockSdk({ sentryOptions: { replaysSampleRate: 0.5 } })); |
| 47 | + } catch (error) { |
| 48 | + console.error(error); |
| 49 | + } |
| 50 | + expect(replay.options.sessionSampleRate).toBe(0.5); |
| 51 | + }); |
| 52 | + |
| 53 | + it('SDK option takes precedence', async () => { |
| 54 | + ({ replay } = await mockSdk({ |
| 55 | + sentryOptions: { replaysSampleRate: 0.5 }, |
| 56 | + replayOptions: { sessionSampleRate: 0.1 }, |
| 57 | + })); |
| 58 | + |
| 59 | + expect(replay.options.sessionSampleRate).toBe(0.5); |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | +describe('replaysOnErrorSampleRate', () => { |
| 64 | + it('works with defining settings in integration', async () => { |
| 65 | + ({ replay } = await mockSdk({ replayOptions: { errorSampleRate: 0.5 } })); |
| 66 | + |
| 67 | + expect(replay.options.errorSampleRate).toBe(0.5); |
| 68 | + }); |
| 69 | + |
| 70 | + it('works with defining settings in SDK', async () => { |
| 71 | + try { |
| 72 | + ({ replay } = await mockSdk({ sentryOptions: { replaysOnErrorSampleRate: 0.5 } })); |
| 73 | + } catch (error) { |
| 74 | + console.error(error); |
| 75 | + } |
| 76 | + expect(replay.options.errorSampleRate).toBe(0.5); |
| 77 | + }); |
| 78 | + |
| 79 | + it('SDK option takes precedence', async () => { |
| 80 | + ({ replay } = await mockSdk({ |
| 81 | + sentryOptions: { replaysOnErrorSampleRate: 0.5 }, |
| 82 | + replayOptions: { errorSampleRate: 0.1 }, |
| 83 | + })); |
| 84 | + |
| 85 | + expect(replay.options.errorSampleRate).toBe(0.5); |
| 86 | + }); |
| 87 | +}); |
| 88 | + |
| 89 | +describe('maskAllText', () => { |
| 90 | + it('works with default value', async () => { |
| 91 | + ({ replay } = await mockSdk({ replayOptions: {} })); |
| 92 | + |
| 93 | + // Default is true |
| 94 | + expect(replay.recordingOptions.maskTextSelector).toBe('*'); |
| 95 | + }); |
| 96 | + |
| 97 | + it('works with true', async () => { |
| 98 | + ({ replay } = await mockSdk({ replayOptions: { maskAllText: true } })); |
| 99 | + |
| 100 | + expect(replay.recordingOptions.maskTextSelector).toBe('*'); |
| 101 | + }); |
| 102 | + |
| 103 | + it('works with false', async () => { |
| 104 | + ({ replay } = await mockSdk({ replayOptions: { maskAllText: false } })); |
| 105 | + |
| 106 | + expect(replay.recordingOptions.maskTextSelector).toBe(undefined); |
| 107 | + }); |
| 108 | + |
| 109 | + it('overwrites custom maskTextSelector option', async () => { |
| 110 | + ({ replay } = await mockSdk({ replayOptions: { maskAllText: true, maskTextSelector: '[custom]' } })); |
| 111 | + |
| 112 | + expect(replay.recordingOptions.maskTextSelector).toBe('*'); |
| 113 | + }); |
| 114 | +}); |
0 commit comments