1- /* eslint-disable @typescript-eslint/no-var-requires */
2- /* eslint-disable @typescript-eslint/no-explicit-any */
3-
1+ import type { Client } from '@sentry/types' ;
42import { onClientEntry } from '../gatsby-browser' ;
5- import { browserTracingIntegration } from '../src/index' ;
3+ import { browserTracingIntegration , getCurrentScope , getIsolationScope , setCurrentClient } from '../src/index' ;
64
75( global as any ) . __SENTRY_RELEASE__ = '683f3a6ab819d47d23abfca9a914c81f0524d35b' ;
86( global as any ) . __SENTRY_DSN__ = 'https://[email protected] /0' ; @@ -50,24 +48,21 @@ describe('onClientEntry', () => {
5048 } ) ;
5149
5250 describe ( 'inits Sentry once' , ( ) => {
51+ beforeEach ( ( ) => {
52+ getCurrentScope ( ) . clear ( ) ;
53+ getIsolationScope ( ) . clear ( ) ;
54+ getCurrentScope ( ) . setClient ( undefined ) ;
55+ } ) ;
56+
5357 afterEach ( ( ) => {
54- delete ( window as any ) . __SENTRY__ ;
5558 ( global . console . warn as jest . Mock ) . mockClear ( ) ;
5659 ( global . console . error as jest . Mock ) . mockClear ( ) ;
5760 } ) ;
5861
59- function setMockedSentryInWindow ( ) {
60- ( window as any ) . __SENTRY__ = {
61- hub : {
62- getClient : ( ) => ( {
63- // Empty object mocking the client
64- } ) ,
65- } ,
66- } ;
67- }
68-
6962 it ( 'initialized in injected config, without pluginParams' , ( ) => {
70- setMockedSentryInWindow ( ) ;
63+ const client = { } as Client ;
64+ setCurrentClient ( client ) ;
65+
7166 onClientEntry ( undefined , { plugins : [ ] } ) ;
7267 // eslint-disable-next-line no-console
7368 expect ( console . warn ) . not . toHaveBeenCalled ( ) ;
@@ -77,7 +72,9 @@ describe('onClientEntry', () => {
7772 } ) ;
7873
7974 it ( 'initialized in injected config, with pluginParams' , ( ) => {
80- setMockedSentryInWindow ( ) ;
75+ const client = { } as Client ;
76+ setCurrentClient ( client ) ;
77+
8178 onClientEntry ( undefined , { plugins : [ ] , dsn : 'dsn' , release : 'release' } ) ;
8279 // eslint-disable-next-line no-console
8380 expect ( ( console . warn as jest . Mock ) . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
0 commit comments