File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,21 @@ describe('AWSLambda', () => {
306
306
expect ( Sentry . flush ) . toBeCalled ( ) ;
307
307
}
308
308
} ) ;
309
+
310
+ test ( 'should not throw when flush rejects' , async ( ) => {
311
+ const handler : Handler = async ( ) => {
312
+ // Friendly handler with no errors :)
313
+ return 'some string' ;
314
+ } ;
315
+
316
+ const wrappedHandler = wrapHandler ( handler ) ;
317
+
318
+ jest . spyOn ( Sentry , 'flush' ) . mockImplementationOnce ( async ( ) => {
319
+ throw new Error ( ) ;
320
+ } ) ;
321
+
322
+ await expect ( wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ) . resolves . toBe ( 'some string' ) ;
323
+ } ) ;
309
324
} ) ;
310
325
311
326
describe ( 'wrapHandler() on async handler with a callback method (aka incorrect usage)' , ( ) => {
Original file line number Diff line number Diff line change @@ -148,6 +148,30 @@ describe('GCPFunction', () => {
148
148
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
149
149
expect ( Sentry . flush ) . toBeCalled ( ) ;
150
150
} ) ;
151
+
152
+ test ( 'should not throw when flush rejects' , async ( ) => {
153
+ const handler : HttpFunction = async ( _req , res ) => {
154
+ res . statusCode = 200 ;
155
+ res . end ( ) ;
156
+ } ;
157
+
158
+ const wrappedHandler = wrapHttpFunction ( handler ) ;
159
+
160
+ const request = {
161
+ method : 'POST' ,
162
+ url : '/path?q=query' ,
163
+ headers : { host : 'hostname' , 'content-type' : 'application/json' } ,
164
+ body : { foo : 'bar' } ,
165
+ } as Request ;
166
+
167
+ const response = { end : ( ) => undefined } as Response ;
168
+
169
+ jest . spyOn ( Sentry , 'flush' ) . mockImplementationOnce ( async ( ) => {
170
+ throw new Error ( ) ;
171
+ } ) ;
172
+
173
+ await expect ( wrappedHandler ( request , response ) ) . resolves . toBeUndefined ( ) ;
174
+ } ) ;
151
175
} ) ;
152
176
153
177
test ( 'wrapHttpFunction request data' , async ( ) => {
You can’t perform that action at this time.
0 commit comments