Skip to content
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

test: the nextjs internal errors should not be caught #67671

Merged
merged 7 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/e2e/on-request-error/basic/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { retry } from 'next-test-utils'
describe('on-request-error - basic', () => {
const { next } = nextTestSetup({
files: __dirname,
skipDeployment: true,
huozhi marked this conversation as resolved.
Show resolved Hide resolved
env: {
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>another</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { notFound } from 'next/navigation'

export function GET() {
notFound()
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { redirect } from 'next/navigation'

export function GET() {
redirect('/another')
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default async function Page() {
await fetch('https://example.vercel.sh')
return <p>dynamic page</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Component() {
return <p>Component</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use client'

import nextDynamic from 'next/dynamic'

const Component = nextDynamic(() => import('./component'))

export default function Page() {
return <Component />
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import { notFound } from 'next/navigation'

export default function Page() {
notFound()
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import { redirect } from 'next/navigation'

export default function Page() {
redirect('/another')
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default async function Page() {
await fetch('https://example.vercel.sh')
return <p>dynamic page</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { notFound } from 'next/navigation'

export default function Page() {
notFound()
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { redirect } from 'next/navigation'

export default function Page() {
redirect('/another')
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function onRequestError(err, request, context) {
console.log('[instrumentation]:error', err.message)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { nextTestSetup } from 'e2e-utils'

describe('on-request-error - skip-next-internal-error.test', () => {
huozhi marked this conversation as resolved.
Show resolved Hide resolved
const { next } = nextTestSetup({
files: __dirname,
skipDeployment: true,
env: {
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
},
})

async function assertNoNextjsInternalErrors(
pathname: string,
expectedStatus = 200
) {
const { status } = await next.fetch(pathname)
expect(status).toBe(expectedStatus)

const output = next.cliOutput
// No navigation errors
expect(output).not.toContain('NEXT_REDIRECT')
expect(output).not.toContain('NEXT_NOT_FOUND')
// No dynamic usage errors
expect(output).not.toContain('DYNAMIC_SERVER_USAGE')
// No react postpone errors
// TODO: cover PPR errors later
expect(output).not.toContain('react.postpone')
}

describe('app router render', () => {
// Server navigation errors
it('should not catch server component not-found errors', async () => {
await assertNoNextjsInternalErrors('/server/not-found', 404)
})

it('should not catch server component redirect errors', async () => {
await assertNoNextjsInternalErrors('/server/redirect')
})

// Client navigation errors
it('should not catch client component not-found errors', async () => {
await assertNoNextjsInternalErrors('/client/not-found', 404)
})

it('should not catch client component redirect errors', async () => {
await assertNoNextjsInternalErrors('/client/redirect')
})

// Dynamic usage
it('should not catch server component dynamic usage errors', async () => {
await assertNoNextjsInternalErrors('/client/dynamic-fetch')
})

it('should not catch client component dynamic usage errors', async () => {
await assertNoNextjsInternalErrors('/client/dynamic-fetch')
})

// No SSR
it('should not catch next dynamic no-ssr errors', async () => {
await assertNoNextjsInternalErrors('/client/no-ssr')
})
})

describe('app router API', () => {
// API routes navigation errors
it('should not catch server component not-found errors', async () => {
await assertNoNextjsInternalErrors('/app-route/not-found', 404)
})

it('should not catch server component redirect errors', async () => {
await assertNoNextjsInternalErrors('/app-route/redirect')
})
})
})
Loading