@@ -84,6 +84,59 @@ describe('wrapCloudEventFunction', () => {
8484 expect ( mockFlush ) . toBeCalledWith ( 2000 ) ;
8585 } ) ;
8686
87+ describe ( 'wrapEventFunction() as Promise' , ( ) => {
88+ test ( 'successful execution' , async ( ) => {
89+ const func : CloudEventFunction = _context =>
90+ new Promise ( resolve => {
91+ setTimeout ( ( ) => {
92+ resolve ( 42 ) ;
93+ } , 10 ) ;
94+ } ) ;
95+ const wrappedHandler = wrapCloudEventFunction ( func ) ;
96+ await expect ( handleCloudEvent ( wrappedHandler ) ) . resolves . toBe ( 42 ) ;
97+
98+ const fakeTransactionContext = {
99+ name : 'event.type' ,
100+ op : 'function.gcp.cloud_event' ,
101+ attributes : {
102+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'component' ,
103+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.serverless.gcp_cloud_event' ,
104+ } ,
105+ } ;
106+
107+ expect ( mockStartSpanManual ) . toBeCalledWith ( fakeTransactionContext , expect . any ( Function ) ) ;
108+ expect ( mockSpan . end ) . toBeCalled ( ) ;
109+ expect ( mockFlush ) . toBeCalledWith ( 2000 ) ;
110+ } ) ;
111+
112+ test ( 'capture error' , async ( ) => {
113+ const error = new Error ( 'wat' ) ;
114+ const handler : CloudEventFunction = _context =>
115+ new Promise ( ( _ , reject ) => {
116+ setTimeout ( ( ) => {
117+ reject ( error ) ;
118+ } , 10 ) ;
119+ } ) ;
120+
121+ const wrappedHandler = wrapCloudEventFunction ( handler ) ;
122+ await expect ( handleCloudEvent ( wrappedHandler ) ) . rejects . toThrowError ( error ) ;
123+
124+ const fakeTransactionContext = {
125+ name : 'event.type' ,
126+ op : 'function.gcp.cloud_event' ,
127+ attributes : {
128+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'component' ,
129+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.serverless.gcp_cloud_event' ,
130+ } ,
131+ } ;
132+
133+ expect ( mockStartSpanManual ) . toBeCalledWith ( fakeTransactionContext , expect . any ( Function ) ) ;
134+ expect ( mockCaptureException ) . toBeCalledWith ( error , expect . any ( Function ) ) ;
135+ expect ( mockSpan . end ) . toBeCalled ( ) ;
136+ expect ( mockFlush ) . toBeCalled ( ) ;
137+ } ) ;
138+ } ) ;
139+
87140 test ( 'capture error' , async ( ) => {
88141 const error = new Error ( 'wat' ) ;
89142 const handler : CloudEventFunction = _context => {
0 commit comments