@@ -3,6 +3,7 @@ import { Integrations } from '@sentry/tracing';
3
3
import { Integration , Package } from '@sentry/types' ;
4
4
5
5
import { defaultOptions , init as gatsbyInit } from '../src/sdk' ;
6
+ import { UserIntegrations } from '../src/utils/integrations' ;
6
7
import { GatsbyOptions } from '../src/utils/types' ;
7
8
8
9
const reactInit = reactInitRaw as jest . Mock ;
@@ -65,28 +66,75 @@ describe('Integrations from options', () => {
65
66
afterEach ( ( ) => reactInit . mockClear ( ) ) ;
66
67
67
68
test . each ( [
68
- [ 'tracing disabled, no integrations' , { } , [ ] ] ,
69
- [ 'tracing enabled, no integrations' , { tracesSampleRate : 1 } , [ 'BrowserTracing' ] ] ,
69
+ [ 'tracing disabled, no integrations' , [ ] , { } , [ ] ] ,
70
+ [ 'tracing enabled, no integrations' , [ ] , { tracesSampleRate : 1 } , [ 'BrowserTracing' ] ] ,
70
71
[
71
- 'tracing disabled, with Integrations.BrowserTracing' ,
72
+ 'tracing disabled, with Integrations.BrowserTracing as an array' ,
73
+ [ ] ,
72
74
{ integrations : [ new Integrations . BrowserTracing ( ) ] } ,
73
75
[ 'BrowserTracing' ] ,
74
76
] ,
75
77
[
76
- 'tracing enabled, with Integrations.BrowserTracing' ,
78
+ 'tracing disabled, with Integrations.BrowserTracing as a function' ,
79
+ [ ] ,
80
+ {
81
+ integrations : ( ) => [ new Integrations . BrowserTracing ( ) ] ,
82
+ } ,
83
+ [ 'BrowserTracing' ] ,
84
+ ] ,
85
+ [
86
+ 'tracing enabled, with Integrations.BrowserTracing as an array' ,
87
+ [ ] ,
77
88
{ tracesSampleRate : 1 , integrations : [ new Integrations . BrowserTracing ( ) ] } ,
78
89
[ 'BrowserTracing' ] ,
79
90
] ,
80
91
[
81
- 'tracing enabled, with another integration' ,
92
+ 'tracing enabled, with Integrations.BrowserTracing as a function' ,
93
+ [ ] ,
94
+ { tracesSampleRate : 1 , integrations : ( ) => [ new Integrations . BrowserTracing ( ) ] } ,
95
+ [ 'BrowserTracing' ] ,
96
+ ] ,
97
+ [
98
+ 'tracing enabled, with another integration as an array' ,
99
+ [ ] ,
82
100
{ tracesSampleRate : 1 , integrations : [ new Integrations . Express ( ) ] } ,
83
101
[ 'Express' , 'BrowserTracing' ] ,
84
102
] ,
85
- [ 'tracing disabled, with another integration' , { integrations : [ new Integrations . Express ( ) ] } , [ 'Express' ] ] ,
86
- ] ) ( '%s' , ( _testName , options : GatsbyOptions , expectedIntNames : string [ ] ) => {
103
+ [
104
+ 'tracing enabled, with another integration as a function' ,
105
+ [ ] ,
106
+ { tracesSampleRate : 1 , integrations : ( ) => [ new Integrations . Express ( ) ] } ,
107
+ [ 'Express' , 'BrowserTracing' ] ,
108
+ ] ,
109
+ [
110
+ 'tracing disabled, with another integration as an array' ,
111
+ [ ] ,
112
+ { integrations : [ new Integrations . Express ( ) ] } ,
113
+ [ 'Express' ] ,
114
+ ] ,
115
+ [
116
+ 'tracing disabled, with another integration as a function' ,
117
+ [ ] ,
118
+ { integrations : ( ) => [ new Integrations . Express ( ) ] } ,
119
+ [ 'Express' ] ,
120
+ ] ,
121
+ [
122
+ 'merges integrations with user integrations as a function' ,
123
+ [ new Integrations . Mongo ( ) ] ,
124
+ {
125
+ tracesSampleRate : 1 ,
126
+ integrations : ( defaultIntegrations : Integration [ ] ) : Integration [ ] => [
127
+ ...defaultIntegrations ,
128
+ new Integrations . Express ( ) ,
129
+ ] ,
130
+ } ,
131
+ [ 'Mongo' , 'Express' , 'BrowserTracing' ] ,
132
+ ] ,
133
+ ] ) ( '%s' , ( _testName , defaultIntegrations : Integration [ ] , options : GatsbyOptions , expectedIntNames : string [ ] ) => {
87
134
gatsbyInit ( options ) ;
88
- const integrations : Integration [ ] = reactInit . mock . calls [ 0 ] [ 0 ] . integrations ;
89
- expect ( integrations ) . toHaveLength ( expectedIntNames . length ) ;
90
- integrations . map ( ( integration , idx ) => expect ( integration . name ) . toStrictEqual ( expectedIntNames [ idx ] ) ) ;
135
+ const integrations : UserIntegrations = reactInit . mock . calls [ 0 ] [ 0 ] . integrations ;
136
+ const arrIntegrations = Array . isArray ( integrations ) ? integrations : integrations ( defaultIntegrations ) ;
137
+ expect ( arrIntegrations ) . toHaveLength ( expectedIntNames . length ) ;
138
+ arrIntegrations . map ( ( integration , idx ) => expect ( integration . name ) . toStrictEqual ( expectedIntNames [ idx ] ) ) ;
91
139
} ) ;
92
140
} ) ;
0 commit comments