Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test(#36855): add test case
  • Loading branch information
SukkaW committed May 14, 2022
commit 2ed6aa377c88d9b9b64a87ef7e96c71bddcfa5ae
1 change: 1 addition & 0 deletions test/integration/export-404-html/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.next-dev
5 changes: 5 additions & 0 deletions test/integration/export-404-html/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (phase) => {
return {
trailingSlash: false,
}
}
1 change: 1 addition & 0 deletions test/integration/export-404-html/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <div id="home-page" />
43 changes: 43 additions & 0 deletions test/integration/export-404-html/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-env jest */

import { join } from 'path'
import { nextBuild, nextExport, File } from 'next-test-utils'

import { promises } from 'fs'

const { access, stat } = promises
const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')
const context = {}
context.appDir = appDir
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)
})
})