-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathroute-handler.test.ts
More file actions
39 lines (30 loc) · 1.96 KB
/
route-handler.test.ts
File metadata and controls
39 lines (30 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import test, { expect } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
test('Should create a transaction for node route handlers', async ({ request }) => {
const routehandlerTransactionPromise = waitForTransaction('nextjs-16', async transactionEvent => {
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/node';
});
const response = await request.get('/route-handler/123/node', { headers: { 'x-charly': 'gomez' } });
expect(await response.json()).toStrictEqual({ message: 'Hello Node Route Handler' });
const routehandlerTransaction = await routehandlerTransactionPromise;
expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok');
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
// This is flaking on dev mode
if (process.env.TEST_ENV !== 'development' && process.env.TEST_ENV !== 'dev-turbopack') {
expect(routehandlerTransaction.contexts?.trace?.data?.['http.request.header.x_charly']).toBe('gomez');
}
});
test('Should create a transaction for edge route handlers', async ({ request }) => {
// This test only works for webpack builds on non-async param extraction
// todo: check if we can set request headers for edge on sdkProcessingMetadata
test.skip();
const routehandlerTransactionPromise = waitForTransaction('nextjs-16', async transactionEvent => {
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/edge';
});
const response = await request.get('/route-handler/123/edge', { headers: { 'x-charly': 'gomez' } });
expect(await response.json()).toStrictEqual({ message: 'Hello Edge Route Handler' });
const routehandlerTransaction = await routehandlerTransactionPromise;
expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok');
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
expect(routehandlerTransaction.contexts?.trace?.data?.['http.request.header.x_charly']).toBe('gomez');
});