@@ -51,17 +51,11 @@ describe('AWSLambda', () => {
5151 test ( 'flushTimeout' , async ( ) => {
5252 expect . assertions ( 1 ) ;
5353
54- const error = new Error ( 'wat' ) ;
55- const handler = ( ) => {
56- throw error ;
57- } ;
54+ const handler = ( ) => { } ;
5855 const wrappedHandler = wrapHandler ( handler , { flushTimeout : 1337 } ) ;
5956
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 ) ;
6559 } ) ;
6660
6761 test ( 'rethrowAfterCapture' , async ( ) => {
@@ -146,18 +140,24 @@ describe('AWSLambda', () => {
146140
147141 describe ( 'wrapHandler() on sync handler' , ( ) => {
148142 test ( 'successful execution' , async ( ) => {
149- expect . assertions ( 1 ) ;
143+ expect . assertions ( 5 ) ;
150144
151145 const handler : Handler = ( _event , _context , callback ) => {
152146 callback ( null , 42 ) ;
153147 } ;
154148 const wrappedHandler = wrapHandler ( handler ) ;
155149 const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
156150 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 ) ;
157157 } ) ;
158158
159159 test ( 'unsuccessful execution' , async ( ) => {
160- expect . assertions ( 2 ) ;
160+ expect . assertions ( 5 ) ;
161161
162162 const error = new Error ( 'sorry' ) ;
163163 const handler : Handler = ( _event , _context , callback ) => {
@@ -168,7 +168,12 @@ describe('AWSLambda', () => {
168168 try {
169169 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
170170 } 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 ) ;
171174 expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
175+ // @ts -ignore see "Why @ts-ignore" note
176+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
172177 expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
173178 }
174179 } ) ;
@@ -186,7 +191,7 @@ describe('AWSLambda', () => {
186191 } ) ;
187192
188193 test ( 'capture error' , async ( ) => {
189- expect . assertions ( 2 ) ;
194+ expect . assertions ( 5 ) ;
190195
191196 const error = new Error ( 'wat' ) ;
192197 const handler : Handler = ( _event , _context , _callback ) => {
@@ -197,22 +202,33 @@ describe('AWSLambda', () => {
197202 try {
198203 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
199204 } 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 ( ) ;
201211 expect ( Sentry . flush ) . toBeCalled ( ) ;
202212 }
203213 } ) ;
204214 } ) ;
205215
206216 describe ( 'wrapHandler() on async handler' , ( ) => {
207217 test ( 'successful execution' , async ( ) => {
208- expect . assertions ( 1 ) ;
218+ expect . assertions ( 5 ) ;
209219
210220 const handler : Handler = async ( _event , _context ) => {
211221 return 42 ;
212222 } ;
213223 const wrappedHandler = wrapHandler ( handler ) ;
214224 const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
215225 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 ( ) ;
216232 } ) ;
217233
218234 test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -227,7 +243,7 @@ describe('AWSLambda', () => {
227243 } ) ;
228244
229245 test ( 'capture error' , async ( ) => {
230- expect . assertions ( 2 ) ;
246+ expect . assertions ( 5 ) ;
231247
232248 const error = new Error ( 'wat' ) ;
233249 const handler : Handler = async ( _event , _context ) => {
@@ -238,22 +254,33 @@ describe('AWSLambda', () => {
238254 try {
239255 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
240256 } 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 ( ) ;
242263 expect ( Sentry . flush ) . toBeCalled ( ) ;
243264 }
244265 } ) ;
245266 } ) ;
246267
247268 describe ( 'wrapHandler() on async handler with a callback method (aka incorrect usage)' , ( ) => {
248269 test ( 'successful execution' , async ( ) => {
249- expect . assertions ( 1 ) ;
270+ expect . assertions ( 5 ) ;
250271
251272 const handler : Handler = async ( _event , _context , _callback ) => {
252273 return 42 ;
253274 } ;
254275 const wrappedHandler = wrapHandler ( handler ) ;
255276 const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
256277 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 ( ) ;
257284 } ) ;
258285
259286 test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -268,7 +295,7 @@ describe('AWSLambda', () => {
268295 } ) ;
269296
270297 test ( 'capture error' , async ( ) => {
271- expect . assertions ( 2 ) ;
298+ expect . assertions ( 5 ) ;
272299
273300 const error = new Error ( 'wat' ) ;
274301 const handler : Handler = async ( _event , _context , _callback ) => {
@@ -279,7 +306,12 @@ describe('AWSLambda', () => {
279306 try {
280307 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
281308 } 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 ( ) ;
283315 expect ( Sentry . flush ) . toBeCalled ( ) ;
284316 }
285317 } ) ;
0 commit comments