(mode = 'server')
| 27 | (await fetchViaHTTP(port, pathname)).headers.get('Cache-Control') |
| 28 | |
| 29 | const runTests = (mode = 'server') => { |
| 30 | it('should use pages/404', async () => { |
| 31 | const html = await renderViaHTTP(appPort, '/abc') |
| 32 | expect(html).toContain('custom 404 page') |
| 33 | }) |
| 34 | |
| 35 | it('should set correct status code with pages/404', async () => { |
| 36 | const res = await fetchViaHTTP(appPort, '/abc') |
| 37 | expect(res.status).toBe(404) |
| 38 | }) |
| 39 | |
| 40 | it('should use pages/404 for .d.ts file', async () => { |
| 41 | const html = await renderViaHTTP(appPort, '/invalidExtension') |
| 42 | expect(html).toContain('custom 404 page') |
| 43 | }) |
| 44 | |
| 45 | it('should not error when visited directly', async () => { |
| 46 | const res = await fetchViaHTTP(appPort, '/404') |
| 47 | expect(res.status).toBe(404) |
| 48 | expect(await res.text()).toContain('custom 404 page') |
| 49 | }) |
| 50 | |
| 51 | it('should render _error for a 500 error still', async () => { |
| 52 | const html = await renderViaHTTP(appPort, '/err') |
| 53 | expect(html).not.toContain('custom 404 page') |
| 54 | expect(html).toContain(mode === 'dev' ? 'oops' : 'Internal Server Error') |
| 55 | }) |
| 56 | |
| 57 | if (mode !== 'dev') { |
| 58 | it('should output 404.html during build', async () => { |
| 59 | const page = getPageFileFromPagesManifest(appDir, '/404') |
| 60 | expect(page.endsWith('.html')).toBe(true) |
| 61 | }) |
| 62 | |
| 63 | it('should still output 404.js anyway', async () => { |
| 64 | expect( |
| 65 | await fs.pathExists(join(appDir, '.next/server/pages/404.js')) |
| 66 | ).toBeTrue() |
| 67 | }) |
| 68 | |
| 69 | it('should add /404 to pages-manifest correctly', async () => { |
| 70 | const manifest = await fs.readJSON( |
| 71 | join(appDir, '.next', mode, 'pages-manifest.json') |
| 72 | ) |
| 73 | expect('/404' in manifest).toBe(true) |
| 74 | }) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | describe('404 Page Support', () => { |
| 79 | ;(process.env.TURBOPACK_BUILD ? describe.skip : describe)( |
no test coverage detected