Skip to content

Commit

Permalink
test(vercel#36855): add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed May 14, 2022
1 parent 167a91b commit 2ed6aa3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/integration/export-404-html/.gitignore
@@ -0,0 +1 @@
.next-dev
5 changes: 5 additions & 0 deletions test/integration/export-404-html/next.config.js
@@ -0,0 +1,5 @@
module.exports = (phase) => {
return {
trailingSlash: false,
}
}
1 change: 1 addition & 0 deletions test/integration/export-404-html/pages/index.js
@@ -0,0 +1 @@
export default () => <div id="home-page" />
43 changes: 43 additions & 0 deletions test/integration/export-404-html/test/index.test.js
@@ -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)
})
})

0 comments on commit 2ed6aa3

Please sign in to comment.