Unverified Commit a0e3198a authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add test for top-level _document error (#24313)

This adds an additional test for the change in https://github.com/vercel/next.js/pull/24079 to ensure top-level errors in `_document` are also handled correctly. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## 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`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
parent 03cc0f89
......@@ -1301,3 +1301,82 @@ test('_app top level error shows logbox', async () => {
expect(await session.hasRedbox()).toBe(false)
await cleanup()
})
test('_document top level error shows logbox', async () => {
const [session, cleanup] = await sandbox(
undefined,
new Map([
[
'pages/_document.js',
`
import Document, { Html, Head, Main, NextScript } from 'next/document'
throw new Error("test");
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}
render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
export default MyDocument
`,
],
])
)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"pages/_document.js (4:16) @ eval
2 | import Document, { Html, Head, Main, NextScript } from 'next/document'
3 |
> 4 | throw new Error(\\"test\\");
| ^
5 |
6 | class MyDocument extends Document {
7 | static async getInitialProps(ctx) {"
`)
await session.patch(
'pages/_document.js',
`
import Document, { Html, Head, Main, NextScript } from 'next/document'
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}
render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
export default MyDocument
`
)
expect(await session.hasRedbox()).toBe(false)
await cleanup()
})
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