1+ import { addTracingExtensions } from '@sentry/core' ;
12import { Scope } from '@sentry/node' ;
23import type { ServerLoad } from '@sveltejs/kit' ;
34import { error } from '@sveltejs/kit' ;
@@ -26,7 +27,7 @@ vi.mock('@sentry/core', async () => {
2627 const original = ( await vi . importActual ( '@sentry/core' ) ) as any ;
2728 return {
2829 ...original ,
29- trace : ( ...args ) => {
30+ trace : ( ...args : unknown [ ] ) => {
3031 mockTrace ( ...args ) ;
3132 return original . trace ( ...args ) ;
3233 } ,
@@ -48,10 +49,11 @@ function getById(_id?: string) {
4849}
4950
5051const MOCK_LOAD_ARGS : any = {
51- params : { id : '1 ' } ,
52+ params : { id : '123 ' } ,
5253 route : {
5354 id : '/users/[id]' ,
5455 } ,
56+ url : new URL ( 'http://localhost:3000/users/123' ) ,
5557 request : {
5658 headers : {
5759 get : ( key : string ) => {
@@ -73,6 +75,10 @@ const MOCK_LOAD_ARGS: any = {
7375 } ,
7476} ;
7577
78+ beforeAll ( ( ) => {
79+ addTracingExtensions ( ) ;
80+ } ) ;
81+
7682describe ( 'wrapLoadWithSentry' , ( ) => {
7783 beforeEach ( ( ) => {
7884 mockCaptureException . mockClear ( ) ;
@@ -81,7 +87,7 @@ describe('wrapLoadWithSentry', () => {
8187 mockScope = new Scope ( ) ;
8288 } ) ;
8389
84- it . only ( 'calls captureException' , async ( ) => {
90+ it ( 'calls captureException' , async ( ) => {
8591 async function load ( { params } : Parameters < ServerLoad > [ 0 ] ) : Promise < ReturnType < ServerLoad > > {
8692 return {
8793 post : getById ( params . id ) ,
@@ -106,18 +112,33 @@ describe('wrapLoadWithSentry', () => {
106112 }
107113
108114 const wrappedLoad = wrapLoadWithSentry ( load ) ;
109- await wrappedLoad ( {
110- params : { id : '1' } ,
111- route : {
112- id : '' ,
113- } ,
114- headers : { 'sentry-trace' : '1234567890abcdef1234567890abcdef-1234567890abcdef-1' } ,
115- } as any ) ;
115+ await wrappedLoad ( MOCK_LOAD_ARGS ) ;
116116
117117 expect ( mockTrace ) . toHaveBeenCalledTimes ( 1 ) ;
118- expect ( mockTrace ) . toHaveBeenCalledWith ( {
119- op : 'function.sveltekit.load' ,
120- } ) ;
118+ expect ( mockTrace ) . toHaveBeenCalledWith (
119+ {
120+ op : 'function.sveltekit.load' ,
121+ name : '/users/[id]' ,
122+ parentSampled : true ,
123+ parentSpanId : '1234567890abcdef' ,
124+ status : 'ok' ,
125+ traceId : '1234567890abcdef1234567890abcdef' ,
126+ metadata : {
127+ dynamicSamplingContext : {
128+ environment : 'production' ,
129+ public_key : 'dogsarebadatkeepingsecrets' ,
130+ release : '1.0.0' ,
131+ sample_rate : '1' ,
132+ trace_id : '1234567890abcdef1234567890abcdef' ,
133+ transaction : 'dogpark' ,
134+ user_segment : 'segmentA' ,
135+ } ,
136+ source : 'route' ,
137+ } ,
138+ } ,
139+ expect . any ( Function ) ,
140+ expect . any ( Function ) ,
141+ ) ;
121142 } ) ;
122143
123144 describe ( 'with error() helper' , ( ) => {
@@ -140,7 +161,7 @@ describe('wrapLoadWithSentry', () => {
140161 }
141162
142163 const wrappedLoad = wrapLoadWithSentry ( load ) ;
143- const res = wrappedLoad ( { params : { id : '1' } } as any ) ;
164+ const res = wrappedLoad ( MOCK_LOAD_ARGS ) ;
144165 await expect ( res ) . rejects . toThrow ( ) ;
145166
146167 expect ( mockCaptureException ) . toHaveBeenCalledTimes ( times ) ;
@@ -160,7 +181,7 @@ describe('wrapLoadWithSentry', () => {
160181 }
161182
162183 const wrappedLoad = wrapLoadWithSentry ( load ) ;
163- const res = wrappedLoad ( { params : { id : '1' } } as any ) ;
184+ const res = wrappedLoad ( MOCK_LOAD_ARGS ) ;
164185 await expect ( res ) . rejects . toThrow ( ) ;
165186
166187 expect ( addEventProcessorSpy ) . toBeCalledTimes ( 1 ) ;
0 commit comments