@@ -19,6 +19,16 @@ import {
19
19
} from '../src/handlers' ;
20
20
import * as SDK from '../src/sdk' ;
21
21
import { setupNodeTransport } from '../src/transports' ;
22
+ import { NodeClientOptions } from '../src/types' ;
23
+
24
+ function getDefaultNodeClientOptions ( options : Partial < NodeClientOptions > = { } ) : NodeClientOptions {
25
+ return {
26
+ integrations : [ ] ,
27
+ transport : sentryCore . NoopTransport ,
28
+ stackParser : ( ) => [ ] ,
29
+ ...options ,
30
+ } ;
31
+ }
22
32
23
33
describe ( 'parseRequest' , ( ) => {
24
34
let mockReq : { [ key : string ] : any } ;
@@ -224,7 +234,7 @@ describe('requestHandler', () => {
224
234
} ) ;
225
235
226
236
it ( 'autoSessionTracking is enabled, sets requestSession status to ok, when handling a request' , ( ) => {
227
- const options = { autoSessionTracking : true , release : '1.2' } ;
237
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : true , release : '1.2' } ) ;
228
238
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
229
239
const hub = new Hub ( client ) ;
230
240
@@ -237,7 +247,7 @@ describe('requestHandler', () => {
237
247
} ) ;
238
248
239
249
it ( 'autoSessionTracking is disabled, does not set requestSession, when handling a request' , ( ) => {
240
- const options = { autoSessionTracking : false , release : '1.2' } ;
250
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : false , release : '1.2' } ) ;
241
251
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
242
252
const hub = new Hub ( client ) ;
243
253
@@ -250,7 +260,7 @@ describe('requestHandler', () => {
250
260
} ) ;
251
261
252
262
it ( 'autoSessionTracking is enabled, calls _captureRequestSession, on response finish' , done => {
253
- const options = { autoSessionTracking : true , release : '1.2' } ;
263
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : true , release : '1.2' } ) ;
254
264
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
255
265
const hub = new Hub ( client ) ;
256
266
@@ -271,7 +281,7 @@ describe('requestHandler', () => {
271
281
} ) ;
272
282
273
283
it ( 'autoSessionTracking is disabled, does not call _captureRequestSession, on response finish' , done => {
274
- const options = { autoSessionTracking : false , release : '1.2' } ;
284
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : false , release : '1.2' } ) ;
275
285
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
276
286
const hub = new Hub ( client ) ;
277
287
jest . spyOn ( sentryCore , 'getCurrentHub' ) . mockReturnValue ( hub ) ;
@@ -372,7 +382,7 @@ describe('tracingHandler', () => {
372
382
373
383
it ( 'extracts request data for sampling context' , ( ) => {
374
384
const tracesSampler = jest . fn ( ) ;
375
- const options = { tracesSampler } ;
385
+ const options = getDefaultNodeClientOptions ( { tracesSampler } ) ;
376
386
const hub = new Hub ( new NodeClient ( options , setupNodeTransport ( options ) . transport ) ) ;
377
387
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
378
388
// `@sentry/hub`, and mocking breaks the link between the two
@@ -395,7 +405,7 @@ describe('tracingHandler', () => {
395
405
} ) ;
396
406
397
407
it ( 'puts its transaction on the scope' , ( ) => {
398
- const options = { tracesSampleRate : 1.0 } ;
408
+ const options = getDefaultNodeClientOptions ( { tracesSampleRate : 1.0 } ) ;
399
409
const hub = new Hub ( new NodeClient ( options , setupNodeTransport ( options ) . transport ) ) ;
400
410
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
401
411
// `@sentry/hub`, and mocking breaks the link between the two
@@ -727,7 +737,7 @@ describe('errorHandler()', () => {
727
737
jest . restoreAllMocks ( ) ;
728
738
} ) ;
729
739
it ( 'when autoSessionTracking is disabled, does not set requestSession status on Crash' , ( ) => {
730
- const options = { autoSessionTracking : false , release : '3.3' } ;
740
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : false , release : '3.3' } ) ;
731
741
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
732
742
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
733
743
// by the`requestHandler`)
@@ -747,7 +757,7 @@ describe('errorHandler()', () => {
747
757
} ) ;
748
758
749
759
it ( 'autoSessionTracking is enabled + requestHandler is not used -> does not set requestSession status on Crash' , ( ) => {
750
- const options = { autoSessionTracking : false , release : '3.3' } ;
760
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : false , release : '3.3' } ) ;
751
761
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
752
762
753
763
const scope = sentryCore . getCurrentHub ( ) . getScope ( ) ;
@@ -764,7 +774,7 @@ describe('errorHandler()', () => {
764
774
} ) ;
765
775
766
776
it ( 'when autoSessionTracking is enabled, should set requestSession status to Crashed when an unhandled error occurs within the bounds of a request' , ( ) => {
767
- const options = { autoSessionTracking : true , release : '1.1' } ;
777
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : true , release : '1.1' } ) ;
768
778
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
769
779
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
770
780
// by the`requestHandler`)
@@ -783,7 +793,7 @@ describe('errorHandler()', () => {
783
793
} ) ;
784
794
785
795
it ( 'when autoSessionTracking is enabled, should not set requestSession status on Crash when it occurs outside the bounds of a request' , ( ) => {
786
- const options = { autoSessionTracking : true , release : '2.2' } ;
796
+ const options = getDefaultNodeClientOptions ( { autoSessionTracking : true , release : '2.2' } ) ;
787
797
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
788
798
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
789
799
// by the`requestHandler`)
0 commit comments