forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: break down metadata test suite into smaller ones (vercel#67018)
### What app-dir `metadata.test.ts` is pretty big and includes a lot of erroring tests and navigation tests. Breaking them into smaller suites to avoid the erroring on effect on others. - metadata - metadata-navigation - metadata-thrown Moved the metadata testing utils into `next-test-utils` for sharing purpose. Moved the hmr test to the bottom to avoid flakyness.
- Loading branch information
Showing
15 changed files
with
317 additions
and
246 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,14 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<head></head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} | ||
|
||
export const metadata = { | ||
title: 'this is the layout title', | ||
description: 'this is the layout description', | ||
keywords: ['nextjs', 'react'], | ||
} |
File renamed without changes.
76 changes: 76 additions & 0 deletions
76
test/e2e/app-dir/metadata-navigation/metadata-navigation.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,76 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { | ||
createMultiDomMatcher, | ||
createMultiHtmlMatcher, | ||
getTitle, | ||
} from 'next-test-utils' | ||
|
||
describe('app dir - metadata navigation', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
describe('navigation', () => { | ||
it('should render root not-found with default metadata', async () => { | ||
const $ = await next.render$('/does-not-exist') | ||
|
||
// Should contain default metadata and noindex tag | ||
const matchHtml = createMultiHtmlMatcher($) | ||
expect($('meta[charset="utf-8"]').length).toBe(1) | ||
matchHtml('meta', 'name', 'content', { | ||
viewport: 'width=device-width, initial-scale=1', | ||
robots: 'noindex', | ||
// not found metadata | ||
description: 'Root not found description', | ||
}) | ||
expect(await $('title').text()).toBe('Root not found') | ||
}) | ||
|
||
it('should support notFound in generateMetadata', async () => { | ||
const res = await next.fetch('/async/not-found') | ||
expect(res.status).toBe(404) | ||
const $ = await next.render$('/async/not-found') | ||
|
||
// TODO-APP: support render custom not-found in SSR for generateMetadata. | ||
// Check contains root not-found payload in flight response for now. | ||
let hasRootNotFoundFlight = false | ||
for (const el of $('script').toArray()) { | ||
const text = $(el).text() | ||
if (text.includes('Local found boundary')) { | ||
hasRootNotFoundFlight = true | ||
} | ||
} | ||
expect(hasRootNotFoundFlight).toBe(true) | ||
|
||
// Should contain default metadata and noindex tag | ||
const matchHtml = createMultiHtmlMatcher($) | ||
expect($('meta[charset="utf-8"]').length).toBe(1) | ||
matchHtml('meta', 'name', 'content', { | ||
viewport: 'width=device-width, initial-scale=1', | ||
robots: 'noindex', | ||
}) | ||
|
||
const browser = await next.browser('/async/not-found') | ||
expect(await browser.elementByCss('h2').text()).toBe( | ||
'Local found boundary' | ||
) | ||
|
||
const matchMultiDom = createMultiDomMatcher(browser) | ||
await matchMultiDom('meta', 'name', 'content', { | ||
viewport: 'width=device-width, initial-scale=1', | ||
keywords: 'parent', | ||
robots: 'noindex', | ||
// not found metadata | ||
description: 'Local not found description', | ||
}) | ||
expect(await getTitle(browser)).toBe('Local not found') | ||
}) | ||
|
||
it('should support redirect in generateMetadata', async () => { | ||
const res = await next.fetch('/async/redirect', { | ||
redirect: 'manual', | ||
}) | ||
expect(res.status).toBe(307) | ||
}) | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes.
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,12 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('app dir - metadata thrown', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should not crash from error thrown during preloading nested generateMetadata', async () => { | ||
const res = await next.fetch('/dynamic-meta') | ||
expect(res.status).toBe(404) | ||
}) | ||
}) |
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,19 @@ | ||
function format({ params, searchParams }) { | ||
const { slug } = params | ||
const { q } = searchParams | ||
return `params - ${slug}${q ? ` query - ${q}` : ''}` | ||
} | ||
|
||
export default function page(props) { | ||
return <p>{format(props)}</p> | ||
} | ||
|
||
export async function generateMetadata(props, parent) { | ||
const parentMetadata = await parent | ||
/* mutating */ | ||
return { | ||
...parentMetadata, | ||
title: format(props), | ||
keywords: parentMetadata.keywords.concat(['child']), | ||
} | ||
} |
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 @@ | ||
export default function layout({ children }) { | ||
return children | ||
} | ||
|
||
export async function generateMetadata() { | ||
return { | ||
keywords: 'parent', | ||
} | ||
} | ||
|
||
export const revalidate = 0 |
Oops, something went wrong.