@@ -7,8 +7,8 @@ const { onClientEntry } = require('../gatsby-browser');
7
7
( global as any ) . __SENTRY_DSN__ = 'https://[email protected] /0' ;
8
8
9
9
let sentryInit = jest . fn ( ) ;
10
- jest . mock ( '@sentry/react ' , ( ) => {
11
- const original = jest . requireActual ( '@sentry/react ' ) ;
10
+ jest . mock ( '@sentry/gatsby ' , ( ) => {
11
+ const original = jest . requireActual ( '@sentry/gatsby ' ) ;
12
12
return {
13
13
...original ,
14
14
init : ( ...args : any [ ] ) => {
@@ -38,42 +38,23 @@ describe('onClientEntry', () => {
38
38
( window as any ) . Sentry = undefined ;
39
39
} ) ;
40
40
41
- it ( 'inits Sentry by default' , ( ) => {
42
- onClientEntry ( undefined , { } ) ;
41
+ it . each ( [
42
+ [ { } , [ 'dsn' , 'release' ] ] ,
43
+ [ { key : 'value' } , [ 'dsn' , 'release' , 'key' ] ] ,
44
+ ] ) ( 'inits Sentry by default' , ( pluginParams , expectedKeys ) => {
45
+ onClientEntry ( undefined , pluginParams ) ;
43
46
expect ( sentryInit ) . toHaveBeenCalledTimes ( 1 ) ;
44
- expect ( sentryInit ) . toHaveBeenLastCalledWith ( {
45
- dsn : ( global as any ) . __SENTRY_DSN__ ,
46
- environment : process . env . NODE_ENV ,
47
- integrations : [ ] ,
48
- release : ( global as any ) . __SENTRY_RELEASE__ ,
49
- autoSessionTracking : true ,
50
- _metadata : {
51
- sdk : {
52
- name : 'sentry.javascript.gatsby' ,
53
- packages : [
54
- {
55
- name : 'npm:@sentry/gatsby' ,
56
- version : expect . any ( String ) ,
57
- } ,
58
- ] ,
59
- version : expect . any ( String ) ,
60
- } ,
61
- } ,
62
- } ) ;
47
+ const calledWith = sentryInit . mock . calls [ 0 ] [ 0 ] ;
48
+ for ( const key of expectedKeys ) {
49
+ expect ( calledWith [ key ] ) . toBeDefined ( ) ;
50
+ }
63
51
} ) ;
64
52
65
53
it ( 'sets window.Sentry' , ( ) => {
66
54
onClientEntry ( undefined , { } ) ;
67
55
expect ( ( window as any ) . Sentry ) . not . toBeUndefined ( ) ;
68
56
} ) ;
69
57
70
- it ( 'adds Tracing extension methods' , ( ) => {
71
- onClientEntry ( undefined , { } ) ;
72
-
73
- expect ( tracingAddExtensionMethods ) . toHaveBeenCalledTimes ( 1 ) ;
74
- expect ( tracingAddExtensionMethods ) . toHaveBeenLastCalledWith ( ) ;
75
- } ) ;
76
-
77
58
it ( 'sets a tracesSampleRate if defined as option' , ( ) => {
78
59
onClientEntry ( undefined , { tracesSampleRate : 0.5 } ) ;
79
60
expect ( sentryInit ) . toHaveBeenLastCalledWith (
@@ -93,25 +74,6 @@ describe('onClientEntry', () => {
93
74
) ;
94
75
} ) ;
95
76
96
- it ( 'adds `BrowserTracing` integration if tracesSampleRate is defined' , ( ) => {
97
- onClientEntry ( undefined , { tracesSampleRate : 0.5 } ) ;
98
- expect ( sentryInit ) . toHaveBeenLastCalledWith (
99
- expect . objectContaining ( {
100
- integrations : [ expect . objectContaining ( { name : 'BrowserTracing' } ) ] ,
101
- } ) ,
102
- ) ;
103
- } ) ;
104
-
105
- it ( 'adds `BrowserTracing` integration if tracesSampler is defined' , ( ) => {
106
- const tracesSampler = jest . fn ( ) ;
107
- onClientEntry ( undefined , { tracesSampler } ) ;
108
- expect ( sentryInit ) . toHaveBeenLastCalledWith (
109
- expect . objectContaining ( {
110
- integrations : [ expect . objectContaining ( { name : 'BrowserTracing' } ) ] ,
111
- } ) ,
112
- ) ;
113
- } ) ;
114
-
115
77
it ( 'only defines a single `BrowserTracing` integration' , ( ) => {
116
78
const Tracing = jest . requireActual ( '@sentry/tracing' ) ;
117
79
const integrations = [ new Tracing . Integrations . BrowserTracing ( ) ] ;
0 commit comments