rsnext/test/e2e/app-dir/parallel-route-not-found/parallel-route-not-found.test.ts
Zack Tanner c56d69da5d
use correct not-found component when triggered from a parallel route (#65343)
When `notFound()` is thrown from metadata, it's caught by a
`<MetadataOutlet />` rendered as a sibling to the page component. But we
currently only pass the custom not-found component to the
`<NotFoundBoundary />` for the `children` slot. This means that if a
parallel route throws a `notFound()` in `generateMetadata`, it'd be
caught by the root not found, which would be unexpected.

This mirrors the logic for determining whether or not a `notFound`
boundary should be provided. A side effect of this is that if you throw
a `notFound()` in `generateMetadata` for a segment that _only_ has
parallel routes, and no `children` slot, it won't be caught by the
boundary. But fixing this will require a larger refactor.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-3320
2024-05-06 14:46:54 +00:00

103 lines
3.8 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
describe('parallel-route-not-found', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
it('should handle a layout that attempts to render a missing parallel route', async () => {
const browser = await next.browser('/no-bar-slot')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'This page could not be found'
)
const warnings = logs.filter((log) => log.source === 'warning')
if (isNextDev) {
expect(warnings.length).toBe(1)
expect(warnings[0].message).toContain(
'No default component was found for a parallel route rendered on this page'
)
expect(warnings[0].message).toContain('Missing slots: @bar')
} else {
expect(warnings.length).toBe(0)
}
})
it('should handle multiple missing parallel routes', async () => {
const browser = await next.browser('/both-slots-missing')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'This page could not be found'
)
const warnings = logs.filter((log) => log.source === 'warning')
if (isNextDev) {
expect(warnings.length).toBe(1)
expect(warnings[0].message).toContain(
'No default component was found for a parallel route rendered on this page'
)
expect(warnings[0].message).toContain('Missing slots: @bar, @foo')
} else {
expect(warnings.length).toBe(0)
}
})
it('should render the page & slots if all parallel routes are found', async () => {
const browser = await next.browser('/has-both-slots')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'Has Both Slots'
)
expect(await browser.elementByCss('body').text()).toContain('@foo slot')
expect(await browser.elementByCss('body').text()).toContain('@bar slot')
const warnings = logs.filter((log) => log.source === 'warning')
expect(warnings.length).toBe(0)
})
it('should handle `notFound()` in generateMetadata on a page that also renders a parallel route', async () => {
const browser = await next.browser('/not-found-metadata/page-error')
// The page's `generateMetadata` function threw a `notFound()` error,
// so we should see the not found page.
expect(await browser.elementByCss('body').text()).toContain(
'Custom Not Found!'
)
})
it('should handle `notFound()` in a slot', async () => {
const browser = await next.browser('/not-found-metadata/slot-error')
// The page's `generateMetadata` function threw a `notFound()` error,
// so we should see the not found page.
expect(await browser.elementByCss('body').text()).toContain(
'Custom Not Found!'
)
})
// TODO-APP: This test should probably work. But we only provide a not-found boundary for the children slot.
// This means that if a parallel route throws a notFound() in generateMetadata, it won't be properly handled.
it.skip('should handle `notFound()` in a slot with no `children` slot', async () => {
const browser = await next.browser('/not-found-metadata/no-page')
// The page's `generateMetadata` function threw a `notFound()` error,
// so we should see the not found page.
expect(await browser.elementByCss('body').text()).toContain(
'Custom Not Found!'
)
})
if (isNextDev) {
it('should not log any warnings for a regular not found page', async () => {
const browser = await next.browser('/this-page-doesnt-exist')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'This page could not be found'
)
const warnings = logs.filter((log) => log.source === 'warning')
expect(warnings.length).toBe(0)
})
}
})