|
1 | | -import * as coreSdk from '@sentry/core'; |
2 | | -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; |
3 | | - |
4 | 1 | import { wrapApiHandlerWithSentry } from '../../src/edge'; |
5 | 2 |
|
6 | 3 | const origRequest = global.Request; |
@@ -31,53 +28,16 @@ afterAll(() => { |
31 | 28 | global.Response = origResponse; |
32 | 29 | }); |
33 | 30 |
|
34 | | -const startSpanSpy = jest.spyOn(coreSdk, 'startSpan'); |
35 | | - |
36 | 31 | afterEach(() => { |
37 | 32 | jest.clearAllMocks(); |
38 | 33 | }); |
39 | 34 |
|
40 | 35 | describe('wrapApiHandlerWithSentry', () => { |
41 | | - it('should return a function that calls trace', async () => { |
42 | | - const request = new Request('https://sentry.io/'); |
43 | | - const origFunction = jest.fn(_req => new Response()); |
44 | | - |
45 | | - const wrappedFunction = wrapApiHandlerWithSentry(origFunction, '/user/[userId]/post/[postId]'); |
46 | | - |
47 | | - await wrappedFunction(request); |
48 | | - |
49 | | - expect(startSpanSpy).toHaveBeenCalledTimes(1); |
50 | | - expect(startSpanSpy).toHaveBeenCalledWith( |
51 | | - expect.objectContaining({ |
52 | | - attributes: { |
53 | | - [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', |
54 | | - [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping', |
55 | | - }, |
56 | | - name: 'POST /user/[userId]/post/[postId]', |
57 | | - op: 'http.server', |
58 | | - }), |
59 | | - expect.any(Function), |
60 | | - ); |
61 | | - }); |
62 | | - |
63 | | - it('should return a function that calls trace without throwing when no request is passed', async () => { |
| 36 | + it('should return a function that does not throw when no request is passed', async () => { |
64 | 37 | const origFunction = jest.fn(() => new Response()); |
65 | 38 |
|
66 | 39 | const wrappedFunction = wrapApiHandlerWithSentry(origFunction, '/user/[userId]/post/[postId]'); |
67 | 40 |
|
68 | 41 | await wrappedFunction(); |
69 | | - |
70 | | - expect(startSpanSpy).toHaveBeenCalledTimes(1); |
71 | | - expect(startSpanSpy).toHaveBeenCalledWith( |
72 | | - expect.objectContaining({ |
73 | | - attributes: { |
74 | | - [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', |
75 | | - [coreSdk.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping', |
76 | | - }, |
77 | | - name: 'handler (/user/[userId]/post/[postId])', |
78 | | - op: 'http.server', |
79 | | - }), |
80 | | - expect.any(Function), |
81 | | - ); |
82 | 42 | }); |
83 | 43 | }); |
0 commit comments