Skip to content

Commit 7ac2fb1

Browse files
committed
fix(replay): Fix handleException
1 parent 5dfcfa0 commit 7ac2fb1

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

packages/replay/src/integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class Replay implements Integration {
5050
maskAllText = true,
5151
maskAllInputs = true,
5252
blockAllMedia = true,
53+
_experiments = {},
5354
blockClass = 'sentry-block',
5455
ignoreClass = 'sentry-ignore',
5556
maskTextClass = 'sentry-mask',
@@ -75,6 +76,7 @@ export class Replay implements Integration {
7576
useCompression,
7677
maskAllText,
7778
blockAllMedia,
79+
_experiments,
7880
};
7981

8082
if (typeof sessionSampleRate === 'number') {

packages/replay/test/mocks/resetSdkMock.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export async function resetSdkMock({ replayOptions, sentryOptions }: MockSdkPara
1010
mockRecord: RecordMock;
1111
mockTransportSend: MockTransportSend;
1212
replay: ReplayContainer;
13-
spyCaptureException: jest.SpyInstance;
1413
}> {
1514
let domHandler: DomHandler;
1615

@@ -29,13 +28,6 @@ export async function resetSdkMock({ replayOptions, sentryOptions }: MockSdkPara
2928
const { mockRrweb } = await import('./mockRrweb');
3029
const { record: mockRecord } = mockRrweb();
3130

32-
// Because of `resetModules`, we need to import and add a spy for
33-
// `@sentry/core` here before `mockSdk` is called
34-
// XXX: This is probably going to make writing future tests difficult and/or
35-
// bloat this area of code
36-
const SentryCore = await import('@sentry/core');
37-
const spyCaptureException = jest.spyOn(SentryCore, 'captureException');
38-
3931
const { replay } = await mockSdk({
4032
replayOptions,
4133
sentryOptions,
@@ -54,6 +46,5 @@ export async function resetSdkMock({ replayOptions, sentryOptions }: MockSdkPara
5446
mockRecord,
5547
mockTransportSend,
5648
replay,
57-
spyCaptureException,
5849
};
5950
}

packages/replay/test/unit/index-errorSampleRate.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
jest.unmock('@sentry/browser');
2-
3-
import { captureException } from '@sentry/browser';
1+
import { captureException } from '@sentry/core';
42

53
import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
64
import { ReplayContainer } from './../../src/replay';

packages/replay/test/unit/index-integrationSettings.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,24 @@ describe('integration settings', () => {
189189
expect(replay.recordingOptions.maskTextSelector).toBe('*');
190190
});
191191
});
192+
193+
describe('_experiments', () => {
194+
it('works with defining _experiments in integration', async () => {
195+
const { replay } = await mockSdk({
196+
replayOptions: { _experiments: { captureExceptions: true } },
197+
sentryOptions: {},
198+
});
199+
200+
expect(replay.options._experiments).toEqual({ captureExceptions: true });
201+
});
202+
203+
it('works without defining _experiments in integration', async () => {
204+
const { replay } = await mockSdk({
205+
replayOptions: {},
206+
sentryOptions: {},
207+
});
208+
209+
expect(replay.options._experiments).toEqual({});
210+
});
211+
});
192212
});

packages/replay/test/unit/index.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
jest.mock('./../../src/util/isInternal', () => ({
2-
isInternal: jest.fn(() => true),
3-
}));
4-
51
import { EventType } from 'rrweb';
62

73
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
@@ -96,7 +92,6 @@ describe('Replay', () => {
9692
let mockRecord: RecordMock;
9793
let mockTransportSend: MockTransportSend;
9894
let domHandler: DomHandler;
99-
let spyCaptureException: jest.MockedFunction<any>;
10095
const prevLocation = WINDOW.location;
10196

10297
type MockSendReplayRequest = jest.MockedFunction<typeof replay.sendReplayRequest>;
@@ -108,7 +103,7 @@ describe('Replay', () => {
108103
});
109104

110105
beforeEach(async () => {
111-
({ mockRecord, mockTransportSend, domHandler, replay, spyCaptureException } = await resetSdkMock({
106+
({ mockRecord, mockTransportSend, domHandler, replay } = await resetSdkMock({
112107
replayOptions: {
113108
stickySession: false,
114109
},
@@ -633,6 +628,9 @@ describe('Replay', () => {
633628
// Suppress console.errors
634629
const mockConsole = jest.spyOn(console, 'error').mockImplementation(jest.fn());
635630

631+
// Check errors
632+
const spyHandleException = jest.spyOn(replay, 'handleException');
633+
636634
expect(replay.session?.segmentId).toBe(0);
637635

638636
// fail the first and second requests and pass the third one
@@ -664,11 +662,10 @@ describe('Replay', () => {
664662
expect(replay.sendReplayRequest).toHaveBeenCalledTimes(4);
665663
expect(replay.sendReplay).toHaveBeenCalledTimes(4);
666664

667-
expect(spyCaptureException).toHaveBeenCalledTimes(5);
668665
// Retries = 3 (total tries = 4 including initial attempt)
669666
// + last exception is max retries exceeded
670-
expect(spyCaptureException).toHaveBeenCalledTimes(5);
671-
expect(spyCaptureException).toHaveBeenLastCalledWith(new Error('Unable to send Replay - max retries exceeded'));
667+
expect(spyHandleException).toHaveBeenCalledTimes(5);
668+
expect(spyHandleException).toHaveBeenLastCalledWith(new Error('Unable to send Replay - max retries exceeded'));
672669

673670
// No activity has occurred, session's last activity should remain the same
674671
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);

0 commit comments

Comments
 (0)