Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/js/integrations/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ

integrations.push(expoContextIntegration());

if (options.spotlight) {
if (options.spotlight && __DEV__) {
const sidecarUrl = typeof options.spotlight === 'string' ? options.spotlight : undefined;
integrations.push(spotlightIntegration({ sidecarUrl }));
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ export interface BaseReactNativeOptions {
*
* More details: https://spotlightjs.com/
*
* IMPORTANT: Only set this option to `true` while developing, not in production!
* NOTE: Spotlight is automatically disabled in production builds (when __DEV__ is false).
* If you need Spotlight in non-development environments, you must manually add
* spotlightIntegration() to your integrations array. However, this is not recommended
* as Spotlight requires a local Sidecar server and is designed for development only.
*/
spotlight?: boolean | string;

Expand Down
83 changes: 83 additions & 0 deletions packages/core/test/integrations/defaultSpotlight.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { Integration } from '@sentry/core';
import { getDefaultIntegrations } from '../../src/js/integrations/default';
import { spotlightIntegration } from '../../src/js/integrations/spotlight';
import type { ReactNativeClientOptions } from '../../src/js/options';
import { notWeb } from '../../src/js/utils/environment';

jest.mock('../../src/js/utils/environment', () => {
const actual = jest.requireActual('../../src/js/utils/environment');
return {
...actual,
notWeb: jest.fn(() => true),
};
});

const spotlightIntegrationName = spotlightIntegration().name;

describe('getDefaultIntegrations - spotlight integration', () => {
let originalDev: boolean | undefined;

beforeEach(() => {
(notWeb as jest.Mock).mockReturnValue(true);
originalDev = (global as typeof globalThis & { __DEV__?: boolean }).__DEV__;
});

afterEach(() => {
(global as typeof globalThis & { __DEV__?: boolean }).__DEV__ = originalDev;
});

const createOptions = (overrides: Partial<ReactNativeClientOptions>): ReactNativeClientOptions => {
return {
dsn: 'https://example.com/1',
enableNative: true,
...overrides,
} as ReactNativeClientOptions;
};

const getIntegrationNames = (options: ReactNativeClientOptions): string[] => {
const integrations = getDefaultIntegrations(options);
return integrations.map((integration: Integration) => integration.name);
};

it('does not add spotlight integration when spotlight option is not set', () => {
(global as typeof globalThis & { __DEV__?: boolean }).__DEV__ = true;
const names = getIntegrationNames(createOptions({}));

expect(names).not.toContain(spotlightIntegrationName);
});

it('adds spotlight integration when spotlight is true and __DEV__ is true', () => {
(global as typeof globalThis & { __DEV__?: boolean }).__DEV__ = true;
const names = getIntegrationNames(createOptions({ spotlight: true }));

expect(names).toContain(spotlightIntegrationName);
});

it('adds spotlight integration when spotlight is a URL string and __DEV__ is true', () => {
(global as typeof globalThis & { __DEV__?: boolean }).__DEV__ = true;
const names = getIntegrationNames(createOptions({ spotlight: 'http://custom-url:8969/stream' }));

expect(names).toContain(spotlightIntegrationName);
});

it('does not add spotlight integration when spotlight is true but __DEV__ is false', () => {
(global as typeof globalThis & { __DEV__?: boolean }).__DEV__ = false;
const names = getIntegrationNames(createOptions({ spotlight: true }));

expect(names).not.toContain(spotlightIntegrationName);
});

it('does not add spotlight integration when spotlight is a URL but __DEV__ is false', () => {
(global as typeof globalThis & { __DEV__?: boolean }).__DEV__ = false;
const names = getIntegrationNames(createOptions({ spotlight: 'http://custom-url:8969/stream' }));

expect(names).not.toContain(spotlightIntegrationName);
});

it('does not add spotlight integration when spotlight is false regardless of __DEV__', () => {
(global as typeof globalThis & { __DEV__?: boolean }).__DEV__ = true;
const names = getIntegrationNames(createOptions({ spotlight: false }));

expect(names).not.toContain(spotlightIntegrationName);
});
});
Loading