Unverified Commit 4a9dc112 authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

Test server component error recovery in dev (#44155)

Test that server components can recover from syntax and component error.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent a7b046d9
...@@ -247,6 +247,88 @@ describe('ReactRefreshLogBox app', () => { ...@@ -247,6 +247,88 @@ describe('ReactRefreshLogBox app', () => {
await cleanup() await cleanup()
}) })
test('server component can recover from syntax error', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`
export default function Page() {
return <p>Hello world</p>
}
`,
],
])
)
// Add syntax error
await session.patch(
'app/page.js',
`
export default function Page() {
return <p>Hello world</p>
`
)
expect(await session.hasRedbox(true)).toBe(true)
// Fix syntax error
await session.patch(
'app/page.js',
`
export default function Page() {
return <p>Hello world 2</p>
}
`
)
expect(await browser.waitForElementByCss('p').text()).toBe('Hello world 2')
await cleanup()
})
test('server component can recover from component error', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`
export default function Page() {
return <p>Hello world</p>
}
`,
],
])
)
// Add component error
await session.patch(
'app/page.js',
`
export default function Page() {
throw new Error("boom")
return <p>Hello world</p>
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
// Fix component error
await session.patch(
'app/page.js',
`
export default function Page() {
return <p>Hello world 2</p>
}
`
)
expect(await browser.waitForElementByCss('p').text()).toBe('Hello world 2')
await cleanup()
})
// https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554137262 // https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554137262
test('render error not shown right after syntax error', async () => { test('render error not shown right after syntax error', async () => {
const { session, cleanup } = await sandbox(next) const { session, cleanup } = await sandbox(next)
......
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