1
1
// NOTE: I have no idea how to fix this right now, and don't want to waste more time, as it builds just fine — Kamil
2
2
// eslint-disable-next-line import/no-unresolved
3
+ import * as SentryNode from '@sentry/node' ;
4
+ // eslint-disable-next-line import/no-unresolved
3
5
import type { Callback , Handler } from 'aws-lambda' ;
4
6
5
7
import * as Sentry from '../src' ;
@@ -40,15 +42,15 @@ const fakeCallback: Callback = (err, result) => {
40
42
41
43
function expectScopeSettings ( fakeTransactionContext : any ) {
42
44
// @ts -ignore see "Why @ts-ignore" note
43
- const fakeTransaction = { ...Sentry . fakeTransaction , ...fakeTransactionContext } ;
45
+ const fakeTransaction = { ...SentryNode . fakeTransaction , ...fakeTransactionContext } ;
44
46
// @ts -ignore see "Why @ts-ignore" note
45
- expect ( Sentry . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
47
+ expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
46
48
// @ts -ignore see "Why @ts-ignore" note
47
- expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'server_name' , expect . anything ( ) ) ;
49
+ expect ( SentryNode . fakeScope . setTag ) . toBeCalledWith ( 'server_name' , expect . anything ( ) ) ;
48
50
// @ts -ignore see "Why @ts-ignore" note
49
- expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'url' , 'awslambda:///functionName' ) ;
51
+ expect ( SentryNode . fakeScope . setTag ) . toBeCalledWith ( 'url' , 'awslambda:///functionName' ) ;
50
52
// @ts -ignore see "Why @ts-ignore" note
51
- expect ( Sentry . fakeScope . setContext ) . toBeCalledWith (
53
+ expect ( SentryNode . fakeScope . setContext ) . toBeCalledWith (
52
54
'aws.lambda' ,
53
55
expect . objectContaining ( {
54
56
aws_request_id : 'awsRequestId' ,
@@ -59,7 +61,7 @@ function expectScopeSettings(fakeTransactionContext: any) {
59
61
} ) ,
60
62
) ;
61
63
// @ts -ignore see "Why @ts-ignore" note
62
- expect ( Sentry . fakeScope . setContext ) . toBeCalledWith (
64
+ expect ( SentryNode . fakeScope . setContext ) . toBeCalledWith (
63
65
'aws.cloudwatch.logs' ,
64
66
expect . objectContaining ( {
65
67
log_group : 'logGroupName' ,
@@ -77,7 +79,7 @@ describe('AWSLambda', () => {
77
79
78
80
afterEach ( ( ) => {
79
81
// @ts -ignore see "Why @ts-ignore" note
80
- Sentry . resetMocks ( ) ;
82
+ SentryNode . resetMocks ( ) ;
81
83
} ) ;
82
84
83
85
describe ( 'wrapHandler() options' , ( ) => {
@@ -88,7 +90,7 @@ describe('AWSLambda', () => {
88
90
const wrappedHandler = wrapHandler ( handler , { flushTimeout : 1337 } ) ;
89
91
90
92
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
91
- expect ( Sentry . flush ) . toBeCalledWith ( 1337 ) ;
93
+ expect ( SentryNode . flush ) . toBeCalledWith ( 1337 ) ;
92
94
} ) ;
93
95
94
96
test ( 'captureTimeoutWarning enabled (default)' , async ( ) => {
@@ -104,7 +106,7 @@ describe('AWSLambda', () => {
104
106
105
107
expect ( Sentry . captureMessage ) . toBeCalled ( ) ;
106
108
// @ts -ignore see "Why @ts-ignore" note
107
- expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'timeout' , '1s' ) ;
109
+ expect ( SentryNode . fakeScope . setTag ) . toBeCalledWith ( 'timeout' , '1s' ) ;
108
110
} ) ;
109
111
110
112
test ( 'captureTimeoutWarning disabled' , async ( ) => {
@@ -152,14 +154,14 @@ describe('AWSLambda', () => {
152
154
153
155
expect ( Sentry . captureMessage ) . toBeCalled ( ) ;
154
156
// @ts -ignore see "Why @ts-ignore" note
155
- expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'timeout' , '1m40s' ) ;
157
+ expect ( SentryNode . fakeScope . setTag ) . toBeCalledWith ( 'timeout' , '1m40s' ) ;
156
158
} ) ;
157
159
158
160
test ( 'captureAllSettledReasons disabled (default)' , async ( ) => {
159
161
const handler = ( ) => Promise . resolve ( [ { status : 'rejected' , reason : new Error ( ) } ] ) ;
160
162
const wrappedHandler = wrapHandler ( handler , { flushTimeout : 1337 } ) ;
161
163
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
162
- expect ( Sentry . captureException ) . toBeCalledTimes ( 0 ) ;
164
+ expect ( SentryNode . captureException ) . toBeCalledTimes ( 0 ) ;
163
165
} ) ;
164
166
165
167
test ( 'captureAllSettledReasons enable' , async ( ) => {
@@ -173,9 +175,9 @@ describe('AWSLambda', () => {
173
175
] ) ;
174
176
const wrappedHandler = wrapHandler ( handler , { flushTimeout : 1337 , captureAllSettledReasons : true } ) ;
175
177
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
176
- expect ( Sentry . captureException ) . toHaveBeenNthCalledWith ( 1 , error ) ;
177
- expect ( Sentry . captureException ) . toHaveBeenNthCalledWith ( 2 , error2 ) ;
178
- expect ( Sentry . captureException ) . toBeCalledTimes ( 2 ) ;
178
+ expect ( SentryNode . captureException ) . toHaveBeenNthCalledWith ( 1 , error ) ;
179
+ expect ( SentryNode . captureException ) . toHaveBeenNthCalledWith ( 2 , error2 ) ;
180
+ expect ( SentryNode . captureException ) . toBeCalledTimes ( 2 ) ;
179
181
} ) ;
180
182
} ) ;
181
183
@@ -197,11 +199,11 @@ describe('AWSLambda', () => {
197
199
198
200
expect ( rv ) . toStrictEqual ( 42 ) ;
199
201
// @ts -ignore see "Why @ts-ignore" note
200
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
202
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
201
203
expectScopeSettings ( fakeTransactionContext ) ;
202
204
// @ts -ignore see "Why @ts-ignore" note
203
- expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
204
- expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
205
+ expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
206
+ expect ( SentryNode . flush ) . toBeCalledWith ( 2000 ) ;
205
207
} ) ;
206
208
207
209
test ( 'unsuccessful execution' , async ( ) => {
@@ -223,12 +225,12 @@ describe('AWSLambda', () => {
223
225
} ;
224
226
225
227
// @ts -ignore see "Why @ts-ignore" note
226
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
228
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
227
229
expectScopeSettings ( fakeTransactionContext ) ;
228
- expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
230
+ expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
229
231
// @ts -ignore see "Why @ts-ignore" note
230
- expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
231
- expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
232
+ expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
233
+ expect ( SentryNode . flush ) . toBeCalledWith ( 2000 ) ;
232
234
}
233
235
} ) ;
234
236
@@ -254,7 +256,7 @@ describe('AWSLambda', () => {
254
256
255
257
const handler : Handler = ( _event , _context , callback ) => {
256
258
// @ts -ignore see "Why @ts-ignore" note
257
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith (
259
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith (
258
260
expect . objectContaining ( {
259
261
parentSpanId : '1121201211212012' ,
260
262
parentSampled : false ,
@@ -300,12 +302,12 @@ describe('AWSLambda', () => {
300
302
} ;
301
303
302
304
// @ts -ignore see "Why @ts-ignore" note
303
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
305
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
304
306
expectScopeSettings ( fakeTransactionContext ) ;
305
- expect ( Sentry . captureException ) . toBeCalledWith ( e ) ;
307
+ expect ( SentryNode . captureException ) . toBeCalledWith ( e ) ;
306
308
// @ts -ignore see "Why @ts-ignore" note
307
- expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
308
- expect ( Sentry . flush ) . toBeCalled ( ) ;
309
+ expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
310
+ expect ( SentryNode . flush ) . toBeCalled ( ) ;
309
311
}
310
312
} ) ;
311
313
} ) ;
@@ -328,11 +330,11 @@ describe('AWSLambda', () => {
328
330
329
331
expect ( rv ) . toStrictEqual ( 42 ) ;
330
332
// @ts -ignore see "Why @ts-ignore" note
331
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
333
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
332
334
expectScopeSettings ( fakeTransactionContext ) ;
333
335
// @ts -ignore see "Why @ts-ignore" note
334
- expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
335
- expect ( Sentry . flush ) . toBeCalled ( ) ;
336
+ expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
337
+ expect ( SentryNode . flush ) . toBeCalled ( ) ;
336
338
} ) ;
337
339
338
340
test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -365,12 +367,12 @@ describe('AWSLambda', () => {
365
367
} ;
366
368
367
369
// @ts -ignore see "Why @ts-ignore" note
368
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
370
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
369
371
expectScopeSettings ( fakeTransactionContext ) ;
370
- expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
372
+ expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
371
373
// @ts -ignore see "Why @ts-ignore" note
372
- expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
373
- expect ( Sentry . flush ) . toBeCalled ( ) ;
374
+ expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
375
+ expect ( SentryNode . flush ) . toBeCalled ( ) ;
374
376
}
375
377
} ) ;
376
378
@@ -408,11 +410,11 @@ describe('AWSLambda', () => {
408
410
409
411
expect ( rv ) . toStrictEqual ( 42 ) ;
410
412
// @ts -ignore see "Why @ts-ignore" note
411
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
413
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
412
414
expectScopeSettings ( fakeTransactionContext ) ;
413
415
// @ts -ignore see "Why @ts-ignore" note
414
- expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
415
- expect ( Sentry . flush ) . toBeCalled ( ) ;
416
+ expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
417
+ expect ( SentryNode . flush ) . toBeCalled ( ) ;
416
418
} ) ;
417
419
418
420
test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -445,12 +447,12 @@ describe('AWSLambda', () => {
445
447
} ;
446
448
447
449
// @ts -ignore see "Why @ts-ignore" note
448
- expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
450
+ expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
449
451
expectScopeSettings ( fakeTransactionContext ) ;
450
- expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
452
+ expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
451
453
// @ts -ignore see "Why @ts-ignore" note
452
- expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
453
- expect ( Sentry . flush ) . toBeCalled ( ) ;
454
+ expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
455
+ expect ( SentryNode . flush ) . toBeCalled ( ) ;
454
456
}
455
457
} ) ;
456
458
} ) ;
0 commit comments