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

Add test for next-found and redirect for metadata #46248

Merged
merged 4 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions test/e2e/app-dir/metadata/app/async/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export async function generateMetadata() {
keywords: 'parent',
}
}

export const revalidate = 0
2 changes: 1 addition & 1 deletion test/e2e/app-dir/metadata/app/async/not-found/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { notFound } from 'next/navigation'

export default function page() {
return 'not found'
return 'not-found-text'
}

export async function generateMetadata() {
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/app-dir/metadata/app/async/redirect/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { redirect } from 'next/navigation'

export default function page() {
return 'redirect to basic'
}

export async function generateMetadata() {
redirect('/basic')
}
11 changes: 11 additions & 0 deletions test/e2e/app-dir/metadata/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ createNextDescribe(
)
})

it('should support notFound and redirect in generateMetadata', async () => {
const resNotFound = await next.fetch('/async/not-found')
expect(resNotFound.status).toBe(404)
const notFoundHtml = await resNotFound.text()
expect(notFoundHtml).not.toBe('not-found-text')
expect(notFoundHtml).toContain('This page could not be found.')

const resRedirect = await next.fetch('/async/redirect')
expect(resRedirect.status).toBe(307)
})

if (isNextDev) {
it('should freeze parent resolved metadata to avoid mutating in generateMetadata', async () => {
const pagePath = 'app/mutate/page.tsx'
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/navigation/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const revalidate = 0
export const dynamic = 'force-dynamic'

export default function Layout({ children }) {
return (
Expand Down