File tree 2 files changed +43
-0
lines changed
2 files changed +43
-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,34 @@ 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
+ expect . assertions ( 2 ) ;
154
+
155
+ const handler : HttpFunction = async ( _req , res ) => {
156
+ res . statusCode = 200 ;
157
+ res . end ( ) ;
158
+ } ;
159
+
160
+ const wrappedHandler = wrapHttpFunction ( handler ) ;
161
+
162
+ const request = {
163
+ method : 'POST' ,
164
+ url : '/path?q=query' ,
165
+ headers : { host : 'hostname' , 'content-type' : 'application/json' } ,
166
+ body : { foo : 'bar' } ,
167
+ } as Request ;
168
+
169
+ const mockEnd = jest . fn ( ) ;
170
+ const response = { end : mockEnd } as unknown as Response ;
171
+
172
+ jest . spyOn ( Sentry , 'flush' ) . mockImplementationOnce ( async ( ) => {
173
+ throw new Error ( ) ;
174
+ } ) ;
175
+
176
+ await expect ( wrappedHandler ( request , response ) ) . resolves . toBeUndefined ( ) ;
177
+ expect ( mockEnd ) . toHaveBeenCalledTimes ( 1 ) ;
178
+ } ) ;
151
179
} ) ;
152
180
153
181
test ( 'wrapHttpFunction request data' , async ( ) => {
You can’t perform that action at this time.
0 commit comments