-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c876577
add route handler tests for turbopack
chargome fafab8c
add test.fail
chargome e63d9b2
workaround for failing test
chargome 3727f46
nevermind
chargome a61478c
bump next version for turbo
chargome 13a3c45
Merge branch 'develop' into cg-add-route-handler-tests
chargome 93a2389
bump
chargome 1da522d
.
chargome 1caefb7
...
chargome 8ec4292
no url
chargome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...ckages/e2e-tests/test-applications/nextjs-turbo/app/route-handlers/[param]/error/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nextjs-turbo/app/route-handlers/[param]/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/nextjs-turbo/app/route-handlers/static/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...packages/e2e-tests/test-applications/nextjs-turbo/tests/app-router/route-handlers.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 }) => { | ||
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'); | ||
// todo: make sure url is attached to request object | ||
// expect(routehandlerError.request?.url).toContain('/route-handlers/boop/error'); | ||
|
||
expect(routehandlerError.transaction).toBe('/route-handlers/[param]/error'); | ||
}); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.