1
1
import { debug } from '@sentry/core' ;
2
- import { afterEach , describe , expect , it , vi } from 'vitest' ;
2
+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
3
+ import { resetGlobals } from '../helpers/mockSdkInit' ;
3
4
4
5
describe ( 'preload' , ( ) => {
6
+ beforeEach ( ( ) => {
7
+ // Mock this to prevent conflicts with other tests
8
+ vi . mock ( '../../src/integrations/tracing' , async ( importOriginal : ( ) => Promise < Record < string , unknown > > ) => {
9
+ const actual = await importOriginal ( ) ;
10
+ return {
11
+ ...actual ,
12
+ getOpenTelemetryInstrumentationToPreload : ( ) => [
13
+ Object . assign ( vi . fn ( ) , { id : 'Http.sentry' } ) ,
14
+ Object . assign ( vi . fn ( ) , { id : 'Http' } ) ,
15
+ Object . assign ( vi . fn ( ) , { id : 'Express' } ) ,
16
+ Object . assign ( vi . fn ( ) , { id : 'Graphql' } ) ,
17
+ ] ,
18
+ } ;
19
+ } ) ;
20
+ } ) ;
21
+
5
22
afterEach ( ( ) => {
6
- vi . resetAllMocks ( ) ;
7
23
debug . disable ( ) ;
24
+ resetGlobals ( ) ;
8
25
9
26
delete process . env . SENTRY_DEBUG ;
10
27
delete process . env . SENTRY_PRELOAD_INTEGRATIONS ;
@@ -29,6 +46,7 @@ describe('preload', () => {
29
46
30
47
await import ( '../../src/preload' ) ;
31
48
49
+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Http.sentry instrumentation' ) ;
32
50
expect ( logSpy ) . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Http instrumentation' ) ;
33
51
expect ( logSpy ) . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Express instrumentation' ) ;
34
52
expect ( logSpy ) . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Graphql instrumentation' ) ;
@@ -44,6 +62,7 @@ describe('preload', () => {
44
62
45
63
await import ( '../../src/preload' ) ;
46
64
65
+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Http.sentry instrumentation' ) ;
47
66
expect ( logSpy ) . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Http instrumentation' ) ;
48
67
expect ( logSpy ) . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Express instrumentation' ) ;
49
68
expect ( logSpy ) . not . toHaveBeenCalledWith ( 'Sentry Logger [log]:' , '[Sentry] Preloaded Graphql instrumentation' ) ;
0 commit comments