Skip to content

Commit

Permalink
Merge branch 'canary' into sam/github-workflow/bankrupt-2019-againn
Browse files Browse the repository at this point in the history
  • Loading branch information
samcx committed Jun 19, 2024
2 parents 768630f + dd06246 commit f8d09dd
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 247 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml
with:
afterBuild: pnpm install && ./node_modules/.bin/devlow-bench ./scripts/devlow-bench.mjs --datadog=ubuntu-latest-16-core ${{ matrix.mode }} ${{ matrix.selector }}
stepName: 'devlow-bench-${{ matrix.group }}'
stepName: 'devlow-bench-${{ matrix.mode }}-${{ matrix.selector }}'
secrets: inherit

test-turbopack-dev:
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/app-dir/metadata-navigation/app/layout.tsx
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 test/e2e/app-dir/metadata-navigation/metadata-navigation.test.ts
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)
})
})
})
12 changes: 12 additions & 0 deletions test/e2e/app-dir/metadata-thrown/metadata-thrown.test.ts
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)
})
})
19 changes: 19 additions & 0 deletions test/e2e/app-dir/metadata/app/dynamic/[slug]/page.tsx
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']),
}
}
11 changes: 11 additions & 0 deletions test/e2e/app-dir/metadata/app/dynamic/layout.tsx
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
Loading

0 comments on commit f8d09dd

Please sign in to comment.