Skip to content

Commit ab88d96

Browse files
authored
test(e2e): Migrate test app nextjs-turbo into nextjs-15 (#19107)
- Migrates pages router and route handler tests from `nextjs-turbo` to `nextjs-15` - Removes the redundant `nextjs-turbo` test app - All tests are now covered in `nextjs-15` with turbopack variant
1 parent c104764 commit ab88d96

36 files changed

+74
-659
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function GET() {
2+
throw new Error('Route handler error');
3+
}

dev-packages/e2e-tests/test-applications/nextjs-15/app/route-handler/[xoxo]/node/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ export const dynamic = 'force-dynamic';
55
export async function GET() {
66
return NextResponse.json({ message: 'Hello Node Route Handler' });
77
}
8+
9+
export async function POST() {
10+
return NextResponse.json({ name: 'Boop' }, { status: 400 });
11+
}

dev-packages/e2e-tests/test-applications/nextjs-turbo/app/route-handlers/static/route.ts renamed to dev-packages/e2e-tests/test-applications/nextjs-15/app/route-handler/static/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NextResponse } from 'next/server';
22

3-
export async function GET(request: Request) {
3+
export async function GET() {
44
return NextResponse.json({ name: 'Static' });
55
}

dev-packages/e2e-tests/test-applications/nextjs-15/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ const nextConfig = {};
55

66
module.exports = withSentryConfig(nextConfig, {
77
silent: true,
8+
release: {
9+
name: 'foobar123',
10+
},
811
});

dev-packages/e2e-tests/test-applications/nextjs-turbo/pages/[param]/pages-router-client-trace-propagation.tsx renamed to dev-packages/e2e-tests/test-applications/nextjs-15/pages/[locale]/pages-router-client-trace-propagation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default function Page() {
2-
<p>Hello World!</p>;
2+
return <p>Hello World!</p>;
33
}
44

55
// getServerSideProps makes this page dynamic and allows tracing data to be inserted

dev-packages/e2e-tests/test-applications/nextjs-turbo/pages/_app.tsx renamed to dev-packages/e2e-tests/test-applications/nextjs-15/pages/_app.tsx

File renamed without changes.

dev-packages/e2e-tests/test-applications/nextjs-turbo/tests/pages-router/client-trace-propagation.test.ts renamed to dev-packages/e2e-tests/test-applications/nextjs-15/tests/client-trace-propagation.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ import { expect, test } from '@playwright/test';
22
import { waitForTransaction } from '@sentry-internal/test-utils';
33
import { parseSemver } from '@sentry/core';
44

5-
const packageJson = require('../../package.json');
5+
const packageJson = require('../package.json');
66
const nextjsVersion = packageJson.dependencies.next;
77
const { major, minor } = parseSemver(nextjsVersion);
88

99
test('Should propagate traces from server to client in pages router', async ({ page }) => {
10-
// TODO: Remove this skippage when Next.js 15.3.0 is released and bump version in package json to 15.3.0
1110
test.skip(
1211
major === 15 && minor !== undefined && minor < 3,
1312
'Next.js version does not support clientside instrumentation',
1413
);
1514

16-
const serverTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => {
17-
return transactionEvent?.transaction === 'GET /[param]/pages-router-client-trace-propagation';
15+
const serverTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
16+
return transactionEvent?.transaction === 'GET /[locale]/pages-router-client-trace-propagation';
1817
});
1918

20-
const pageloadTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => {
21-
return transactionEvent?.transaction === '/[param]/pages-router-client-trace-propagation';
19+
const pageloadTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
20+
return transactionEvent?.transaction === '/[locale]/pages-router-client-trace-propagation';
2221
});
2322

2423
await page.goto(`/123/pages-router-client-trace-propagation`);

dev-packages/e2e-tests/test-applications/nextjs-15/tests/route-handler.test.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test, { expect } from '@playwright/test';
2-
import { waitForTransaction } from '@sentry-internal/test-utils';
2+
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
33

44
test('Should create a transaction for node route handlers', async ({ request }) => {
55
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
@@ -37,3 +37,59 @@ test('Should create a transaction for edge route handlers', async ({ request })
3737
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
3838
expect(routehandlerTransaction.contexts?.trace?.data?.['http.request.header.x_charly']).toBe('gomez');
3939
});
40+
41+
test('Should create a transaction for static route handlers', async ({ request }) => {
42+
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
43+
return transactionEvent?.transaction === 'GET /route-handler/static';
44+
});
45+
46+
const response = await request.get('/route-handler/static');
47+
expect(await response.json()).toStrictEqual({ name: 'Static' });
48+
49+
const routehandlerTransaction = await routehandlerTransactionPromise;
50+
51+
expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok');
52+
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
53+
});
54+
55+
test('Should create a transaction for route handlers and correctly set span status depending on http status', async ({
56+
request,
57+
}) => {
58+
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
59+
return transactionEvent?.transaction === 'POST /route-handler/[xoxo]/node';
60+
});
61+
62+
const response = await request.post('/route-handler/123/node');
63+
expect(await response.json()).toStrictEqual({ name: 'Boop' });
64+
65+
const routehandlerTransaction = await routehandlerTransactionPromise;
66+
67+
expect(routehandlerTransaction.contexts?.trace?.status).toBe('invalid_argument');
68+
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
69+
});
70+
71+
test('Should record exceptions and transactions for faulty route handlers', async ({ request }) => {
72+
const errorEventPromise = waitForError('nextjs-15', errorEvent => {
73+
return errorEvent?.exception?.values?.[0]?.value === 'Route handler error';
74+
});
75+
76+
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
77+
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/error';
78+
});
79+
80+
await request.get('/route-handler/123/error').catch(() => {});
81+
82+
const routehandlerTransaction = await routehandlerTransactionPromise;
83+
const routehandlerError = await errorEventPromise;
84+
85+
expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error');
86+
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
87+
expect(routehandlerTransaction.contexts?.trace?.origin).toContain('auto');
88+
89+
expect(routehandlerError.exception?.values?.[0].value).toBe('Route handler error');
90+
91+
expect(routehandlerError.request?.method).toBe('GET');
92+
expect(routehandlerError.request?.url).toContain('/route-handler/123/error');
93+
94+
expect(routehandlerError.transaction).toContain('/route-handler/[xoxo]/error');
95+
});

dev-packages/e2e-tests/test-applications/nextjs-turbo/.gitignore

Lines changed: 0 additions & 46 deletions
This file was deleted.

dev-packages/e2e-tests/test-applications/nextjs-turbo/.npmrc

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)