1
1
import { Scope , SessionFlusher } from '@sentry/hub' ;
2
+ import { NoopTransport } from '@sentry/core' ;
2
3
3
4
import { NodeClient } from '../src' ;
4
5
import { setupNodeTransport } from '../src/transports' ;
6
+ import { NodeClientOptions } from '../src/types' ;
5
7
6
8
const PUBLIC_DSN = 'https://username@domain/123' ;
7
9
10
+ function getDefaultNodeClientOptions ( options : Partial < NodeClientOptions > = { } ) : NodeClientOptions {
11
+ return {
12
+ integrations : [ ] ,
13
+ transport : NoopTransport ,
14
+ stackParser : ( ) => [ ] ,
15
+ ...options ,
16
+ } ;
17
+ }
18
+
8
19
describe ( 'NodeClient' , ( ) => {
9
20
let client : NodeClient ;
10
21
@@ -15,7 +26,7 @@ describe('NodeClient', () => {
15
26
16
27
describe ( 'captureException' , ( ) => {
17
28
test ( 'when autoSessionTracking is enabled, and requestHandler is not used -> requestStatus should not be set' , ( ) => {
18
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
29
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
19
30
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
20
31
const scope = new Scope ( ) ;
21
32
scope . setRequestSession ( { status : 'ok' } ) ;
@@ -26,7 +37,7 @@ describe('NodeClient', () => {
26
37
expect ( requestSession ! . status ) . toEqual ( 'ok' ) ;
27
38
} ) ;
28
39
test ( 'when autoSessionTracking is disabled -> requestStatus should not be set' , ( ) => {
29
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ;
40
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ) ;
30
41
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
31
42
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
32
43
// by the`requestHandler`)
@@ -41,7 +52,7 @@ describe('NodeClient', () => {
41
52
expect ( requestSession ! . status ) . toEqual ( 'ok' ) ;
42
53
} ) ;
43
54
test ( 'when autoSessionTracking is enabled + requestSession status is Crashed -> requestStatus should not be overridden' , ( ) => {
44
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
55
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
45
56
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
46
57
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
47
58
// by the`requestHandler`)
@@ -56,7 +67,7 @@ describe('NodeClient', () => {
56
67
expect ( requestSession ! . status ) . toEqual ( 'crashed' ) ;
57
68
} ) ;
58
69
test ( 'when autoSessionTracking is enabled + error occurs within request bounds -> requestStatus should be set to Errored' , ( ) => {
59
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
70
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
60
71
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
61
72
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
62
73
// by the`requestHandler`)
@@ -71,7 +82,7 @@ describe('NodeClient', () => {
71
82
expect ( requestSession ! . status ) . toEqual ( 'errored' ) ;
72
83
} ) ;
73
84
test ( 'when autoSessionTracking is enabled + error occurs outside of request bounds -> requestStatus should not be set to Errored' , ( ) => {
74
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
85
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
75
86
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
76
87
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
77
88
// by the`requestHandler`)
@@ -88,7 +99,7 @@ describe('NodeClient', () => {
88
99
89
100
describe ( 'captureEvent()' , ( ) => {
90
101
test ( 'If autoSessionTracking is disabled, requestSession status should not be set' , ( ) => {
91
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ;
102
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ) ;
92
103
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
93
104
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
94
105
// by the`requestHandler`)
@@ -107,7 +118,7 @@ describe('NodeClient', () => {
107
118
} ) ;
108
119
109
120
test ( 'When captureEvent is called with an exception, requestSession status should be set to Errored' , ( ) => {
110
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ;
121
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ) ;
111
122
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
112
123
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
113
124
// by the`requestHandler`)
@@ -123,7 +134,7 @@ describe('NodeClient', () => {
123
134
} ) ;
124
135
125
136
test ( 'When captureEvent is called without an exception, requestSession status should not be set to Errored' , ( ) => {
126
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ;
137
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ) ;
127
138
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
128
139
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
129
140
// by the`requestHandler`)
@@ -139,7 +150,7 @@ describe('NodeClient', () => {
139
150
} ) ;
140
151
141
152
test ( 'When captureEvent is called with an exception but outside of a request, then requestStatus should not be set' , ( ) => {
142
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ;
153
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ) ;
143
154
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
144
155
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
145
156
// by the`requestHandler`)
@@ -157,7 +168,7 @@ describe('NodeClient', () => {
157
168
} ) ;
158
169
159
170
test ( 'When captureEvent is called with a transaction, then requestSession status should not be set' , ( ) => {
160
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ;
171
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ) ;
161
172
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
162
173
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
163
174
// by the`requestHandler`)
@@ -172,7 +183,7 @@ describe('NodeClient', () => {
172
183
} ) ;
173
184
174
185
test ( 'When captureEvent is called with an exception but requestHandler is not used, then requestSession status should not be set' , ( ) => {
175
- const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ;
186
+ const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ) ;
176
187
client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
177
188
178
189
const scope = new Scope ( ) ;
@@ -192,11 +203,11 @@ describe('NodeClient', () => {
192
203
describe ( 'flush/close' , ( ) => {
193
204
test ( 'client close function disables _sessionFlusher' , async ( ) => {
194
205
jest . useRealTimers ( ) ;
195
- const options = {
206
+ const options = getDefaultNodeClientOptions ( {
196
207
dsn : PUBLIC_DSN ,
197
208
autoSessionTracking : true ,
198
209
release : '1.1' ,
199
- } ;
210
+ } ) ;
200
211
const client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
201
212
client . initSessionFlusher ( ) ;
202
213
// Clearing interval is important here to ensure that the flush function later on is called by the `client.close()`
0 commit comments