Skip to content

Commit

Permalink
Adjust test and add comment to browser impl
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Mar 27, 2024
1 parent 926984e commit 606c389
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
43 changes: 10 additions & 33 deletions packages/angular/test/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as SentryBrowser from '@sentry/browser';
import { vi } from 'vitest';
import { getDefaultIntegrations, init } from '../src/index';
import { getDefaultIntegrations, init } from '../src/sdk';

describe('init', () => {
it('sets the Angular version (if available) in the global scope', () => {
Expand All @@ -14,39 +14,16 @@ describe('init', () => {
expect(setContextSpy).toHaveBeenCalledWith('angular', { version: 14 });
});

describe('filtering out the `BrowserApiErrors` integration', () => {
const browserInitSpy = vi.spyOn(SentryBrowser, 'init');
it('does not include the BrowserApiErrors integration', () => {
const browserDefaultIntegrationsWithoutBrowserApiErrors = SentryBrowser.getDefaultIntegrations()
.filter(i => i.name !== 'BrowserApiErrors')
.map(i => i.name)
.sort();

beforeEach(() => {
browserInitSpy.mockClear();
});
const angularDefaultIntegrations = getDefaultIntegrations()
.map(i => i.name)
.sort();

it('filters if `defaultIntegrations` is not set', () => {
init({});

expect(browserInitSpy).toHaveBeenCalledTimes(1);

const options = browserInitSpy.mock.calls[0][0] || {};
expect(options.defaultIntegrations).not.toContainEqual(expect.objectContaining({ name: 'BrowserApiErrors' }));
});

it("doesn't filter if `defaultIntegrations` is set to `false`", () => {
init({ defaultIntegrations: false });

expect(browserInitSpy).toHaveBeenCalledTimes(1);

const options = browserInitSpy.mock.calls[0][0] || {};
expect(options.defaultIntegrations).toEqual(false);
});

it("doesn't filter if `defaultIntegrations` is overwritten", () => {
const defaultIntegrations = getDefaultIntegrations({});
init({ defaultIntegrations });

expect(browserInitSpy).toHaveBeenCalledTimes(1);

const options = browserInitSpy.mock.calls[0][0] || {};
expect(options.defaultIntegrations).toEqual(defaultIntegrations);
});
expect(angularDefaultIntegrations).toEqual(browserDefaultIntegrationsWithoutBrowserApiErrors);
});
});
4 changes: 4 additions & 0 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import { makeFetchTransport } from './transports/fetch';

/** Get the default integrations for the browser SDK. */
export function getDefaultIntegrations(_options: Options): Integration[] {
/**
* Note: Please make sure this stays in sync with Angular SDK, which re-exports
* `getDefaultIntegrations` but with an adjusted set of integrations.
*/
return [
inboundFiltersIntegration(),
functionToStringIntegration(),
Expand Down

0 comments on commit 606c389

Please sign in to comment.