-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dx: add pagePath info to missing component error (#66916)
### What Show the full `pagePath` information for missing default component app router convention files. Move runtime error tests from `rsc-build-errors.test.ts` to the new test `test/development/acceptance-app/undefined-default-export.test.ts` ### Why Previously we only log `segment` which could be `[slug]` that is not enough useful for users to locate the bad defined component
- Loading branch information
Showing
3 changed files
with
100 additions
and
47 deletions.
There are no files selected for viewing
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
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
90 changes: 90 additions & 0 deletions
90
test/development/acceptance-app/undefined-default-export.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,90 @@ | ||
import path from 'path' | ||
import { FileRef, nextTestSetup } from 'e2e-utils' | ||
import { sandbox } from 'development-sandbox' | ||
|
||
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 () => { | ||
const { session, cleanup } = await sandbox( | ||
next, | ||
new Map([ | ||
['app/(group)/specific-path/server/page.js', 'export const a = 123'], | ||
]), | ||
'/specific-path/server' | ||
) | ||
|
||
await session.assertHasRedbox() | ||
expect(await session.getRedboxDescription()).toInclude( | ||
'The default export is not a React Component in "/specific-path/server/page"' | ||
) | ||
|
||
await cleanup() | ||
}) | ||
|
||
it('should error if not-found component does not have default export when trigger not-found boundary', async () => { | ||
const { session, cleanup } = await sandbox( | ||
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' | ||
) | ||
|
||
await session.assertHasRedbox() | ||
expect(await session.getRedboxDescription()).toInclude( | ||
'The default export is not a React Component in "/will-not-found/not-found"' | ||
) | ||
|
||
await cleanup() | ||
}) | ||
|
||
it('should error when page component export is not valid', async () => { | ||
const { session, cleanup } = await sandbox( | ||
next, | ||
undefined, | ||
'/server-with-errors/page-export' | ||
) | ||
|
||
await next.patchFile( | ||
'app/server-with-errors/page-export/page.js', | ||
'export const a = 123' | ||
) | ||
|
||
await session.assertHasRedbox() | ||
expect(await session.getRedboxDescription()).toInclude( | ||
'The default export is not a React Component in "/server-with-errors/page-export/page"' | ||
) | ||
|
||
await cleanup() | ||
}) | ||
|
||
it('should error when page component export is not valid on initial load', async () => { | ||
const { session, cleanup } = await sandbox( | ||
next, | ||
new Map([ | ||
[ | ||
'app/server-with-errors/page-export-initial-error/page.js', | ||
'export const a = 123', | ||
], | ||
]), | ||
'/server-with-errors/page-export-initial-error' | ||
) | ||
|
||
await session.assertHasRedbox() | ||
expect(await session.getRedboxDescription()).toInclude( | ||
'The default export is not a React Component in "/server-with-errors/page-export-initial-error/page"' | ||
) | ||
|
||
await cleanup() | ||
}) | ||
}) |