-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(nextjs): Add route handler tests for turbopack #17515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function GET(request: Request) { | ||
throw new Error('Dynamic route handler error'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function GET() { | ||
return NextResponse.json({ name: 'Beep' }); | ||
} | ||
|
||
export async function POST() { | ||
return NextResponse.json({ name: 'Boop' }, { status: 400 }); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function GET(request: Request) { | ||
return NextResponse.json({ name: 'Static' }); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
||
test('Should create a transaction for dynamic route handlers', async ({ request }) => { | ||
const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { | ||
return transactionEvent?.transaction === 'GET /route-handlers/[param]'; | ||
}); | ||
|
||
const response = await request.get('/route-handlers/foo'); | ||
expect(await response.json()).toStrictEqual({ name: 'Beep' }); | ||
|
||
const routehandlerTransaction = await routehandlerTransactionPromise; | ||
|
||
expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok'); | ||
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); | ||
}); | ||
|
||
test('Should create a transaction for static route handlers', async ({ request }) => { | ||
const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { | ||
return transactionEvent?.transaction === 'GET /route-handlers/static'; | ||
}); | ||
|
||
const response = await request.get('/route-handlers/static'); | ||
expect(await response.json()).toStrictEqual({ name: 'Static' }); | ||
|
||
const routehandlerTransaction = await routehandlerTransactionPromise; | ||
|
||
expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok'); | ||
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); | ||
}); | ||
|
||
test('Should create a transaction for route handlers and correctly set span status depending on http status', async ({ | ||
request, | ||
}) => { | ||
const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { | ||
return transactionEvent?.transaction === 'POST /route-handlers/[param]'; | ||
}); | ||
|
||
const response = await request.post('/route-handlers/bar'); | ||
expect(await response.json()).toStrictEqual({ name: 'Boop' }); | ||
|
||
const routehandlerTransaction = await routehandlerTransactionPromise; | ||
|
||
expect(routehandlerTransaction.contexts?.trace?.status).toBe('invalid_argument'); | ||
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); | ||
}); | ||
|
||
test('Should record exceptions and transactions for faulty route handlers', async ({ request }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test.fail seems to not work with test timeouts – I added a workaround so the test fails once the issue is resolved upstream There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, this is already fixed in canary. leaving as is |
||
const errorEventPromise = waitForError('nextjs-turbo', errorEvent => { | ||
return errorEvent?.exception?.values?.[0]?.value === 'Dynamic route handler error'; | ||
}); | ||
|
||
const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { | ||
return transactionEvent?.transaction === 'GET /route-handlers/[param]/error'; | ||
}); | ||
|
||
await request.get('/route-handlers/boop/error').catch(() => {}); | ||
|
||
const routehandlerTransaction = await routehandlerTransactionPromise; | ||
const routehandlerError = await errorEventPromise; | ||
|
||
expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error'); | ||
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); | ||
expect(routehandlerTransaction.contexts?.trace?.origin).toContain('auto'); | ||
|
||
expect(routehandlerError.exception?.values?.[0].value).toBe('Dynamic route handler error'); | ||
|
||
expect(routehandlerError.request?.method).toBe('GET'); | ||
expect(routehandlerError.request?.url).toContain('/route-handlers/boop/error'); | ||
|
||
expect(routehandlerError.transaction).toBe('GET /route-handlers/[param]/error'); | ||
}); | ||
chargome marked this conversation as resolved.
Show resolved
Hide resolved
|