Unverified Commit d6125822 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

[test] Overhaul `Undefined default export` test suite (#84235)

The test suite is now using fixture files instead of sandboxes, same principle as in #83398. I also removed two test cases that didn't test anything novel, compared to the other tests. They were originally moved from another test suite into this one in #66916.

This is done in preparation for adding build-time assertions.

> [!TIP]
> Best reviewed with hidden whitespace changes.
parent 46fa4ded
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { notFound } from 'next/navigation'
export default function Page() {
notFound()
}
import path from 'path'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { createSandbox } from 'development-sandbox'
import { retry } from 'next-test-utils'
describe('Undefined default export', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
const { next, isNextDev } = nextTestSetup({
files: new FileRef(
path.join(__dirname, 'fixtures', 'undefined-default-export')
),
})
it('should error if page component does not have default export', async () => {
await using sandbox = await createSandbox(
next,
new Map([
['app/(group)/specific-path/server/page.js', 'export const a = 123'],
]),
'/specific-path/server'
)
const { browser } = sandbox
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/specific-path/server/page"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
it('should error if layout component does not have default export', async () => {
await using sandbox = await createSandbox(
next,
new Map([
['app/(group)/specific-path/server/layout.js', 'export const a = 123'],
[
'app/(group)/specific-path/server/page.js',
'export default function Page() { return <div>Hello</div> }',
],
]),
'/specific-path/server'
)
const { browser } = sandbox
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/specific-path/server/layout"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
it('should error if not-found component does not have default export when trigger not-found boundary', async () => {
await using sandbox = await createSandbox(
next,
new Map([
[
'app/will-not-found/page.js',
`
import { notFound } from 'next/navigation'
export default function Page() { notFound() }
`,
],
['app/will-not-found/not-found.js', 'export const a = 123'],
]),
'/will-not-found'
)
const { browser } = sandbox
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/will-not-found/not-found"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
it('should error when page component export is not valid', async () => {
await using sandbox = await createSandbox(next, undefined, '/')
const { browser } = sandbox
const cliOutputLength = next.cliOutput.length
await next.patchFile('app/page.js', 'const a = 123')
// The page will fail build and navigate to /_error route of pages router.
// We wait for the error page to be compiled before asserting the redbox.
await retry(async () => {
expect(next.cliOutput.slice(cliOutputLength)).toContain(
'✓ Compiled /_error'
)
}, 10_000)
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/page"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
it('should error when page component export is not valid on initial load', async () => {
await using sandbox = await createSandbox(
next,
new Map([
[
'app/server-with-errors/page-export-initial-error/page.js',
'export const a = 123',
],
]),
'/server-with-errors/page-export-initial-error'
)
const { browser } = sandbox
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/server-with-errors/page-export-initial-error/page"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
// TODO: This is currently always true. It's just here to already indent the
// code, so that git blame is preserved in the subsequent commit, when we're
// moving the file.
if (isNextDev) {
it('should error if page component does not have default export', async () => {
const browser = await next.browser('/specific-path/1')
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/specific-path/1/page"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
it('should error if layout component does not have default export', async () => {
const browser = await next.browser('/specific-path/2')
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/specific-path/2/layout"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
it('should error if not-found component does not have default export when trigger not-found boundary', async () => {
const browser = await next.browser('/will-not-found')
await expect(browser).toDisplayRedbox(`
{
"description": "The default export is not a React Component in "/will-not-found/not-found"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
})
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment