1
1
import { Scope , SessionFlusher } from '@sentry/hub' ;
2
2
3
3
import { NodeClient } from '../src' ;
4
+ import { setupNodeTransport } from '../src/transports' ;
4
5
5
6
const PUBLIC_DSN = 'https://username@domain/123' ;
6
7
@@ -14,7 +15,8 @@ describe('NodeClient', () => {
14
15
15
16
describe ( 'captureException' , ( ) => {
16
17
test ( 'when autoSessionTracking is enabled, and requestHandler is not used -> requestStatus should not be set' , ( ) => {
17
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
18
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
19
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
18
20
const scope = new Scope ( ) ;
19
21
scope . setRequestSession ( { status : 'ok' } ) ;
20
22
@@ -24,7 +26,8 @@ describe('NodeClient', () => {
24
26
expect ( requestSession ! . status ) . toEqual ( 'ok' ) ;
25
27
} ) ;
26
28
test ( 'when autoSessionTracking is disabled -> requestStatus should not be set' , ( ) => {
27
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ) ;
29
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ;
30
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
28
31
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
29
32
// by the`requestHandler`)
30
33
client . initSessionFlusher ( ) ;
@@ -38,7 +41,8 @@ describe('NodeClient', () => {
38
41
expect ( requestSession ! . status ) . toEqual ( 'ok' ) ;
39
42
} ) ;
40
43
test ( 'when autoSessionTracking is enabled + requestSession status is Crashed -> requestStatus should not be overridden' , ( ) => {
41
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
44
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
45
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
42
46
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
43
47
// by the`requestHandler`)
44
48
client . initSessionFlusher ( ) ;
@@ -52,7 +56,8 @@ describe('NodeClient', () => {
52
56
expect ( requestSession ! . status ) . toEqual ( 'crashed' ) ;
53
57
} ) ;
54
58
test ( 'when autoSessionTracking is enabled + error occurs within request bounds -> requestStatus should be set to Errored' , ( ) => {
55
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
59
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
60
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
56
61
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
57
62
// by the`requestHandler`)
58
63
client . initSessionFlusher ( ) ;
@@ -66,7 +71,8 @@ describe('NodeClient', () => {
66
71
expect ( requestSession ! . status ) . toEqual ( 'errored' ) ;
67
72
} ) ;
68
73
test ( 'when autoSessionTracking is enabled + error occurs outside of request bounds -> requestStatus should not be set to Errored' , ( ) => {
69
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ) ;
74
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.4' } ;
75
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
70
76
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
71
77
// by the`requestHandler`)
72
78
client . initSessionFlusher ( ) ;
@@ -82,7 +88,8 @@ describe('NodeClient', () => {
82
88
83
89
describe ( 'captureEvent()' , ( ) => {
84
90
test ( 'If autoSessionTracking is disabled, requestSession status should not be set' , ( ) => {
85
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ) ;
91
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : false , release : '1.4' } ;
92
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
86
93
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
87
94
// by the`requestHandler`)
88
95
client . initSessionFlusher ( ) ;
@@ -100,7 +107,8 @@ describe('NodeClient', () => {
100
107
} ) ;
101
108
102
109
test ( 'When captureEvent is called with an exception, requestSession status should be set to Errored' , ( ) => {
103
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ) ;
110
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ;
111
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
104
112
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
105
113
// by the`requestHandler`)
106
114
client . initSessionFlusher ( ) ;
@@ -115,7 +123,8 @@ describe('NodeClient', () => {
115
123
} ) ;
116
124
117
125
test ( 'When captureEvent is called without an exception, requestSession status should not be set to Errored' , ( ) => {
118
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ) ;
126
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ;
127
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
119
128
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
120
129
// by the`requestHandler`)
121
130
client . initSessionFlusher ( ) ;
@@ -130,7 +139,8 @@ describe('NodeClient', () => {
130
139
} ) ;
131
140
132
141
test ( 'When captureEvent is called with an exception but outside of a request, then requestStatus should not be set' , ( ) => {
133
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ) ;
142
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '2.2' } ;
143
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
134
144
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
135
145
// by the`requestHandler`)
136
146
client . initSessionFlusher ( ) ;
@@ -147,7 +157,8 @@ describe('NodeClient', () => {
147
157
} ) ;
148
158
149
159
test ( 'When captureEvent is called with a transaction, then requestSession status should not be set' , ( ) => {
150
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ) ;
160
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ;
161
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
151
162
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
152
163
// by the`requestHandler`)
153
164
client . initSessionFlusher ( ) ;
@@ -161,7 +172,8 @@ describe('NodeClient', () => {
161
172
} ) ;
162
173
163
174
test ( 'When captureEvent is called with an exception but requestHandler is not used, then requestSession status should not be set' , ( ) => {
164
- client = new NodeClient ( { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ) ;
175
+ const options = { dsn : PUBLIC_DSN , autoSessionTracking : true , release : '1.3' } ;
176
+ client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
165
177
166
178
const scope = new Scope ( ) ;
167
179
scope . setRequestSession ( { status : 'ok' } ) ;
@@ -180,11 +192,12 @@ describe('NodeClient', () => {
180
192
describe ( 'flush/close' , ( ) => {
181
193
test ( 'client close function disables _sessionFlusher' , async ( ) => {
182
194
jest . useRealTimers ( ) ;
183
- const client = new NodeClient ( {
195
+ const options = {
184
196
dsn : PUBLIC_DSN ,
185
197
autoSessionTracking : true ,
186
198
release : '1.1' ,
187
- } ) ;
199
+ } ;
200
+ const client = new NodeClient ( options , setupNodeTransport ( options ) . transport ) ;
188
201
client . initSessionFlusher ( ) ;
189
202
// Clearing interval is important here to ensure that the flush function later on is called by the `client.close()`
190
203
// not due to the interval running every 60s
0 commit comments