@@ -18,6 +18,7 @@ import {
18
18
tracingHandler ,
19
19
} from '../src/handlers' ;
20
20
import * as SDK from '../src/sdk' ;
21
+ import { setupNodeTransport } from '../src/transports' ;
21
22
22
23
describe ( 'parseRequest' , ( ) => {
23
24
let mockReq : { [ key : string ] : any } ;
@@ -223,7 +224,8 @@ describe('requestHandler', () => {
223
224
} ) ;
224
225
225
226
it ( 'autoSessionTracking is enabled, sets requestSession status to ok, when handling a request' , ( ) => {
226
- client = new NodeClient ( { autoSessionTracking : true , release : '1.2' } ) ;
227
+ const options = { autoSessionTracking : true , release : '1.2' } ;
228
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
227
229
const hub = new Hub ( client ) ;
228
230
229
231
jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
@@ -235,7 +237,8 @@ describe('requestHandler', () => {
235
237
} ) ;
236
238
237
239
it ( 'autoSessionTracking is disabled, does not set requestSession, when handling a request' , ( ) => {
238
- client = new NodeClient ( { autoSessionTracking : false , release : '1.2' } ) ;
240
+ const options = { autoSessionTracking : false , release : '1.2' } ;
241
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
239
242
const hub = new Hub ( client ) ;
240
243
241
244
jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
@@ -247,7 +250,8 @@ describe('requestHandler', () => {
247
250
} ) ;
248
251
249
252
it ( 'autoSessionTracking is enabled, calls _captureRequestSession, on response finish' , done => {
250
- client = new NodeClient ( { autoSessionTracking : true , release : '1.2' } ) ;
253
+ const options = { autoSessionTracking : true , release : '1.2' } ;
254
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
251
255
const hub = new Hub ( client ) ;
252
256
253
257
jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
@@ -267,7 +271,8 @@ describe('requestHandler', () => {
267
271
} ) ;
268
272
269
273
it ( 'autoSessionTracking is disabled, does not call _captureRequestSession, on response finish' , done => {
270
- client = new NodeClient ( { autoSessionTracking : false , release : '1.2' } ) ;
274
+ const options = { autoSessionTracking : false , release : '1.2' } ;
275
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
271
276
const hub = new Hub ( client ) ;
272
277
jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
273
278
@@ -367,7 +372,8 @@ describe('tracingHandler', () => {
367
372
368
373
it ( 'extracts request data for sampling context' , ( ) => {
369
374
const tracesSampler = jest . fn ( ) ;
370
- const hub = new Hub ( new NodeClient ( { tracesSampler } ) ) ;
375
+ const options = { tracesSampler } ;
376
+ const hub = new Hub ( new NodeClient ( options , setupNodeTransport ( options ) . transport ) ) ;
371
377
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
372
378
// `@sentry/hub`, and mocking breaks the link between the two
373
379
jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
@@ -389,7 +395,8 @@ describe('tracingHandler', () => {
389
395
} ) ;
390
396
391
397
it ( 'puts its transaction on the scope' , ( ) => {
392
- const hub = new Hub ( new NodeClient ( { tracesSampleRate : 1.0 } ) ) ;
398
+ const options = { tracesSampleRate : 1.0 } ;
399
+ const hub = new Hub ( new NodeClient ( options , setupNodeTransport ( options ) . transport ) ) ;
393
400
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
394
401
// `@sentry/hub`, and mocking breaks the link between the two
395
402
jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
@@ -720,7 +727,8 @@ describe('errorHandler()', () => {
720
727
jest . restoreAllMocks ( ) ;
721
728
} ) ;
722
729
it ( 'when autoSessionTracking is disabled, does not set requestSession status on Crash' , ( ) => {
723
- client = new NodeClient ( { autoSessionTracking : false , release : '3.3' } ) ;
730
+ const options = { autoSessionTracking : false , release : '3.3' } ;
731
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
724
732
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
725
733
// by the`requestHandler`)
726
734
client . initSessionFlusher ( ) ;
@@ -739,7 +747,8 @@ describe('errorHandler()', () => {
739
747
} ) ;
740
748
741
749
it ( 'autoSessionTracking is enabled + requestHandler is not used -> does not set requestSession status on Crash' , ( ) => {
742
- client = new NodeClient ( { autoSessionTracking : false , release : '3.3' } ) ;
750
+ const options = { autoSessionTracking : false , release : '3.3' } ;
751
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
743
752
744
753
const scope = sentryCore . getCurrentHub ( ) . getScope ( ) ;
745
754
const hub = new Hub ( client ) ;
@@ -755,7 +764,8 @@ describe('errorHandler()', () => {
755
764
} ) ;
756
765
757
766
it ( 'when autoSessionTracking is enabled, should set requestSession status to Crashed when an unhandled error occurs within the bounds of a request' , ( ) => {
758
- client = new NodeClient ( { autoSessionTracking : true , release : '1.1' } ) ;
767
+ const options = { autoSessionTracking : true , release : '1.1' } ;
768
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
759
769
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
760
770
// by the`requestHandler`)
761
771
client . initSessionFlusher ( ) ;
@@ -773,7 +783,8 @@ describe('errorHandler()', () => {
773
783
} ) ;
774
784
775
785
it ( 'when autoSessionTracking is enabled, should not set requestSession status on Crash when it occurs outside the bounds of a request' , ( ) => {
776
- client = new NodeClient ( { autoSessionTracking : true , release : '2.2' } ) ;
786
+ const options = { autoSessionTracking : true , release : '2.2' } ;
787
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
777
788
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
778
789
// by the`requestHandler`)
779
790
client . initSessionFlusher ( ) ;
0 commit comments