Skip to content

Commit

Permalink
expose ios options
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-zimerman committed Mar 22, 2024
1 parent bb0eb4f commit fd6670d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/js/__tests__/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getGlobalObject } from '@sentry/utils';

import type { CordovaOptions } from '../options';
import * as Sdk from '../sdk';
import { getPlatform } from '../utils';

const optionsTest: {
current?: CordovaOptions;
Expand All @@ -19,6 +20,15 @@ jest.mock('@sentry/core', () => {
};
});

jest.mock('../utils', () => {
const util = jest.requireActual('../utils');

return {
...util,
getPlatform: jest.fn().mockReturnValue('android'),
};
});

describe('Tests SDK', () => {
describe('init', () => {
it('Uses SENTRY_RELEASE environment variable if present.', () => {
Expand All @@ -44,5 +54,42 @@ describe('Tests SDK', () => {

expect(optionsTest.current?.release).toBe('user-release');
});

describe('ios Options', () => {

it('Should include iOS parameters when running on iOS', async () => {
(getPlatform as jest.Mock).mockReturnValue('ios');

const expectedOptions: CordovaOptions = {
environment: 'abc',
// iOS parameters
enableAppHangTracking: true,
appHangTimeoutInterval: 123
};

Sdk.init(expectedOptions);

expect(optionsTest.current?.appHangTimeoutInterval).toEqual(expectedOptions.appHangTimeoutInterval);
expect(optionsTest.current?.enableAppHangTracking).toEqual(expectedOptions.enableAppHangTracking);
});

it('Should not include iOS parameters when running on android', async () => {
(getPlatform as jest.Mock).mockReturnValue('android');

const expectedOption = {
environment: 'abc'
}
const unexpectedOptions = {
appHangTimeoutInterval: 123,
enableAppHangTracking: true
};

Sdk.init({ ...unexpectedOptions, ...expectedOption });

expect(optionsTest.current).not.toContain(unexpectedOptions);
expect(optionsTest.current?.environment).toEqual(expectedOption.environment);
});
})

});
});
22 changes: 22 additions & 0 deletions src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,26 @@ export interface CordovaOptions
* @deprecated The method will be removed on a major update, instead, use enableWatchdogTerminationTracking for the same result.
* */
enableOutOfMemoryTracking?: boolean;

/**
* When enabled, the SDK tracks when the application stops responding for a specific amount of
* time defined by the `appHangTimeoutInterval` option.
*
* iOS only
*
* @default true
*/
enableAppHangTracking?: boolean;

/**
* The minimum amount of time an app should be unresponsive to be classified as an App Hanging.
* The actual amount may be a little longer.
* Avoid using values lower than 100ms, which may cause a lot of app hangs events being transmitted.
* Value should be in seconds.
*
* iOS only
*
* @default 2
*/
appHangTimeoutInterval?: number;
}
7 changes: 7 additions & 0 deletions src/js/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Cordova, EventOrigin, SdkInfo } from './integrations';
import type { CordovaOptions } from './options';
import { CordovaScope } from './scope';
import { makeCordovaTransport } from './transports/cordova';
import { CordovaPlatformType } from './types';
import { getPlatform } from './utils';
import { NATIVE } from './wrapper';
const DEFAULT_OPTIONS: CordovaOptions = {
enableNative: true,
Expand Down Expand Up @@ -47,6 +49,11 @@ export function init(options: Partial<CordovaOptions>): void {
if (finalOptions.enableNative === undefined) {
finalOptions.enableNative = true;
}

if (getPlatform() !== CordovaPlatformType.Ios) {
delete finalOptions.appHangTimeoutInterval;
delete finalOptions.enableAppHangTracking;
}
}

// Initialize a new hub using our scope with native sync
Expand Down

0 comments on commit fd6670d

Please sign in to comment.