11import * as SentryNode from '@sentry/node' ;
2+ import type { Event } from '@sentry/types' ;
23import * as domain from 'domain' ;
34
45import * as Sentry from '../src' ;
@@ -12,7 +13,6 @@ import type {
1213 Request ,
1314 Response ,
1415} from '../src/gcpfunction/general' ;
15-
1616/**
1717 * Why @ts-ignore some Sentry.X calls
1818 *
@@ -198,7 +198,7 @@ describe('GCPFunction', () => {
198198 expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
199199 // @ts -ignore see "Why @ts-ignore" note
200200 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
201- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
201+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
202202 // @ts -ignore see "Why @ts-ignore" note
203203 expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
204204 expect ( SentryNode . flush ) . toBeCalled ( ) ;
@@ -317,7 +317,7 @@ describe('GCPFunction', () => {
317317 expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
318318 // @ts -ignore see "Why @ts-ignore" note
319319 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
320- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
320+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
321321 // @ts -ignore see "Why @ts-ignore" note
322322 expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
323323 expect ( SentryNode . flush ) . toBeCalled ( ) ;
@@ -382,7 +382,7 @@ describe('GCPFunction', () => {
382382 expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
383383 // @ts -ignore see "Why @ts-ignore" note
384384 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
385- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
385+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
386386 // @ts -ignore see "Why @ts-ignore" note
387387 expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
388388 expect ( SentryNode . flush ) . toBeCalled ( ) ;
@@ -440,7 +440,7 @@ describe('GCPFunction', () => {
440440 expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
441441 // @ts -ignore see "Why @ts-ignore" note
442442 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
443- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
443+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
444444 // @ts -ignore see "Why @ts-ignore" note
445445 expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
446446 expect ( SentryNode . flush ) . toBeCalled ( ) ;
@@ -469,7 +469,33 @@ describe('GCPFunction', () => {
469469 expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
470470 // @ts -ignore see "Why @ts-ignore" note
471471 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
472- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
472+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
473+ } ) ;
474+ } ) ;
475+
476+ test ( 'marks the captured error as unhandled' , async ( ) => {
477+ expect . assertions ( 4 ) ;
478+
479+ const error = new Error ( 'wat' ) ;
480+ const handler : EventFunctionWithCallback = ( _data , _context , _cb ) => {
481+ throw error ;
482+ } ;
483+ const wrappedHandler = wrapEventFunction ( handler ) ;
484+ await expect ( handleEvent ( wrappedHandler ) ) . rejects . toThrowError ( error ) ;
485+
486+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
487+
488+ // @ts -ignore just mocking around...
489+ const scopeFunction = SentryNode . captureException . mock . calls [ 0 ] [ 1 ] ;
490+ const event : Event = { exception : { values : [ { } ] } } ;
491+ let evtProcessor : ( ( e : Event ) => Event ) | undefined = undefined ;
492+ scopeFunction ( { addEventProcessor : jest . fn ( ) . mockImplementation ( proc => ( evtProcessor = proc ) ) } ) ;
493+
494+ expect ( evtProcessor ) . toBeInstanceOf ( Function ) ;
495+ // @ts -ignore just mocking around...
496+ expect ( evtProcessor ( event ) . exception . values [ 0 ] . mechanism ) . toEqual ( {
497+ handled : false ,
498+ type : 'generic' ,
473499 } ) ;
474500 } ) ;
475501
@@ -537,7 +563,7 @@ describe('GCPFunction', () => {
537563 expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
538564 // @ts -ignore see "Why @ts-ignore" note
539565 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
540- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
566+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
541567 // @ts -ignore see "Why @ts-ignore" note
542568 expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
543569 expect ( SentryNode . flush ) . toBeCalled ( ) ;
@@ -595,7 +621,7 @@ describe('GCPFunction', () => {
595621 expect ( SentryNode . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
596622 // @ts -ignore see "Why @ts-ignore" note
597623 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
598- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
624+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
599625 // @ts -ignore see "Why @ts-ignore" note
600626 expect ( SentryNode . fakeTransaction . finish ) . toBeCalled ( ) ;
601627 expect ( SentryNode . flush ) . toBeCalled ( ) ;
@@ -625,7 +651,7 @@ describe('GCPFunction', () => {
625651 // @ts -ignore see "Why @ts-ignore" note
626652 expect ( SentryNode . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
627653
628- expect ( SentryNode . captureException ) . toBeCalledWith ( error ) ;
654+ expect ( SentryNode . captureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
629655 } ) ;
630656 } ) ;
631657
0 commit comments