From 488177d306bd2ef9acbb208800847be1d595e892 Mon Sep 17 00:00:00 2001 From: Najib Boutaib Date: Thu, 23 May 2024 14:50:42 +0200 Subject: [PATCH] [RUM-3887] Add unit and E2E tests --- packages/rum/src/boot/recorderApi.spec.ts | 7 +++++ .../scenario/recorder/recorder.scenario.ts | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/packages/rum/src/boot/recorderApi.spec.ts b/packages/rum/src/boot/recorderApi.spec.ts index 3cf6cc1342..e8836c2959 100644 --- a/packages/rum/src/boot/recorderApi.spec.ts +++ b/packages/rum/src/boot/recorderApi.spec.ts @@ -135,6 +135,13 @@ describe('makeRecorderApi', () => { expect(startRecordingSpy).not.toHaveBeenCalled() }) + it('should start recording if session is tracked without session replay when forced', () => { + setupBuilder.withSessionManager(createRumSessionManagerMock().setTrackedWithoutSessionReplay()).build() + rumInit() + recorderApi.start({ force: true }) + expect(startRecordingSpy).toHaveBeenCalledTimes(1) + }) + it('uses the previously created worker if available', () => { setupBuilder.build() rumInit({ worker: mockWorker }) diff --git a/test/e2e/scenario/recorder/recorder.scenario.ts b/test/e2e/scenario/recorder/recorder.scenario.ts index 7bff50a91d..b017eea5c9 100644 --- a/test/e2e/scenario/recorder/recorder.scenario.ts +++ b/test/e2e/scenario/recorder/recorder.scenario.ts @@ -806,6 +806,34 @@ describe('recorder', () => { }) }) + describe('recording of sampled out sessions', () => { + createTest('should not start recording when session is sampled out') + .withRum({ sessionReplaySampleRate: 0 }) + .withSetup(bundleSetup) + .run(async ({ intakeRegistry }) => { + await browser.execute(() => { + window.DD_RUM!.startSessionReplayRecording() + }) + + await flushEvents() + + expect(intakeRegistry.replaySegments.length).toBe(0) + }) + + createTest('should start recording if forced when session is sampled out') + .withRum({ sessionReplaySampleRate: 0 }) + .withSetup(bundleSetup) + .run(async ({ intakeRegistry }) => { + await browser.execute(() => { + window.DD_RUM!.startSessionReplayRecording({ force: true }) + }) + + await flushEvents() + + expect(intakeRegistry.replaySegments.length).toBe(1) + }) + }) + createTest('restarting recording should send a new full snapshot') .withRum() .withSetup(bundleSetup)