@@ -646,6 +646,63 @@ describe('addIntegration', () => {
646646 expect ( warnings ) . toHaveBeenCalledTimes ( 1 ) ;
647647 expect ( warnings ) . toHaveBeenCalledWith ( 'Cannot add integration "test" because no SDK Client is available.' ) ;
648648 } ) ;
649+
650+ it ( 'triggers all hooks' , ( ) => {
651+ const setup = jest . fn ( ) ;
652+ const setupOnce = jest . fn ( ) ;
653+ const setupAfterAll = jest . fn ( ) ;
654+
655+ class CustomIntegration implements Integration {
656+ name = 'test' ;
657+ setupOnce = setupOnce ;
658+ setup = setup ;
659+ afterAllSetup = setupAfterAll ;
660+ }
661+
662+ const client = getTestClient ( ) ;
663+ const hub = new Hub ( client ) ;
664+ // eslint-disable-next-line deprecation/deprecation
665+ makeMain ( hub ) ;
666+
667+ const integration = new CustomIntegration ( ) ;
668+ addIntegration ( integration ) ;
669+
670+ expect ( setupOnce ) . toHaveBeenCalledTimes ( 1 ) ;
671+ expect ( setup ) . toHaveBeenCalledTimes ( 1 ) ;
672+ expect ( setupAfterAll ) . toHaveBeenCalledTimes ( 1 ) ;
673+ } ) ;
674+
675+ it ( 'does not trigger hooks if already installed' , ( ) => {
676+ const logs = jest . spyOn ( logger , 'log' ) ;
677+
678+ class CustomIntegration implements Integration {
679+ name = 'test' ;
680+ setupOnce = jest . fn ( ) ;
681+ setup = jest . fn ( ) ;
682+ afterAllSetup = jest . fn ( ) ;
683+ }
684+
685+ const client = getTestClient ( ) ;
686+ const hub = new Hub ( client ) ;
687+ // eslint-disable-next-line deprecation/deprecation
688+ makeMain ( hub ) ;
689+
690+ const integration1 = new CustomIntegration ( ) ;
691+ const integration2 = new CustomIntegration ( ) ;
692+ addIntegration ( integration1 ) ;
693+
694+ expect ( integration1 . setupOnce ) . toHaveBeenCalledTimes ( 1 ) ;
695+ expect ( integration1 . setup ) . toHaveBeenCalledTimes ( 1 ) ;
696+ expect ( integration1 . afterAllSetup ) . toHaveBeenCalledTimes ( 1 ) ;
697+
698+ addIntegration ( integration2 ) ;
699+
700+ expect ( integration2 . setupOnce ) . toHaveBeenCalledTimes ( 0 ) ;
701+ expect ( integration2 . setup ) . toHaveBeenCalledTimes ( 0 ) ;
702+ expect ( integration2 . afterAllSetup ) . toHaveBeenCalledTimes ( 0 ) ;
703+
704+ expect ( logs ) . toHaveBeenCalledWith ( 'Integration skipped because it was already installed: test' ) ;
705+ } ) ;
649706} ) ;
650707
651708describe ( 'convertIntegrationFnToClass' , ( ) => {
0 commit comments