Skip to content

Commit 7caf12b

Browse files
committed
Add tests
1 parent 28fb0a2 commit 7caf12b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/serverless/test/awslambda.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,21 @@ describe('AWSLambda', () => {
306306
expect(Sentry.flush).toBeCalled();
307307
}
308308
});
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+
});
309324
});
310325

311326
describe('wrapHandler() on async handler with a callback method (aka incorrect usage)', () => {

packages/serverless/test/gcpfunction.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ describe('GCPFunction', () => {
148148
expect(Sentry.fakeTransaction.finish).toBeCalled();
149149
expect(Sentry.flush).toBeCalled();
150150
});
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+
});
151179
});
152180

153181
test('wrapHttpFunction request data', async () => {

0 commit comments

Comments
 (0)