1
+ import { afterEach , describe , expect , it , vi } from 'vitest' ;
2
+
1
3
import * as SentryBrowser from '@sentry/browser' ;
2
4
import * as SentryCore from '@sentry/core' ;
3
5
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN , SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core' ;
@@ -6,21 +8,21 @@ import type { Span, SpanAttributes } from '@sentry/types';
6
8
import type { Route } from '../src/router' ;
7
9
import { instrumentVueRouter } from '../src/router' ;
8
10
9
- const captureExceptionSpy = jest . spyOn ( SentryBrowser , 'captureException' ) ;
10
- jest . mock ( '@sentry/core' , ( ) => {
11
- const actual = jest . requireActual ( '@sentry/core' ) ;
11
+ const captureExceptionSpy = vi . spyOn ( SentryBrowser , 'captureException' ) ;
12
+ vi . mock ( '@sentry/core' , async ( ) => {
13
+ const actual = await vi . importActual ( '@sentry/core' ) ;
12
14
return {
13
15
...actual ,
14
- getActiveSpan : jest . fn ( ) . mockReturnValue ( { } ) ,
16
+ getActiveSpan : vi . fn ( ) . mockReturnValue ( { } ) ,
15
17
} ;
16
18
} ) ;
17
19
18
20
const mockVueRouter = {
19
- onError : jest . fn < void , [ ( error : Error ) => void ] > ( ) ,
20
- beforeEach : jest . fn < void , [ ( from : Route , to : Route , next ?: ( ) => void ) => void ] > ( ) ,
21
+ onError : vi . fn < [ ( error : Error ) => void ] > ( ) ,
22
+ beforeEach : vi . fn < [ ( from : Route , to : Route , next ?: ( ) => void ) => void ] > ( ) ,
21
23
} ;
22
24
23
- const mockNext = jest . fn ( ) ;
25
+ const mockNext = vi . fn ( ) ;
24
26
25
27
const testRoutes : Record < string , Route > = {
26
28
initialPageloadRoute : { matched : [ ] , params : { } , path : '' , query : { } } ,
@@ -68,11 +70,11 @@ const testRoutes: Record<string, Route> = {
68
70
69
71
describe ( 'instrumentVueRouter()' , ( ) => {
70
72
afterEach ( ( ) => {
71
- jest . clearAllMocks ( ) ;
73
+ vi . clearAllMocks ( ) ;
72
74
} ) ;
73
75
74
76
it ( 'should return instrumentation that instruments VueRouter.onError' , ( ) => {
75
- const mockStartSpan = jest . fn ( ) ;
77
+ const mockStartSpan = vi . fn ( ) ;
76
78
instrumentVueRouter (
77
79
mockVueRouter ,
78
80
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -99,7 +101,7 @@ describe('instrumentVueRouter()', () => {
99
101
] ) (
100
102
'should return instrumentation that instruments VueRouter.beforeEach(%s, %s) for navigations' ,
101
103
( fromKey , toKey , transactionName , transactionSource ) => {
102
- const mockStartSpan = jest . fn ( ) ;
104
+ const mockStartSpan = vi . fn ( ) ;
103
105
instrumentVueRouter (
104
106
mockVueRouter ,
105
107
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -138,15 +140,15 @@ describe('instrumentVueRouter()', () => {
138
140
'should return instrumentation that instruments VueRouter.beforeEach(%s, %s) for pageloads' ,
139
141
( fromKey , toKey , transactionName , transactionSource ) => {
140
142
const mockRootSpan = {
141
- getSpanJSON : jest . fn ( ) . mockReturnValue ( { op : 'pageload' } ) ,
142
- updateName : jest . fn ( ) ,
143
- setAttribute : jest . fn ( ) ,
144
- setAttributes : jest . fn ( ) ,
143
+ getSpanJSON : vi . fn ( ) . mockReturnValue ( { op : 'pageload' } ) ,
144
+ updateName : vi . fn ( ) ,
145
+ setAttribute : vi . fn ( ) ,
146
+ setAttributes : vi . fn ( ) ,
145
147
} ;
146
148
147
- jest . spyOn ( SentryCore , 'getRootSpan' ) . mockImplementation ( ( ) => mockRootSpan as unknown as Span ) ;
149
+ vi . spyOn ( SentryCore , 'getRootSpan' ) . mockImplementation ( ( ) => mockRootSpan as unknown as Span ) ;
148
150
149
- const mockStartSpan = jest . fn ( ) . mockImplementation ( _ => {
151
+ const mockStartSpan = vi . fn ( ) . mockImplementation ( _ => {
150
152
return mockRootSpan ;
151
153
} ) ;
152
154
instrumentVueRouter (
@@ -178,7 +180,7 @@ describe('instrumentVueRouter()', () => {
178
180
) ;
179
181
180
182
it ( 'allows to configure routeLabel=path' , ( ) => {
181
- const mockStartSpan = jest . fn ( ) ;
183
+ const mockStartSpan = vi . fn ( ) ;
182
184
instrumentVueRouter (
183
185
mockVueRouter ,
184
186
{ routeLabel : 'path' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -205,7 +207,7 @@ describe('instrumentVueRouter()', () => {
205
207
} ) ;
206
208
207
209
it ( 'allows to configure routeLabel=name' , ( ) => {
208
- const mockStartSpan = jest . fn ( ) ;
210
+ const mockStartSpan = vi . fn ( ) ;
209
211
instrumentVueRouter (
210
212
mockVueRouter ,
211
213
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -233,9 +235,9 @@ describe('instrumentVueRouter()', () => {
233
235
234
236
it ( "doesn't overwrite a pageload transaction name it was set to custom before the router resolved the route" , ( ) => {
235
237
const mockRootSpan = {
236
- updateName : jest . fn ( ) ,
237
- setAttribute : jest . fn ( ) ,
238
- setAttributes : jest . fn ( ) ,
238
+ updateName : vi . fn ( ) ,
239
+ setAttribute : vi . fn ( ) ,
240
+ setAttributes : vi . fn ( ) ,
239
241
name : '' ,
240
242
getSpanJSON : ( ) => ( {
241
243
op : 'pageload' ,
@@ -244,10 +246,10 @@ describe('instrumentVueRouter()', () => {
244
246
} ,
245
247
} ) ,
246
248
} ;
247
- const mockStartSpan = jest . fn ( ) . mockImplementation ( _ => {
249
+ const mockStartSpan = vi . fn ( ) . mockImplementation ( _ => {
248
250
return mockRootSpan ;
249
251
} ) ;
250
- jest . spyOn ( SentryCore , 'getRootSpan' ) . mockImplementation ( ( ) => mockRootSpan as unknown as Span ) ;
252
+ vi . spyOn ( SentryCore , 'getRootSpan' ) . mockImplementation ( ( ) => mockRootSpan as unknown as Span ) ;
251
253
252
254
instrumentVueRouter (
253
255
mockVueRouter ,
@@ -287,14 +289,14 @@ describe('instrumentVueRouter()', () => {
287
289
} ) ;
288
290
289
291
it ( "updates the scope's `transactionName` when a route is resolved" , ( ) => {
290
- const mockStartSpan = jest . fn ( ) . mockImplementation ( _ => {
292
+ const mockStartSpan = vi . fn ( ) . mockImplementation ( _ => {
291
293
return { } ;
292
294
} ) ;
293
295
294
- const scopeSetTransactionNameSpy = jest . fn ( ) ;
296
+ const scopeSetTransactionNameSpy = vi . fn ( ) ;
295
297
296
298
// @ts -expect-error - only creating a partial scope but that's fine
297
- jest . spyOn ( SentryCore , 'getCurrentScope' ) . mockImplementation ( ( ) => ( {
299
+ vi . spyOn ( SentryCore , 'getCurrentScope' ) . mockImplementation ( ( ) => ( {
298
300
setTransactionName : scopeSetTransactionNameSpy ,
299
301
} ) ) ;
300
302
@@ -315,17 +317,17 @@ describe('instrumentVueRouter()', () => {
315
317
expect ( scopeSetTransactionNameSpy ) . toHaveBeenCalledWith ( '/books/:bookId/chapter/:chapterId' ) ;
316
318
} ) ;
317
319
318
- test . each ( [
320
+ it . each ( [
319
321
[ false , 0 ] ,
320
322
[ true , 1 ] ,
321
323
] ) (
322
324
'should return instrumentation that considers the instrumentPageLoad = %p' ,
323
325
( instrumentPageLoad , expectedCallsAmount ) => {
324
326
const mockRootSpan = {
325
- updateName : jest . fn ( ) ,
326
- setData : jest . fn ( ) ,
327
- setAttribute : jest . fn ( ) ,
328
- setAttributes : jest . fn ( ) ,
327
+ updateName : vi . fn ( ) ,
328
+ setData : vi . fn ( ) ,
329
+ setAttribute : vi . fn ( ) ,
330
+ setAttributes : vi . fn ( ) ,
329
331
name : '' ,
330
332
getSpanJSON : ( ) => ( {
331
333
op : 'pageload' ,
@@ -334,9 +336,9 @@ describe('instrumentVueRouter()', () => {
334
336
} ,
335
337
} ) ,
336
338
} ;
337
- jest . spyOn ( SentryCore , 'getRootSpan' ) . mockImplementation ( ( ) => mockRootSpan as unknown as Span ) ;
339
+ vi . spyOn ( SentryCore , 'getRootSpan' ) . mockImplementation ( ( ) => mockRootSpan as unknown as Span ) ;
338
340
339
- const mockStartSpan = jest . fn ( ) ;
341
+ const mockStartSpan = vi . fn ( ) ;
340
342
instrumentVueRouter (
341
343
mockVueRouter ,
342
344
{ routeLabel : 'name' , instrumentPageLoad, instrumentNavigation : true } ,
@@ -354,13 +356,13 @@ describe('instrumentVueRouter()', () => {
354
356
} ,
355
357
) ;
356
358
357
- test . each ( [
359
+ it . each ( [
358
360
[ false , 0 ] ,
359
361
[ true , 1 ] ,
360
362
] ) (
361
363
'should return instrumentation that considers the instrumentNavigation = %p' ,
362
364
( instrumentNavigation , expectedCallsAmount ) => {
363
- const mockStartSpan = jest . fn ( ) ;
365
+ const mockStartSpan = vi . fn ( ) ;
364
366
instrumentVueRouter (
365
367
mockVueRouter ,
366
368
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation } ,
@@ -378,7 +380,7 @@ describe('instrumentVueRouter()', () => {
378
380
) ;
379
381
380
382
it ( "doesn't throw when `next` is not available in the beforeEach callback (Vue Router 4)" , ( ) => {
381
- const mockStartSpan = jest . fn ( ) ;
383
+ const mockStartSpan = vi . fn ( ) ;
382
384
instrumentVueRouter (
383
385
mockVueRouter ,
384
386
{ routeLabel : 'path' , instrumentPageLoad : true , instrumentNavigation : true } ,
0 commit comments