@@ -51,17 +51,11 @@ describe('AWSLambda', () => {
51
51
test ( 'flushTimeout' , async ( ) => {
52
52
expect . assertions ( 1 ) ;
53
53
54
- const error = new Error ( 'wat' ) ;
55
- const handler = ( ) => {
56
- throw error ;
57
- } ;
54
+ const handler = ( ) => { } ;
58
55
const wrappedHandler = wrapHandler ( handler , { flushTimeout : 1337 } ) ;
59
56
60
- try {
61
- await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
62
- } catch ( e ) {
63
- expect ( Sentry . flush ) . toBeCalledWith ( 1337 ) ;
64
- }
57
+ await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
58
+ expect ( Sentry . flush ) . toBeCalledWith ( 1337 ) ;
65
59
} ) ;
66
60
67
61
test ( 'rethrowAfterCapture' , async ( ) => {
@@ -146,18 +140,24 @@ describe('AWSLambda', () => {
146
140
147
141
describe ( 'wrapHandler() on sync handler' , ( ) => {
148
142
test ( 'successful execution' , async ( ) => {
149
- expect . assertions ( 1 ) ;
143
+ expect . assertions ( 5 ) ;
150
144
151
145
const handler : Handler = ( _event , _context , callback ) => {
152
146
callback ( null , 42 ) ;
153
147
} ;
154
148
const wrappedHandler = wrapHandler ( handler ) ;
155
149
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
156
150
expect ( rv ) . toStrictEqual ( 42 ) ;
151
+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
152
+ // @ts -ignore see "Why @ts-ignore" note
153
+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
154
+ // @ts -ignore see "Why @ts-ignore" note
155
+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
156
+ expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
157
157
} ) ;
158
158
159
159
test ( 'unsuccessful execution' , async ( ) => {
160
- expect . assertions ( 2 ) ;
160
+ expect . assertions ( 5 ) ;
161
161
162
162
const error = new Error ( 'sorry' ) ;
163
163
const handler : Handler = ( _event , _context , callback ) => {
@@ -168,7 +168,12 @@ describe('AWSLambda', () => {
168
168
try {
169
169
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
170
170
} catch ( e ) {
171
+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
172
+ // @ts -ignore see "Why @ts-ignore" note
173
+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
171
174
expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
175
+ // @ts -ignore see "Why @ts-ignore" note
176
+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
172
177
expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
173
178
}
174
179
} ) ;
@@ -186,7 +191,7 @@ describe('AWSLambda', () => {
186
191
} ) ;
187
192
188
193
test ( 'capture error' , async ( ) => {
189
- expect . assertions ( 2 ) ;
194
+ expect . assertions ( 5 ) ;
190
195
191
196
const error = new Error ( 'wat' ) ;
192
197
const handler : Handler = ( _event , _context , _callback ) => {
@@ -197,22 +202,33 @@ describe('AWSLambda', () => {
197
202
try {
198
203
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
199
204
} catch ( e ) {
200
- expect ( Sentry . captureException ) . toBeCalled ( ) ;
205
+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
206
+ // @ts -ignore see "Why @ts-ignore" note
207
+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
208
+ expect ( Sentry . captureException ) . toBeCalledWith ( e ) ;
209
+ // @ts -ignore see "Why @ts-ignore" note
210
+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
201
211
expect ( Sentry . flush ) . toBeCalled ( ) ;
202
212
}
203
213
} ) ;
204
214
} ) ;
205
215
206
216
describe ( 'wrapHandler() on async handler' , ( ) => {
207
217
test ( 'successful execution' , async ( ) => {
208
- expect . assertions ( 1 ) ;
218
+ expect . assertions ( 5 ) ;
209
219
210
220
const handler : Handler = async ( _event , _context ) => {
211
221
return 42 ;
212
222
} ;
213
223
const wrappedHandler = wrapHandler ( handler ) ;
214
224
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
215
225
expect ( rv ) . toStrictEqual ( 42 ) ;
226
+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
227
+ // @ts -ignore see "Why @ts-ignore" note
228
+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
229
+ // @ts -ignore see "Why @ts-ignore" note
230
+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
231
+ expect ( Sentry . flush ) . toBeCalled ( ) ;
216
232
} ) ;
217
233
218
234
test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -227,7 +243,7 @@ describe('AWSLambda', () => {
227
243
} ) ;
228
244
229
245
test ( 'capture error' , async ( ) => {
230
- expect . assertions ( 2 ) ;
246
+ expect . assertions ( 5 ) ;
231
247
232
248
const error = new Error ( 'wat' ) ;
233
249
const handler : Handler = async ( _event , _context ) => {
@@ -238,22 +254,33 @@ describe('AWSLambda', () => {
238
254
try {
239
255
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
240
256
} catch ( e ) {
241
- expect ( Sentry . captureException ) . toBeCalled ( ) ;
257
+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
258
+ // @ts -ignore see "Why @ts-ignore" note
259
+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
260
+ expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
261
+ // @ts -ignore see "Why @ts-ignore" note
262
+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
242
263
expect ( Sentry . flush ) . toBeCalled ( ) ;
243
264
}
244
265
} ) ;
245
266
} ) ;
246
267
247
268
describe ( 'wrapHandler() on async handler with a callback method (aka incorrect usage)' , ( ) => {
248
269
test ( 'successful execution' , async ( ) => {
249
- expect . assertions ( 1 ) ;
270
+ expect . assertions ( 5 ) ;
250
271
251
272
const handler : Handler = async ( _event , _context , _callback ) => {
252
273
return 42 ;
253
274
} ;
254
275
const wrappedHandler = wrapHandler ( handler ) ;
255
276
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
256
277
expect ( rv ) . toStrictEqual ( 42 ) ;
278
+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
279
+ // @ts -ignore see "Why @ts-ignore" note
280
+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
281
+ // @ts -ignore see "Why @ts-ignore" note
282
+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
283
+ expect ( Sentry . flush ) . toBeCalled ( ) ;
257
284
} ) ;
258
285
259
286
test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -268,7 +295,7 @@ describe('AWSLambda', () => {
268
295
} ) ;
269
296
270
297
test ( 'capture error' , async ( ) => {
271
- expect . assertions ( 2 ) ;
298
+ expect . assertions ( 5 ) ;
272
299
273
300
const error = new Error ( 'wat' ) ;
274
301
const handler : Handler = async ( _event , _context , _callback ) => {
@@ -279,7 +306,12 @@ describe('AWSLambda', () => {
279
306
try {
280
307
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
281
308
} catch ( e ) {
282
- expect ( Sentry . captureException ) . toBeCalled ( ) ;
309
+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
310
+ // @ts -ignore see "Why @ts-ignore" note
311
+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
312
+ expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
313
+ // @ts -ignore see "Why @ts-ignore" note
314
+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
283
315
expect ( Sentry . flush ) . toBeCalled ( ) ;
284
316
}
285
317
} ) ;
0 commit comments