From aa8be082f2f7f9cce32fee8c99f681d7de771f8b Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Wed, 10 Jan 2024 19:05:17 +0000 Subject: [PATCH 1/2] fix: simplify test setup --- .../replay/sessionrecording.test.ts | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/__tests__/extensions/replay/sessionrecording.test.ts b/src/__tests__/extensions/replay/sessionrecording.test.ts index bee68567e..4c08b488c 100644 --- a/src/__tests__/extensions/replay/sessionrecording.test.ts +++ b/src/__tests__/extensions/replay/sessionrecording.test.ts @@ -54,9 +54,15 @@ describe('SessionRecording', () => { let onFeatureFlagsCallback: ((flags: string[]) => void) | null beforeEach(() => { - assignableWindow.rrwebRecord = jest.fn() - _addCustomEvent.mockClear() - assignableWindow.rrwebRecord = _addCustomEvent + ;(loadScript as any).mockImplementation((_path: any, callback: any) => callback()) + + assignableWindow.rrwebRecord = jest.fn(({ emit }) => { + _emit = emit + return () => {} + }) + assignableWindow.rrwebRecord.takeFullSnapshot = jest.fn() + assignableWindow.rrwebRecord.addCustomEvent = _addCustomEvent + assignableWindow.rrwebConsoleRecord = { getRecordConsolePlugin: jest.fn(), } @@ -219,11 +225,6 @@ describe('SessionRecording', () => { describe('afterDecideResponse()', () => { beforeEach(() => { jest.spyOn(sessionRecording, 'startRecordingIfEnabled') - ;(loadScript as any).mockImplementation((_path: any, callback: any) => callback()) - assignableWindow.rrwebRecord = jest.fn(({ emit }) => { - _emit = emit - return () => {} - }) }) it('buffers snapshots until decide is received and drops them if disabled', () => { @@ -302,17 +303,6 @@ describe('SessionRecording', () => { }) describe('recording', () => { - beforeEach(() => { - const mockFullSnapshot = jest.fn() - assignableWindow.rrwebRecord = jest.fn(({ emit }) => { - _emit = emit - return () => {} - }) - assignableWindow.rrwebRecord.takeFullSnapshot = mockFullSnapshot - assignableWindow.rrwebRecord.addCustomEvent = _addCustomEvent - ;(loadScript as any).mockImplementation((_path: any, callback: any) => callback()) - }) - describe('sampling', () => { it('does not emit to capture if the sample rate is 0', () => { sessionRecording.startRecordingIfEnabled() @@ -1082,13 +1072,6 @@ describe('SessionRecording', () => { }) describe('buffering minimum duration', () => { - beforeEach(() => { - assignableWindow.rrwebRecord = jest.fn(({ emit }) => { - _emit = emit - return () => {} - }) - }) - it('can report no duration when no data', () => { sessionRecording.startRecordingIfEnabled() expect(sessionRecording['status']).toBe('buffering') From 982796921080b8444ce7d20b3fd3c2c789cfb68b Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Wed, 10 Jan 2024 19:07:13 +0000 Subject: [PATCH 2/2] and a little more --- src/__tests__/extensions/replay/sessionrecording.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/__tests__/extensions/replay/sessionrecording.test.ts b/src/__tests__/extensions/replay/sessionrecording.test.ts index 4c08b488c..1409004fc 100644 --- a/src/__tests__/extensions/replay/sessionrecording.test.ts +++ b/src/__tests__/extensions/replay/sessionrecording.test.ts @@ -54,8 +54,6 @@ describe('SessionRecording', () => { let onFeatureFlagsCallback: ((flags: string[]) => void) | null beforeEach(() => { - ;(loadScript as any).mockImplementation((_path: any, callback: any) => callback()) - assignableWindow.rrwebRecord = jest.fn(({ emit }) => { _emit = emit return () => {}