11import type { Scope } from '@sentry/core' ;
22import { act , render } from '@testing-library/svelte' ;
33
4+ import { vi } from 'vitest' ;
45// linter doesn't like Svelte component imports
56import DummyComponent from './components/Dummy.svelte' ;
67
78let returnUndefinedTransaction = false ;
89
910const testTransaction : { spans : any [ ] ; startChild : jest . Mock ; end : jest . Mock ; isRecording : ( ) => boolean } = {
1011 spans : [ ] ,
11- startChild : jest . fn ( ) ,
12- end : jest . fn ( ) ,
12+ startChild : vi . fn ( ) ,
13+ end : vi . fn ( ) ,
1314 isRecording : ( ) => true ,
1415} ;
15- const testUpdateSpan = { end : jest . fn ( ) } ;
16+ const testUpdateSpan = { end : vi . fn ( ) } ;
1617const testInitSpan : any = {
1718 transaction : testTransaction ,
18- end : jest . fn ( ) ,
19- startChild : jest . fn ( ) ,
19+ end : vi . fn ( ) ,
20+ startChild : vi . fn ( ) ,
2021 isRecording : ( ) => true ,
2122} ;
2223
23- jest . mock ( '@sentry/core' , ( ) => {
24- const original = jest . requireActual ( '@sentry/core' ) ;
24+ vi . mock ( '@sentry/core' , async ( ) => {
25+ const original = await vi . importActual ( '@sentry/core' ) ;
2526 return {
2627 ...original ,
2728 getCurrentScope ( ) : Scope {
@@ -36,7 +37,7 @@ jest.mock('@sentry/core', () => {
3637
3738describe ( 'Sentry.trackComponent()' , ( ) => {
3839 beforeEach ( ( ) => {
39- jest . resetAllMocks ( ) ;
40+ vi . resetAllMocks ( ) ;
4041 testTransaction . spans = [ ] ;
4142
4243 testTransaction . startChild . mockImplementation ( spanCtx => {
@@ -49,7 +50,7 @@ describe('Sentry.trackComponent()', () => {
4950 return testUpdateSpan ;
5051 } ) ;
5152
52- testInitSpan . end = jest . fn ( ) ;
53+ testInitSpan . end = vi . fn ( ) ;
5354 testInitSpan . isRecording = ( ) => true ;
5455 returnUndefinedTransaction = false ;
5556 } ) ;
@@ -58,13 +59,13 @@ describe('Sentry.trackComponent()', () => {
5859 render ( DummyComponent , { props : { options : { } } } ) ;
5960
6061 expect ( testTransaction . startChild ) . toHaveBeenCalledWith ( {
61- description : '<Dummy>' ,
62+ description : '<Dummy$ >' ,
6263 op : 'ui.svelte.init' ,
6364 origin : 'auto.ui.svelte' ,
6465 } ) ;
6566
6667 expect ( testInitSpan . startChild ) . toHaveBeenCalledWith ( {
67- description : '<Dummy>' ,
68+ description : '<Dummy$ >' ,
6869 op : 'ui.svelte.update' ,
6970 origin : 'auto.ui.svelte' ,
7071 } ) ;
@@ -91,7 +92,7 @@ describe('Sentry.trackComponent()', () => {
9192 // once for init (unimportant here), once for starting the update span
9293 expect ( testTransaction . startChild ) . toHaveBeenCalledTimes ( 2 ) ;
9394 expect ( testTransaction . startChild ) . toHaveBeenLastCalledWith ( {
94- description : '<Dummy>' ,
95+ description : '<Dummy$ >' ,
9596 op : 'ui.svelte.update' ,
9697 origin : 'auto.ui.svelte' ,
9798 } ) ;
@@ -102,7 +103,7 @@ describe('Sentry.trackComponent()', () => {
102103 render ( DummyComponent , { props : { options : { trackUpdates : false } } } ) ;
103104
104105 expect ( testTransaction . startChild ) . toHaveBeenCalledWith ( {
105- description : '<Dummy>' ,
106+ description : '<Dummy$ >' ,
106107 op : 'ui.svelte.init' ,
107108 origin : 'auto.ui.svelte' ,
108109 } ) ;
@@ -117,7 +118,7 @@ describe('Sentry.trackComponent()', () => {
117118 render ( DummyComponent , { props : { options : { trackInit : false } } } ) ;
118119
119120 expect ( testTransaction . startChild ) . toHaveBeenCalledWith ( {
120- description : '<Dummy>' ,
121+ description : '<Dummy$ >' ,
121122 op : 'ui.svelte.update' ,
122123 origin : 'auto.ui.svelte' ,
123124 } ) ;
@@ -187,7 +188,7 @@ describe('Sentry.trackComponent()', () => {
187188 // but not the second update
188189 expect ( testTransaction . startChild ) . toHaveBeenCalledTimes ( 1 ) ;
189190 expect ( testTransaction . startChild ) . toHaveBeenLastCalledWith ( {
190- description : '<Dummy>' ,
191+ description : '<Dummy$ >' ,
191192 op : 'ui.svelte.init' ,
192193 origin : 'auto.ui.svelte' ,
193194 } ) ;
0 commit comments