@@ -374,24 +374,21 @@ describe('tracingHandler', () => {
374
374
const tracesSampler = jest . fn ( ) ;
375
375
const options = getDefaultNodeClientOptions ( { tracesSampler } ) ;
376
376
const hub = new Hub ( new NodeClient ( options ) ) ;
377
- // we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
378
- // `@sentry/hub`, and mocking breaks the link between the two
379
- jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
380
- jest . spyOn ( sentryHub , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
381
-
382
- sentryTracingMiddleware ( req , res , next ) ;
383
-
384
- expect ( tracesSampler ) . toHaveBeenCalledWith (
385
- expect . objectContaining ( {
386
- request : {
387
- headers,
388
- method,
389
- url : `http://${ hostname } ${ path } ?${ queryString } ` ,
390
- cookies : { favorite : 'zukes' } ,
391
- query_string : queryString ,
392
- } ,
393
- } ) ,
394
- ) ;
377
+ hub . run ( ( ) => {
378
+ sentryTracingMiddleware ( req , res , next ) ;
379
+
380
+ expect ( tracesSampler ) . toHaveBeenCalledWith (
381
+ expect . objectContaining ( {
382
+ request : {
383
+ headers,
384
+ method,
385
+ url : `http://${ hostname } ${ path } ?${ queryString } ` ,
386
+ cookies : { favorite : 'zukes' } ,
387
+ query_string : queryString ,
388
+ } ,
389
+ } ) ,
390
+ ) ;
391
+ } ) ;
395
392
} ) ;
396
393
397
394
it ( 'puts its transaction on the scope' , ( ) => {
@@ -773,13 +770,13 @@ describe('errorHandler()', () => {
773
770
const hub = new Hub ( client , scope ) ;
774
771
775
772
jest . spyOn < any , any > ( client , '_captureRequestSession' ) ;
776
- jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
777
- jest . spyOn ( sentryHub , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
778
773
779
- scope ?. setRequestSession ( { status : 'ok' } ) ;
780
- sentryErrorMiddleware ( { name : 'error' , message : 'this is an error' } , req , res , next ) ;
781
- const requestSession = scope ?. getRequestSession ( ) ;
782
- expect ( requestSession ) . toEqual ( { status : 'crashed' } ) ;
774
+ hub . run ( ( ) => {
775
+ scope ?. setRequestSession ( { status : 'ok' } ) ;
776
+ sentryErrorMiddleware ( { name : 'error' , message : 'this is an error' } , req , res , next ) ;
777
+ const requestSession = scope ?. getRequestSession ( ) ;
778
+ expect ( requestSession ) . toEqual ( { status : 'crashed' } ) ;
779
+ } ) ;
783
780
} ) ;
784
781
785
782
it ( 'when autoSessionTracking is enabled, should not set requestSession status on Crash when it occurs outside the bounds of a request' , ( ) => {
0 commit comments