@@ -671,7 +671,7 @@ describe('BaseClient', () => {
671671 test ( 'adds installed integrations to sdk info' , ( ) => {
672672 const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , integrations : [ new TestIntegration ( ) ] } ) ;
673673 const client = new TestClient ( options ) ;
674- client . setupIntegrations ( ) ;
674+ client . init ( ) ;
675675
676676 client . captureEvent ( { message : 'message' } ) ;
677677
@@ -685,7 +685,7 @@ describe('BaseClient', () => {
685685
686686 const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , integrations : [ new TestIntegration ( ) ] } ) ;
687687 const client = new TestClient ( options ) ;
688- client . setupIntegrations ( ) ;
688+ client . init ( ) ;
689689 client . addIntegration ( new AdHocIntegration ( ) ) ;
690690
691691 client . captureException ( new Error ( 'test exception' ) ) ;
@@ -706,7 +706,7 @@ describe('BaseClient', () => {
706706 integrations : [ new TestIntegration ( ) , null , undefined ] ,
707707 } ) ;
708708 const client = new TestClient ( options ) ;
709- client . setupIntegrations ( ) ;
709+ client . init ( ) ;
710710
711711 client . captureEvent ( { message : 'message' } ) ;
712712
@@ -1482,24 +1482,48 @@ describe('BaseClient', () => {
14821482
14831483 const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , integrations : [ new TestIntegration ( ) ] } ) ;
14841484 const client = new TestClient ( options ) ;
1485+ // eslint-disable-next-line deprecation/deprecation
14851486 client . setupIntegrations ( ) ;
14861487
14871488 expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 1 ) ;
14881489 expect ( client . getIntegration ( TestIntegration ) ) . toBeTruthy ( ) ;
14891490 } ) ;
14901491
1491- test ( 'skips installation if DSN is not provided' , ( ) => {
1492+ test ( 'sets up each integration on `init` call' , ( ) => {
1493+ expect . assertions ( 2 ) ;
1494+
1495+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , integrations : [ new TestIntegration ( ) ] } ) ;
1496+ const client = new TestClient ( options ) ;
1497+ client . init ( ) ;
1498+
1499+ expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 1 ) ;
1500+ expect ( client . getIntegration ( TestIntegration ) ) . toBeTruthy ( ) ;
1501+ } ) ;
1502+
1503+ test ( 'skips installation for `setupIntegrations()` if DSN is not provided' , ( ) => {
14921504 expect . assertions ( 2 ) ;
14931505
14941506 const options = getDefaultTestClientOptions ( { integrations : [ new TestIntegration ( ) ] } ) ;
14951507 const client = new TestClient ( options ) ;
1508+ // eslint-disable-next-line deprecation/deprecation
14961509 client . setupIntegrations ( ) ;
14971510
14981511 expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 0 ) ;
14991512 expect ( client . getIntegration ( TestIntegration ) ) . toBeFalsy ( ) ;
15001513 } ) ;
15011514
1502- test ( 'skips installation if `enabled` is set to `false`' , ( ) => {
1515+ test ( 'skips installation for `init()` if DSN is not provided' , ( ) => {
1516+ expect . assertions ( 2 ) ;
1517+
1518+ const options = getDefaultTestClientOptions ( { integrations : [ new TestIntegration ( ) ] } ) ;
1519+ const client = new TestClient ( options ) ;
1520+ client . init ( ) ;
1521+
1522+ expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 0 ) ;
1523+ expect ( client . getIntegration ( TestIntegration ) ) . toBeFalsy ( ) ;
1524+ } ) ;
1525+
1526+ test ( 'skips installation for `setupIntegrations()` if `enabled` is set to `false`' , ( ) => {
15031527 expect . assertions ( 2 ) ;
15041528
15051529 const options = getDefaultTestClientOptions ( {
@@ -1508,12 +1532,28 @@ describe('BaseClient', () => {
15081532 integrations : [ new TestIntegration ( ) ] ,
15091533 } ) ;
15101534 const client = new TestClient ( options ) ;
1535+ // eslint-disable-next-line deprecation/deprecation
15111536 client . setupIntegrations ( ) ;
15121537
15131538 expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 0 ) ;
15141539 expect ( client . getIntegration ( TestIntegration ) ) . toBeFalsy ( ) ;
15151540 } ) ;
15161541
1542+ test ( 'skips installation for `init()` if `enabled` is set to `false`' , ( ) => {
1543+ expect . assertions ( 2 ) ;
1544+
1545+ const options = getDefaultTestClientOptions ( {
1546+ dsn : PUBLIC_DSN ,
1547+ enabled : false ,
1548+ integrations : [ new TestIntegration ( ) ] ,
1549+ } ) ;
1550+ const client = new TestClient ( options ) ;
1551+ client . init ( ) ;
1552+
1553+ expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 0 ) ;
1554+ expect ( client . getIntegration ( TestIntegration ) ) . toBeFalsy ( ) ;
1555+ } ) ;
1556+
15171557 test ( 'skips installation if integrations are already installed' , ( ) => {
15181558 expect . assertions ( 4 ) ;
15191559
@@ -1523,17 +1563,41 @@ describe('BaseClient', () => {
15231563 const setupIntegrationsHelper = jest . spyOn ( integrationModule , 'setupIntegrations' ) ;
15241564
15251565 // it should install the first time, because integrations aren't yet installed...
1566+ // eslint-disable-next-line deprecation/deprecation
15261567 client . setupIntegrations ( ) ;
15271568
15281569 expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 1 ) ;
15291570 expect ( client . getIntegration ( TestIntegration ) ) . toBeTruthy ( ) ;
15301571 expect ( setupIntegrationsHelper ) . toHaveBeenCalledTimes ( 1 ) ;
15311572
15321573 // ...but it shouldn't try to install a second time
1574+ // eslint-disable-next-line deprecation/deprecation
15331575 client . setupIntegrations ( ) ;
15341576
15351577 expect ( setupIntegrationsHelper ) . toHaveBeenCalledTimes ( 1 ) ;
15361578 } ) ;
1579+
1580+ test ( 'does not add integrations twice when calling `init` multiple times' , ( ) => {
1581+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , integrations : [ new TestIntegration ( ) ] } ) ;
1582+ const client = new TestClient ( options ) ;
1583+ // note: not the `Client` method `setupIntegrations`, but the free-standing function which that method calls
1584+ const setupIntegrationsHelper = jest . spyOn ( integrationModule , 'setupIntegrations' ) ;
1585+
1586+ // it should install the first time, because integrations aren't yet installed...
1587+ client . init ( ) ;
1588+
1589+ expect ( Object . keys ( ( client as any ) . _integrations ) . length ) . toEqual ( 1 ) ;
1590+ expect ( client . getIntegration ( TestIntegration ) ) . toBeTruthy ( ) ;
1591+ expect ( setupIntegrationsHelper ) . toHaveBeenCalledTimes ( 1 ) ;
1592+
1593+ client . init ( ) ;
1594+
1595+ // is called again...
1596+ expect ( setupIntegrationsHelper ) . toHaveBeenCalledTimes ( 2 ) ;
1597+
1598+ // but integrations are only added once anyhow!
1599+ expect ( client [ '_integrations' ] ) . toEqual ( { TestIntegration : expect . any ( TestIntegration ) } ) ;
1600+ } ) ;
15371601 } ) ;
15381602
15391603 describe ( 'flush/close' , ( ) => {
0 commit comments