@@ -472,6 +472,59 @@ describe('GCPFunction', () => {
472
472
expect ( mockFlush ) . toBeCalledWith ( 2000 ) ;
473
473
} ) ;
474
474
475
+ describe ( 'wrapEventFunction() as Promise' , ( ) => {
476
+ test ( 'successful execution' , async ( ) => {
477
+ const func : CloudEventFunction = _context =>
478
+ new Promise ( resolve => {
479
+ setTimeout ( ( ) => {
480
+ resolve ( 42 ) ;
481
+ } , 10 ) ;
482
+ } ) ;
483
+ const wrappedHandler = wrapCloudEventFunction ( func ) ;
484
+ await expect ( handleCloudEvent ( wrappedHandler ) ) . resolves . toBe ( 42 ) ;
485
+
486
+ const fakeTransactionContext = {
487
+ name : 'event.type' ,
488
+ op : 'function.gcp.cloud_event' ,
489
+ attributes : {
490
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'component' ,
491
+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.serverless.gcp_cloud_event' ,
492
+ } ,
493
+ } ;
494
+
495
+ expect ( mockStartSpanManual ) . toBeCalledWith ( fakeTransactionContext , expect . any ( Function ) ) ;
496
+ expect ( mockSpan . end ) . toBeCalled ( ) ;
497
+ expect ( mockFlush ) . toBeCalledWith ( 2000 ) ;
498
+ } ) ;
499
+
500
+ test ( 'capture error' , async ( ) => {
501
+ const error = new Error ( 'wat' ) ;
502
+ const handler : CloudEventFunction = _context =>
503
+ new Promise ( ( _ , reject ) => {
504
+ setTimeout ( ( ) => {
505
+ reject ( error ) ;
506
+ } , 10 ) ;
507
+ } ) ;
508
+
509
+ const wrappedHandler = wrapCloudEventFunction ( handler ) ;
510
+ await expect ( handleCloudEvent ( wrappedHandler ) ) . rejects . toThrowError ( error ) ;
511
+
512
+ const fakeTransactionContext = {
513
+ name : 'event.type' ,
514
+ op : 'function.gcp.cloud_event' ,
515
+ attributes : {
516
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'component' ,
517
+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.serverless.gcp_cloud_event' ,
518
+ } ,
519
+ } ;
520
+
521
+ expect ( mockStartSpanManual ) . toBeCalledWith ( fakeTransactionContext , expect . any ( Function ) ) ;
522
+ expect ( mockCaptureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
523
+ expect ( mockSpan . end ) . toBeCalled ( ) ;
524
+ expect ( mockFlush ) . toBeCalled ( ) ;
525
+ } ) ;
526
+ } ) ;
527
+
475
528
test ( 'capture error' , async ( ) => {
476
529
const error = new Error ( 'wat' ) ;
477
530
const handler : CloudEventFunction = _context => {
0 commit comments