@@ -2,6 +2,7 @@ import { Hub, Scope, Session } from '@sentry/hub';
22import { Event , Severity , Span } from '@sentry/types' ;
33import { logger , SentryError , SyncPromise } from '@sentry/utils' ;
44
5+ import * as integrationModule from '../../src/integration' ;
56import { TestBackend } from '../mocks/backend' ;
67import { TestClient } from '../mocks/client' ;
78import { TestIntegration } from '../mocks/integration' ;
@@ -872,6 +873,26 @@ describe('BaseClient', () => {
872873 expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toBe ( 0 ) ;
873874 expect ( client . getIntegration ( TestIntegration ) ) . toBeFalsy ( ) ;
874875 } ) ;
876+
877+ test ( 'skips installation if integrations are already installed' , ( ) => {
878+ expect . assertions ( 4 ) ;
879+ const client = new TestClient ( {
880+ dsn : PUBLIC_DSN ,
881+ integrations : [ new TestIntegration ( ) ] ,
882+ } ) ;
883+ // note: not the `Client` method `setupIntegrations`, but the free-standing function which that method calls
884+ const setupIntegrationsHelper = jest . spyOn ( integrationModule , 'setupIntegrations' ) ;
885+
886+ // it should install the first time, because integrations aren't yet installed...
887+ client . setupIntegrations ( ) ;
888+ expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toBe ( 1 ) ;
889+ expect ( client . getIntegration ( TestIntegration ) ) . toBeTruthy ( ) ;
890+ expect ( setupIntegrationsHelper ) . toHaveBeenCalledTimes ( 1 ) ;
891+
892+ // ...but it shouldn't try to install a second time
893+ client . setupIntegrations ( ) ;
894+ expect ( setupIntegrationsHelper ) . toHaveBeenCalledTimes ( 1 ) ;
895+ } ) ;
875896 } ) ;
876897
877898 describe ( 'flush/close' , ( ) => {
0 commit comments