|
| 1 | +import { withSentry, AugmentedNextApiResponse } from '../../src/utils/withSentry'; |
| 2 | +import { NextApiHandler, NextApiRequest } from 'next'; |
| 3 | +import { Hub, makeMain } from '@sentry/hub'; |
| 4 | +import { NodeClient } from '@sentry/node'; |
| 5 | +import { logger } from '@sentry/utils'; |
| 6 | + |
| 7 | +const loggerSpy = jest.spyOn(logger, 'log'); |
| 8 | + |
| 9 | +describe('withSentry', async () => { |
| 10 | + it('flushes events before rethrowing error', async done => { |
| 11 | + const hub = new Hub( |
| 12 | + new NodeClient({ dsn: 'https://[email protected]/12312012' }), |
| 13 | + ); |
| 14 | + makeMain(hub); |
| 15 | + const apiHandler: NextApiHandler = async (_req: any, _res: any) => { |
| 16 | + throw new Error('Charlie ate the flip-flops. :-('); |
| 17 | + }; |
| 18 | + const req = { url: 'http://dogs.are.great' } as NextApiRequest; |
| 19 | + const res = ({ end: async () => undefined } as unknown) as AugmentedNextApiResponse; |
| 20 | + |
| 21 | + const wrappedHandler = withSentry(apiHandler); |
| 22 | + expect(async () => await wrappedHandler(req, res)).toThrow(); |
| 23 | + expect(loggerSpy).toHaveBeenCalledWith('Done flushing events'); |
| 24 | + done(); |
| 25 | + }); |
| 26 | + |
| 27 | + it("doesn't interfere with non-erroring responses", () => { |
| 28 | + // pass |
| 29 | + }); |
| 30 | + |
| 31 | + it('creates a transaction, puts it on the scope, and sends it to sentry', () => { |
| 32 | + // pass |
| 33 | + }); |
| 34 | + |
| 35 | + it('separates scopes between invocations', () => { |
| 36 | + // pass |
| 37 | + }); |
| 38 | + |
| 39 | + it('continues a trace given a `sentry-trace` header', () => { |
| 40 | + // pass |
| 41 | + }); |
| 42 | + |
| 43 | + it('parameterizes path', () => { |
| 44 | + // pass |
| 45 | + }); |
| 46 | +}); |
0 commit comments