2023-11-01 21:28:13 +01:00
|
|
|
import { nextBuild } from 'next-test-utils'
|
|
|
|
|
|
|
|
describe('ppr build errors', () => {
|
2023-12-04 15:23:32 +01:00
|
|
|
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
|
|
|
|
let stderr: string
|
|
|
|
let stdout: string
|
2023-11-01 21:28:13 +01:00
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
beforeAll(async () => {
|
|
|
|
const output = await nextBuild(__dirname, [], {
|
|
|
|
stderr: true,
|
|
|
|
stdout: true,
|
|
|
|
})
|
|
|
|
stderr = output.stderr
|
|
|
|
stdout = output.stdout
|
2023-11-01 21:28:13 +01:00
|
|
|
})
|
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
describe('within a suspense boundary', () => {
|
|
|
|
it('should fail the build for uncaught prerender errors', async () => {
|
2023-11-01 21:28:13 +01:00
|
|
|
expect(stderr).toContain(
|
2023-12-04 15:23:32 +01:00
|
|
|
'Error occurred prerendering page "/regular-error-suspense-boundary".'
|
2023-11-01 21:28:13 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
describe('when a postpone call was made but missing postpone data', () => {
|
|
|
|
it('should fail the build', async () => {
|
|
|
|
expect(stderr).toContain(
|
|
|
|
'Prerendering / needs to partially bail out because something dynamic was used. '
|
|
|
|
)
|
|
|
|
})
|
2023-11-01 21:28:13 +01:00
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
it('should fail the build & surface any errors that were thrown by user code', async () => {
|
|
|
|
// in the case of catching a postpone and throwing a new error, we log the error that the user threw to help with debugging
|
|
|
|
expect(stderr).toContain(
|
|
|
|
'Prerendering /re-throwing-error needs to partially bail out because something dynamic was used. '
|
|
|
|
)
|
|
|
|
expect(stderr).toContain(
|
|
|
|
'The following error was thrown during build, and may help identify the source of the issue:'
|
|
|
|
)
|
|
|
|
expect(stderr).toContain(
|
|
|
|
'Error: The original error was caught and rethrown.'
|
|
|
|
)
|
2023-11-01 21:28:13 +01:00
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
// the regular pre-render error should not be thrown as well, as we've already logged a more specific error
|
|
|
|
expect(stderr).not.toContain(
|
|
|
|
'Error occurred prerendering page "/re-throwing-error"'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2023-11-01 21:28:13 +01:00
|
|
|
})
|
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
describe('outside of a suspense boundary', () => {
|
|
|
|
it('should fail the build for uncaught errors', async () => {
|
2023-11-01 21:28:13 +01:00
|
|
|
expect(stderr).toContain(
|
2023-12-04 15:23:32 +01:00
|
|
|
'Error occurred prerendering page "/regular-error".'
|
2023-11-01 21:28:13 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
describe('when a postpone call was made but missing postpone data', () => {
|
|
|
|
it('should fail the build', async () => {
|
|
|
|
expect(stderr).toContain(
|
|
|
|
'Prerendering /no-suspense-boundary needs to partially bail out because something dynamic was used. '
|
|
|
|
)
|
2023-11-01 21:28:13 +01:00
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
// the regular pre-render error should not be thrown as well, as we've already logged a more specific error
|
|
|
|
expect(stderr).not.toContain(
|
|
|
|
'Error occurred prerendering page "/no-suspense-boundary"'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should fail the build & surface any errors that were thrown by user code', async () => {
|
|
|
|
// in the case of catching a postpone and throwing a new error, we log the error that the user threw to help with debugging
|
|
|
|
expect(stderr).toContain(
|
|
|
|
'Prerendering /no-suspense-boundary-re-throwing-error needs to partially bail out because something dynamic was used. '
|
|
|
|
)
|
|
|
|
expect(stderr).toContain(
|
|
|
|
'The following error was thrown during build, and may help identify the source of the issue:'
|
|
|
|
)
|
|
|
|
expect(stderr).toContain(
|
|
|
|
"Error: Throwing a new error from 'no-suspense-boundary-re-throwing-error'"
|
|
|
|
)
|
|
|
|
|
|
|
|
// the regular pre-render error should not be thrown as well, as we've already logged a more specific error
|
|
|
|
expect(stderr).not.toContain(
|
|
|
|
'Error occurred prerendering page "/no-suspense-boundary-re-throwing-error"'
|
|
|
|
)
|
|
|
|
})
|
2023-11-01 21:28:13 +01:00
|
|
|
})
|
|
|
|
})
|
2023-11-08 22:16:40 +01:00
|
|
|
|
2023-12-04 15:23:32 +01:00
|
|
|
describe('when a postpone call is caught and logged it should', () => {
|
|
|
|
it('should include a message telling why', async () => {
|
|
|
|
expect(stdout).toContain(
|
|
|
|
'Logged error: This page needs to bail out of prerendering at this point because it used cookies.'
|
|
|
|
)
|
|
|
|
})
|
2023-11-08 22:16:40 +01:00
|
|
|
})
|
|
|
|
})
|
2023-11-01 21:28:13 +01:00
|
|
|
})
|