@@ -7,8 +7,8 @@ const { onClientEntry } = require('../gatsby-browser');
77( global as any ) . __SENTRY_DSN__ = 'https://[email protected] /0' ; 88
99let 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 ' ) ;
1212 return {
1313 ...original ,
1414 init : ( ...args : any [ ] ) => {
@@ -38,42 +38,23 @@ describe('onClientEntry', () => {
3838 ( window as any ) . Sentry = undefined ;
3939 } ) ;
4040
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 ) ;
4346 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+ }
6351 } ) ;
6452
6553 it ( 'sets window.Sentry' , ( ) => {
6654 onClientEntry ( undefined , { } ) ;
6755 expect ( ( window as any ) . Sentry ) . not . toBeUndefined ( ) ;
6856 } ) ;
6957
70- it ( 'adds Tracing extension methods' , ( ) => {
71- onClientEntry ( undefined , { } ) ;
72-
73- expect ( tracingAddExtensionMethods ) . toHaveBeenCalledTimes ( 1 ) ;
74- expect ( tracingAddExtensionMethods ) . toHaveBeenLastCalledWith ( ) ;
75- } ) ;
76-
7758 it ( 'sets a tracesSampleRate if defined as option' , ( ) => {
7859 onClientEntry ( undefined , { tracesSampleRate : 0.5 } ) ;
7960 expect ( sentryInit ) . toHaveBeenLastCalledWith (
@@ -93,25 +74,6 @@ describe('onClientEntry', () => {
9374 ) ;
9475 } ) ;
9576
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-
11577 it ( 'only defines a single `BrowserTracing` integration' , ( ) => {
11678 const Tracing = jest . requireActual ( '@sentry/tracing' ) ;
11779 const integrations = [ new Tracing . Integrations . BrowserTracing ( ) ] ;
0 commit comments