@@ -5,7 +5,10 @@ import { TestClient } from '../mocks/client';
55declare var global : any ;
66
77class MockIntegration implements Integration {
8- public name : string = 'MockIntegration' ;
8+ public constructor ( name : string ) {
9+ this . name = name ;
10+ }
11+ public name : string ;
912 public handler : ( ) => void = jest . fn ( ) ;
1013 public install : ( ) => void = ( ) => {
1114 this . handler ( ) ;
@@ -19,32 +22,48 @@ describe('SDK', () => {
1922
2023 describe ( 'initAndBind' , ( ) => {
2124 test ( 'installs default integrations' , ( ) => {
22- const DEFAULT_INTEGRATIONS : Integration [ ] = [ new MockIntegration ( ) , new MockIntegration ( ) ] ;
25+ const DEFAULT_INTEGRATIONS : Integration [ ] = [
26+ new MockIntegration ( 'MockIntegration 1' ) ,
27+ new MockIntegration ( 'MockIntegration 2' ) ,
28+ ] ;
2329 initAndBind ( TestClient , { } , DEFAULT_INTEGRATIONS ) ;
2430 expect ( DEFAULT_INTEGRATIONS [ 0 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
2531 expect ( DEFAULT_INTEGRATIONS [ 1 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
2632 } ) ;
2733
2834 test ( 'installs integrations provided through options' , ( ) => {
29- const integrations : Integration [ ] = [ new MockIntegration ( ) , new MockIntegration ( ) ] ;
35+ const integrations : Integration [ ] = [
36+ new MockIntegration ( 'MockIntegration 1' ) ,
37+ new MockIntegration ( 'MockIntegration 2' ) ,
38+ ] ;
3039 initAndBind ( TestClient , { integrations } , [ ] ) ;
3140 expect ( integrations [ 0 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
3241 expect ( integrations [ 1 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
3342 } ) ;
3443
35- test ( 'installs merged default integrations and one provided through options' , ( ) => {
36- const DEFAULT_INTEGRATIONS : Integration [ ] = [ new MockIntegration ( ) , new MockIntegration ( ) ] ;
37- const integrations : Integration [ ] = [ new MockIntegration ( ) , new MockIntegration ( ) ] ;
44+ test ( 'installs merged default integrations, with overrides provided through options' , ( ) => {
45+ const DEFAULT_INTEGRATIONS : Integration [ ] = [
46+ new MockIntegration ( 'MockIntegration 1' ) ,
47+ new MockIntegration ( 'MockIntegration 2' ) ,
48+ ] ;
49+ const integrations : Integration [ ] = [
50+ new MockIntegration ( 'MockIntegration 1' ) ,
51+ new MockIntegration ( 'MockIntegration 3' ) ,
52+ ] ;
3853 initAndBind ( TestClient , { integrations } , DEFAULT_INTEGRATIONS ) ;
39- expect ( DEFAULT_INTEGRATIONS [ 0 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
54+ // 'MockIntegration 1' should be overridden by the one with the same name provided through options
55+ expect ( DEFAULT_INTEGRATIONS [ 0 ] . handler . mock . calls . length ) . toBe ( 0 ) ;
4056 expect ( DEFAULT_INTEGRATIONS [ 1 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
4157 expect ( integrations [ 0 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
4258 expect ( integrations [ 1 ] . handler . mock . calls . length ) . toBe ( 1 ) ;
4359 } ) ;
4460
4561 test ( 'installs integrations returned from a callback function' , ( ) => {
46- const DEFAULT_INTEGRATIONS : Integration [ ] = [ new MockIntegration ( ) , new MockIntegration ( ) ] ;
47- const newIntegration = new MockIntegration ( ) ;
62+ const DEFAULT_INTEGRATIONS : Integration [ ] = [
63+ new MockIntegration ( 'MockIntegration 1' ) ,
64+ new MockIntegration ( 'MockIntegration 2' ) ,
65+ ] ;
66+ const newIntegration = new MockIntegration ( 'MockIntegration 3' ) ;
4867 initAndBind (
4968 TestClient ,
5069 {
0 commit comments