File size: 4,036 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
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')),
})
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": [],
}
`)
})
})
|