-
Notifications
You must be signed in to change notification settings - Fork 26.1k
/
index.test.js
51 lines (41 loc) · 1.71 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* eslint-env jest */
import { promises } from 'fs'
import { join } from 'path'
import { nextBuild, nextExport, File } from 'next-test-utils'
const { readFile, access, stat } = promises
const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')
const nextConfig = new File(join(appDir, 'next.config.js'))
const fileExist = (path) =>
access(path)
.then(() => stat(path))
.then((stats) => (stats.isFile() ? true : false))
.catch(() => false)
// Issue #36855
// https://github.com/vercel/next.js/issues/36855
describe('Static 404 Export', () => {
it('only export 404.html when trailingSlash: false', async () => {
await nextBuild(appDir)
await nextExport(appDir, { outdir })
expect(await fileExist(join(outdir, '404.html'))).toBe(true)
expect(await fileExist(join(outdir, '404.html.html'))).toBe(false)
expect(await fileExist(join(outdir, '404/index.html'))).toBe(false)
})
it('export 404.html and 404/index.html when trailingSlash: true', async () => {
nextConfig.replace(`trailingSlash: false`, `trailingSlash: true`)
await nextBuild(appDir)
await nextExport(appDir, { outdir })
nextConfig.restore()
expect(await fileExist(join(outdir, '404/index.html'))).toBe(true)
expect(await fileExist(join(outdir, '404.html.html'))).toBe(false)
expect(await fileExist(join(outdir, '404.html'))).toBe(true)
})
})
describe('Export with a page named 404.js', () => {
it('should export a custom 404.html instead of default 404.html', async () => {
await nextBuild(appDir)
await nextExport(appDir, { outdir })
const html = await readFile(join(outdir, '404.html'), 'utf8')
expect(html).toMatch(/this is a 404 page override the default 404\.html/)
})
})