From 1171bb8038448a50c4a0f849ecfe4ebd7fb285a8 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Tue, 17 Dec 2024 12:40:51 +0100 Subject: [PATCH] add js tests --- packages/core/test/sdk.test.ts | 88 +++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/packages/core/test/sdk.test.ts b/packages/core/test/sdk.test.ts index 94cbed0aa..a5542103c 100644 --- a/packages/core/test/sdk.test.ts +++ b/packages/core/test/sdk.test.ts @@ -14,7 +14,7 @@ import { init, withScope } from '../src/js/sdk'; import type { ReactNativeTracingIntegration } from '../src/js/tracing'; import { REACT_NATIVE_TRACING_INTEGRATION_NAME, reactNativeTracingIntegration } from '../src/js/tracing'; import { makeNativeTransport } from '../src/js/transports/native'; -import { getDefaultEnvironment, isExpoGo, isWeb, notWeb } from '../src/js/utils/environment'; +import { getDefaultEnvironment, isExpoGo, notWeb } from '../src/js/utils/environment'; import { NATIVE } from './mockWrapper'; import { firstArg, secondArg } from './testutils'; @@ -864,6 +864,14 @@ describe('Tests the SDK functionality', () => { expectIntegration('MobileReplay'); }); + it('adds mobile replay integration when replaysOnErrorSampleRate is set', () => { + init({ + replaysOnErrorSampleRate: 1.0, + }); + + expectIntegration('MobileReplay'); + }); + it('adds mobile replay integration when _experiments.replaysSessionSampleRate is set', () => { init({ _experiments: { @@ -874,6 +882,14 @@ describe('Tests the SDK functionality', () => { expectIntegration('MobileReplay'); }); + it('adds mobile replay integration when replaysSessionSampleRate is set', () => { + init({ + replaysSessionSampleRate: 1.0, + }); + + expectIntegration('MobileReplay'); + }); + it('does not add mobile replay integration when no replay sample rates are set', () => { init({ _experiments: {}, @@ -882,8 +898,8 @@ describe('Tests the SDK functionality', () => { expectNotIntegration('MobileReplay'); }); - it('does not add any replay integration when on web even with on error sample rate', () => { - (isWeb as jest.Mock).mockImplementation(() => true); + it('does not add any replay integration when on web even with on experimental error sample rate', () => { + (notWeb as jest.Mock).mockImplementation(() => false); init({ _experiments: { replaysOnErrorSampleRate: 1.0, @@ -894,8 +910,8 @@ describe('Tests the SDK functionality', () => { expectNotIntegration('MobileReplay'); }); - it('does not add any replay integration when on web even with session sample rate', () => { - (isWeb as jest.Mock).mockImplementation(() => true); + it('does not add any replay integration when on web even with experimental session sample rate', () => { + (notWeb as jest.Mock).mockImplementation(() => false); init({ _experiments: { replaysSessionSampleRate: 1.0, @@ -906,16 +922,74 @@ describe('Tests the SDK functionality', () => { expectNotIntegration('MobileReplay'); }); + it('does not add any replay integration when on web even with on error sample rate', () => { + (notWeb as jest.Mock).mockImplementation(() => false); + init({ + replaysOnErrorSampleRate: 1.0, + }); + + expectNotIntegration('Replay'); + expectNotIntegration('MobileReplay'); + }); + + it('does not add any replay integration when on web even with session sample rate', () => { + (notWeb as jest.Mock).mockImplementation(() => false); + init({ + replaysSessionSampleRate: 1.0, + }); + + expectNotIntegration('Replay'); + expectNotIntegration('MobileReplay'); + }); + it('does not add any replay integration when on web', () => { - (isWeb as jest.Mock).mockImplementation(() => true); + (notWeb as jest.Mock).mockImplementation(() => false); init({}); expectNotIntegration('Replay'); expectNotIntegration('MobileReplay'); }); + it('ignores experimental replay options when ga options are set', () => { + (notWeb as jest.Mock).mockImplementation(() => false); + init({ + replaysOnErrorSampleRate: 0.1, + replaysSessionSampleRate: 0.2, + _experiments: { + replaysOnErrorSampleRate: 0.3, + replaysSessionSampleRate: 0.4, + }, + }); + + const actualOptions = usedOptions(); + expect(actualOptions).toEqual( + expect.objectContaining({ + replaysOnErrorSampleRate: 0.1, + replaysSessionSampleRate: 0.2, + }), + ); + }); + it('converts experimental replay options to standard web options when on web', () => { - (isWeb as jest.Mock).mockImplementation(() => true); + (notWeb as jest.Mock).mockImplementation(() => false); + init({ + _experiments: { + replaysOnErrorSampleRate: 0.5, + replaysSessionSampleRate: 0.1, + }, + }); + + const actualOptions = usedOptions(); + expect(actualOptions).toEqual( + expect.objectContaining({ + replaysOnErrorSampleRate: 0.5, + replaysSessionSampleRate: 0.1, + }), + ); + }); + + it('converts experimental replay options to standard web options when on mobile', () => { + (notWeb as jest.Mock).mockImplementation(() => true); init({ _experiments: { replaysOnErrorSampleRate: 0.5,