1
- // Note: These tests run the handler in Node.js, which is has some differences to the cloudflare workers runtime.
1
+ // Note: These tests run the handler in Node.js, which has some differences to the cloudflare workers runtime.
2
2
// Although this is not ideal, this is the best we can do until we have a better way to test cloudflare workers.
3
3
4
4
import { beforeEach , describe , expect , test , vi } from 'vitest' ;
@@ -69,9 +69,9 @@ describe('withSentry', () => {
69
69
} ) ;
70
70
71
71
test ( 'creates a cloudflare client and sets it on the handler' , async ( ) => {
72
+ const initAndBindSpy = vi . spyOn ( SentryCore , 'initAndBind' ) ;
72
73
const handler = {
73
74
async fetch ( _request , _env , _context ) {
74
- expect ( SentryCore . getClient ( ) instanceof CloudflareClient ) . toBe ( true ) ;
75
75
return new Response ( 'test' ) ;
76
76
} ,
77
77
} satisfies ExportedHandler ;
@@ -80,7 +80,8 @@ describe('withSentry', () => {
80
80
const wrappedHandler = withSentry ( ( ) => ( { } ) , handler ) ;
81
81
await wrappedHandler . fetch ( new Request ( 'https://example.com' ) , MOCK_ENV , context ) ;
82
82
83
- expect . assertions ( 1 ) ;
83
+ expect ( initAndBindSpy ) . toHaveBeenCalledTimes ( 1 ) ;
84
+ expect ( initAndBindSpy ) . toHaveBeenLastCalledWith ( CloudflareClient , expect . any ( Object ) ) ;
84
85
} ) ;
85
86
86
87
describe ( 'scope instrumentation' , ( ) => {
@@ -180,7 +181,9 @@ describe('withSentry', () => {
180
181
// ignore
181
182
}
182
183
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
183
- expect ( captureExceptionSpy ) . toHaveBeenLastCalledWith ( error , { mechanism : { handled : false } } ) ;
184
+ expect ( captureExceptionSpy ) . toHaveBeenLastCalledWith ( error , {
185
+ mechanism : { handled : false , type : 'cloudflare' } ,
186
+ } ) ;
184
187
} ) ;
185
188
186
189
test ( 're-throws the error after capturing' , async ( ) => {
0 commit comments