rsnext/test/e2e/app-dir/static-generation-status/index.test.ts
Jiachi Liu 93aac0e39b
Respect non 200 status to page static generation response (#63731)
### What

In static generation phase of app page, if there's any case that we're
receiving 3xx/4xx status code from the response, we 're setting it into
the static generation meta now to make sure they're still returning the
same status after build.

### Why

During static generation if there's any 3xx/4xx status code that is set
in the response, we should respect to it, such as the ones caused by
using `notFound()` to mark as 404 response or `redirect` to mark as
`307` response.

Closes NEXT-2895
Fixes #51021
Fixes #62228
2024-03-27 16:20:02 +01:00

25 lines
716 B
TypeScript

import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'app-dir static-generation-status',
{
files: __dirname,
},
({ next }) => {
it('should render the page using notFound with status 404', async () => {
const { status } = await next.fetch('/not-found-page')
expect(status).toBe(404)
})
it('should render the page using redirect with status 307', async () => {
const { status } = await next.fetch('/redirect-page', {
redirect: 'manual',
})
expect(status).toBe(307)
})
it('should render the non existed route redirect with status 404', async () => {
expect((await next.fetch('/does-not-exist')).status).toBe(404)
})
}
)