1
- import type { BrowserClient } from '@sentry/browser' ;
2
1
import {
3
2
browserTracingIntegration ,
4
3
getActiveSpan ,
5
- getClient ,
6
4
getCurrentScope ,
7
5
getGlobalScope ,
8
6
getIsolationScope ,
@@ -12,7 +10,7 @@ import * as SentryBrowser from '@sentry/browser';
12
10
import { afterEach , describe , expect , it , vi } from 'vitest' ;
13
11
import { init } from '../../src/client/sdk' ;
14
12
15
- const browserInit = vi . spyOn ( SentryBrowser , 'init ' ) ;
13
+ const browserInit = vi . spyOn ( SentryBrowser , 'initWithDefaultIntegrations ' ) ;
16
14
17
15
describe ( 'Sentry client SDK' , ( ) => {
18
16
describe ( 'init' , ( ) => {
@@ -44,6 +42,7 @@ describe('Sentry client SDK', () => {
44
42
} ,
45
43
} ,
46
44
} ) ,
45
+ expect . any ( Function ) ,
47
46
) ;
48
47
} ) ;
49
48
@@ -53,45 +52,39 @@ describe('Sentry client SDK', () => {
53
52
[ 'tracesSampler' , { tracesSampler : ( ) => 1.0 } ] ,
54
53
[ 'no tracing option set' , { } ] ,
55
54
] ) ( 'adds browserTracingIntegration if tracing is enabled via %s' , ( _ , tracingOptions ) => {
56
- init ( {
55
+ const client = init ( {
57
56
dsn :
'https://[email protected] /1337' ,
58
57
...tracingOptions ,
59
58
} ) ;
60
59
61
- const integrationsToInit = browserInit . mock . calls [ 0 ] ! [ 0 ] ?. defaultIntegrations ;
62
- const browserTracing = getClient < BrowserClient > ( ) ?. getIntegrationByName ( 'BrowserTracing' ) ;
63
-
64
- expect ( integrationsToInit ) . toContainEqual ( expect . objectContaining ( { name : 'BrowserTracing' } ) ) ;
60
+ const browserTracing = client ?. getIntegrationByName ( 'BrowserTracing' ) ;
65
61
expect ( browserTracing ) . toBeDefined ( ) ;
66
62
} ) ;
67
63
68
64
it ( "doesn't add browserTracingIntegration if `__SENTRY_TRACING__` is set to false" , ( ) => {
69
65
( globalThis as any ) . __SENTRY_TRACING__ = false ;
70
66
71
- init ( {
67
+ const client = init ( {
72
68
dsn :
'https://[email protected] /1337' ,
73
69
tracesSampleRate : 1 ,
74
70
} ) ;
75
71
76
- const integrationsToInit = browserInit . mock . calls [ 0 ] ! [ 0 ] ?. defaultIntegrations || [ ] ;
77
- const browserTracing = getClient < BrowserClient > ( ) ?. getIntegrationByName ( 'BrowserTracing' ) ;
78
-
79
- expect ( integrationsToInit ) . not . toContainEqual ( expect . objectContaining ( { name : 'BrowserTracing' } ) ) ;
72
+ const browserTracing = client ?. getIntegrationByName ( 'BrowserTracing' ) ;
80
73
expect ( browserTracing ) . toBeUndefined ( ) ;
81
74
82
75
delete ( globalThis as any ) . __SENTRY_TRACING__ ;
83
76
} ) ;
84
77
85
78
it ( 'Overrides the automatically default browserTracingIntegration instance with a a user-provided browserTracingIntegration instance' , ( ) => {
86
- init ( {
79
+ const client = init ( {
87
80
dsn :
'https://[email protected] /1337' ,
88
81
integrations : [
89
82
browserTracingIntegration ( { finalTimeout : 10 , instrumentNavigation : false , instrumentPageLoad : false } ) ,
90
83
] ,
91
84
tracesSampleRate : 1 ,
92
85
} ) ;
93
86
94
- const browserTracing = getClient < BrowserClient > ( ) ?. getIntegrationByName ( 'BrowserTracing' ) ;
87
+ const browserTracing = client ?. getIntegrationByName ( 'BrowserTracing' ) ;
95
88
expect ( browserTracing ) . toBeDefined ( ) ;
96
89
97
90
// no active span means the settings were respected
0 commit comments