Unverified Commit df774690 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Use new Redbox matchers in server-navigation-error (#76787)

parent ab00c876
import { nextTestSetup } from 'e2e-utils'
import {
assertHasRedbox,
getRedboxDescription,
getRedboxSource,
} from 'next-test-utils'
describe('server-navigation-error', () => {
const { isTurbopack, next } = nextTestSetup({
......@@ -13,64 +8,74 @@ describe('server-navigation-error', () => {
describe('pages router', () => {
it('should error on navigation API redirect', async () => {
const browser = await next.browser('/pages/redirect')
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatch(
`Next.js navigation API is not allowed to be used in Pages Router.`
)
const source = await getRedboxSource(browser)
if (isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"pages/pages/redirect.tsx (4:10) @ Page
2 |
3 | export default function Page() {
> 4 | redirect('/')
| ^
5 | }
6 |"
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/redirect.tsx (4:10) @ Page
> 4 | redirect('/')
| ^",
"stack": [
"Page pages/pages/redirect.tsx (4:10)",
],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"pages/pages/redirect.tsx (4:11) @ Page
2 |
3 | export default function Page() {
> 4 | redirect('/')
| ^
5 | }
6 |"
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/redirect.tsx (4:11) @ Page
> 4 | redirect('/')
| ^",
"stack": [
"Page pages/pages/redirect.tsx (4:11)",
],
}
`)
}
})
it('should error on navigation API notFound', async () => {
const browser = await next.browser('/pages/not-found')
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatch(
`Next.js navigation API is not allowed to be used in Pages Router.`
)
const source = await getRedboxSource(browser)
if (isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"pages/pages/not-found.tsx (4:10) @ Page
2 |
3 | export default function Page() {
> 4 | notFound()
| ^
5 | }
6 |"
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/not-found.tsx (4:10) @ Page
> 4 | notFound()
| ^",
"stack": [
"Page pages/pages/not-found.tsx (4:10)",
],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"pages/pages/not-found.tsx (4:11) @ Page
2 |
3 | export default function Page() {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/not-found.tsx (4:11) @ Page
> 4 | notFound()
| ^
5 | }
6 |"
| ^",
"stack": [
"Page pages/pages/not-found.tsx (4:11)",
],
}
`)
}
})
......@@ -81,69 +86,74 @@ describe('server-navigation-error', () => {
const browser = await next.browser('/middleware/redirect')
// FIXME: the first request to middleware error load didn't show the redbox, need one more reload
await browser.refresh()
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatch(
`Next.js navigation API is not allowed to be used in Middleware.`
)
const source = await getRedboxSource(browser)
if (isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"middleware.ts (8:12) @ middleware
6 | notFound()
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
> 8 | redirect('/')
| ^
9 | }
10 | }
11 |"
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (8:12) @ middleware
> 8 | redirect('/')
| ^",
"stack": [
"middleware middleware.ts (8:12)",
],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"middleware.ts (8:13) @ middleware
6 | notFound()
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
> 8 | redirect('/')
| ^
9 | }
10 | }
11 |"
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (8:13) @ middleware
> 8 | redirect('/')
| ^",
"stack": [
"middleware middleware.ts (8:13)",
],
}
`)
}
})
it('should error on navigation API not-found', async () => {
const browser = await next.browser('/middleware/not-found')
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatch(
`Next.js navigation API is not allowed to be used in Middleware.`
)
const source = await getRedboxSource(browser)
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if (isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"middleware.ts (6:12) @ middleware
4 | export default function middleware(req: NextRequest) {
5 | if (req.nextUrl.pathname === '/middleware/not-found') {
> 6 | notFound()
| ^
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
8 | redirect('/')
9 | }"
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (6:12) @ middleware
> 6 | notFound()
| ^",
"stack": [
"middleware middleware.ts (6:12)",
],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"middleware.ts (6:13) @ middleware
4 | export default function middleware(req: NextRequest) {
5 | if (req.nextUrl.pathname === '/middleware/not-found') {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (6:13) @ middleware
> 6 | notFound()
| ^
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
8 | redirect('/')
9 | }"
| ^",
"stack": [
"middleware middleware.ts (6:13)",
],
}
`)
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment