-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: the nextjs internal errors should not be caught (#67671)
### What Cover the Next.js internal errors are not captured by instrumentation onRequestError API Also skip deployment tests for onRequestError API due to the private env flag `__NEXT_EXPERIMENTAL_INSTRUMENTATION` cannot be used in deployment <!-- Closes NDX-33 -->
- Loading branch information
Showing
16 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
3 changes: 3 additions & 0 deletions
3
test/e2e/on-request-error/skip-next-internal-error/app/another/page.js
This file contains 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 default function Page() { | ||
return <p>another</p> | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/on-request-error/skip-next-internal-error/app/app-route/not-found/route.js
This file contains 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,7 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export function GET() { | ||
notFound() | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
7 changes: 7 additions & 0 deletions
7
test/e2e/on-request-error/skip-next-internal-error/app/app-route/redirect/route.js
This file contains 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,7 @@ | ||
import { redirect } from 'next/navigation' | ||
|
||
export function GET() { | ||
redirect('/another') | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
4 changes: 4 additions & 0 deletions
4
test/e2e/on-request-error/skip-next-internal-error/app/client/dynamic-fetch/page.js
This file contains 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,4 @@ | ||
export default async function Page() { | ||
await fetch('https://example.vercel.sh') | ||
return <p>dynamic page</p> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/on-request-error/skip-next-internal-error/app/client/no-ssr/component.js
This file contains 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 default function Component() { | ||
return <p>Component</p> | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/on-request-error/skip-next-internal-error/app/client/no-ssr/page.js
This file contains 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,11 @@ | ||
'use client' | ||
|
||
import nextDynamic from 'next/dynamic' | ||
|
||
const Component = nextDynamic(() => import('./component')) | ||
|
||
export default function Page() { | ||
return <Component /> | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
9 changes: 9 additions & 0 deletions
9
test/e2e/on-request-error/skip-next-internal-error/app/client/not-found/page.js
This file contains 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 @@ | ||
'use client' | ||
|
||
import { notFound } from 'next/navigation' | ||
|
||
export default function Page() { | ||
notFound() | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
9 changes: 9 additions & 0 deletions
9
test/e2e/on-request-error/skip-next-internal-error/app/client/redirect/page.js
This file contains 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 @@ | ||
'use client' | ||
|
||
import { redirect } from 'next/navigation' | ||
|
||
export default function Page() { | ||
redirect('/another') | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
9 changes: 9 additions & 0 deletions
9
test/e2e/on-request-error/skip-next-internal-error/app/layout.js
This file contains 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 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
4 changes: 4 additions & 0 deletions
4
test/e2e/on-request-error/skip-next-internal-error/app/server/dynamic-fetch/page.js
This file contains 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,4 @@ | ||
export default async function Page() { | ||
await fetch('https://example.vercel.sh') | ||
return <p>dynamic page</p> | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/on-request-error/skip-next-internal-error/app/server/not-found/page.js
This file contains 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,7 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export default function Page() { | ||
notFound() | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
7 changes: 7 additions & 0 deletions
7
test/e2e/on-request-error/skip-next-internal-error/app/server/redirect/page.js
This file contains 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,7 @@ | ||
import { redirect } from 'next/navigation' | ||
|
||
export default function Page() { | ||
redirect('/another') | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
3 changes: 3 additions & 0 deletions
3
test/e2e/on-request-error/skip-next-internal-error/instrumentation.js
This file contains 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 function onRequestError(err, request, context) { | ||
console.log('[instrumentation]:error', err.message) | ||
} |
5 changes: 5 additions & 0 deletions
5
test/e2e/on-request-error/skip-next-internal-error/next.config.js
This file contains 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 @@ | ||
module.exports = { | ||
experimental: { | ||
instrumentationHook: true, | ||
}, | ||
} |
82 changes: 82 additions & 0 deletions
82
test/e2e/on-request-error/skip-next-internal-error/skip-next-internal-error.test.ts
This file contains 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,82 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('on-request-error - skip-next-internal-error', () => { | ||
const { next, skipped } = nextTestSetup({ | ||
files: __dirname, | ||
skipDeployment: true, | ||
env: { | ||
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1', | ||
}, | ||
}) | ||
|
||
if (skipped) { | ||
return | ||
} | ||
|
||
async function assertNoNextjsInternalErrors() { | ||
const output = next.cliOutput | ||
// No navigation errors | ||
expect(output).not.toContain('NEXT_REDIRECT') | ||
expect(output).not.toContain('NEXT_NOT_FOUND') | ||
expect(output).not.toContain('BAILOUT_TO_CLIENT_SIDE_RENDERING') | ||
// 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 next.fetch('/server/not-found') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
|
||
it('should not catch server component redirect errors', async () => { | ||
await next.render('/server/redirect') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
|
||
// Client navigation errors | ||
it('should not catch client component not-found errors', async () => { | ||
await next.fetch('/server/not-found') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
|
||
it('should not catch client component redirect errors', async () => { | ||
await next.render('/client/redirect') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
|
||
// Dynamic usage | ||
it('should not catch server component dynamic usage errors', async () => { | ||
await next.fetch('/server/dynamic-fetch') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
|
||
it('should not catch client component dynamic usage errors', async () => { | ||
await next.fetch('/client/dynamic-fetch') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
|
||
// No SSR | ||
it('should not catch next dynamic no-ssr errors', async () => { | ||
await next.fetch('/client/no-ssr') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
}) | ||
|
||
describe('app router API', () => { | ||
// API routes navigation errors | ||
it('should not catch server component not-found errors', async () => { | ||
await next.render('/app-route/not-found') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
|
||
it('should not catch server component redirect errors', async () => { | ||
await next.render('/app-route/redirect') | ||
await assertNoNextjsInternalErrors() | ||
}) | ||
}) | ||
}) |