Skip to content

Commit

Permalink
add js tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Dec 17, 2024
1 parent 87b8ee1 commit 1171bb8
Showing 1 changed file with 81 additions and 7 deletions.
88 changes: 81 additions & 7 deletions packages/core/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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: {
Expand All @@ -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: {},
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 1171bb8

Please sign in to comment.