Skip to content

Commit d2cff1a

Browse files
authored
fix: Install integrations when SDK is enabled (getsentry#2193)
1 parent 4f898a0 commit d2cff1a

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

packages/core/src/baseclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
7272
this._dsn = new Dsn(options.dsn);
7373
}
7474

75-
if (!options.enabled) {
75+
if (this._isEnabled()) {
7676
this._integrations = setupIntegrations(this._options);
7777
}
7878
}

packages/core/test/lib/base.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,26 @@ describe('BaseClient', () => {
426426
expect(Object.keys(client.getIntegrations()).length).toBe(1);
427427
expect(client.getIntegration(TestIntegration)).toBeTruthy();
428428
});
429+
430+
test('skips installation if DSN is not provided', () => {
431+
expect.assertions(2);
432+
const client = new TestClient({
433+
integrations: [new TestIntegration()],
434+
});
435+
expect(Object.keys(client.getIntegrations()).length).toBe(0);
436+
expect(client.getIntegration(TestIntegration)).toBeFalsy();
437+
});
438+
439+
test('skips installation if enabled is set to false', () => {
440+
expect.assertions(2);
441+
const client = new TestClient({
442+
dsn: PUBLIC_DSN,
443+
enabled: false,
444+
integrations: [new TestIntegration()],
445+
});
446+
expect(Object.keys(client.getIntegrations()).length).toBe(0);
447+
expect(client.getIntegration(TestIntegration)).toBeFalsy();
448+
});
429449
});
430450

431451
describe('flush/close', () => {

packages/core/test/lib/sdk.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { TestClient } from '../mocks/client';
66

77
declare var global: any;
88

9+
const PUBLIC_DSN = 'https://username@domain/path';
10+
911
jest.mock('@sentry/hub', () => ({
1012
getCurrentHub(): {
1113
bindClient(): boolean;
@@ -42,7 +44,7 @@ describe('SDK', () => {
4244
new MockIntegration('MockIntegration 1'),
4345
new MockIntegration('MockIntegration 2'),
4446
];
45-
initAndBind(TestClient, { defaultIntegrations: DEFAULT_INTEGRATIONS });
47+
initAndBind(TestClient, { dsn: PUBLIC_DSN, defaultIntegrations: DEFAULT_INTEGRATIONS });
4648
expect((DEFAULT_INTEGRATIONS[0].setupOnce as jest.Mock).mock.calls.length).toBe(1);
4749
expect((DEFAULT_INTEGRATIONS[1].setupOnce as jest.Mock).mock.calls.length).toBe(1);
4850
});
@@ -52,7 +54,7 @@ describe('SDK', () => {
5254
new MockIntegration('MockIntegration 1'),
5355
new MockIntegration('MockIntegration 2'),
5456
];
55-
initAndBind(TestClient, { defaultIntegrations: false });
57+
initAndBind(TestClient, { dsn: PUBLIC_DSN, defaultIntegrations: false });
5658
expect((DEFAULT_INTEGRATIONS[0].setupOnce as jest.Mock).mock.calls.length).toBe(0);
5759
expect((DEFAULT_INTEGRATIONS[1].setupOnce as jest.Mock).mock.calls.length).toBe(0);
5860
});
@@ -62,7 +64,7 @@ describe('SDK', () => {
6264
new MockIntegration('MockIntegration 1'),
6365
new MockIntegration('MockIntegration 2'),
6466
];
65-
initAndBind(TestClient, { integrations });
67+
initAndBind(TestClient, { dsn: PUBLIC_DSN, integrations });
6668
expect((integrations[0].setupOnce as jest.Mock).mock.calls.length).toBe(1);
6769
expect((integrations[1].setupOnce as jest.Mock).mock.calls.length).toBe(1);
6870
});
@@ -76,7 +78,7 @@ describe('SDK', () => {
7678
new MockIntegration('MockIntegration 1'),
7779
new MockIntegration('MockIntegration 3'),
7880
];
79-
initAndBind(TestClient, { defaultIntegrations: DEFAULT_INTEGRATIONS, integrations });
81+
initAndBind(TestClient, { dsn: PUBLIC_DSN, defaultIntegrations: DEFAULT_INTEGRATIONS, integrations });
8082
// 'MockIntegration 1' should be overridden by the one with the same name provided through options
8183
expect((DEFAULT_INTEGRATIONS[0].setupOnce as jest.Mock).mock.calls.length).toBe(0);
8284
expect((DEFAULT_INTEGRATIONS[1].setupOnce as jest.Mock).mock.calls.length).toBe(1);
@@ -91,6 +93,7 @@ describe('SDK', () => {
9193
];
9294
const newIntegration = new MockIntegration('MockIntegration 3');
9395
initAndBind(TestClient, {
96+
dsn: PUBLIC_DSN,
9497
// Take only the first one and add a new one to it
9598
defaultIntegrations: DEFAULT_INTEGRATIONS,
9699
integrations: (integrations: Integration[]) => integrations.slice(0, 1).concat(newIntegration),

0 commit comments

Comments
 (0)