Unverified Commit 563f3c08 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Honor exportTrailingSlash for default 404 (#10109)

parent d6721676
......@@ -254,8 +254,8 @@ export default async function(
distDir,
buildId,
})
if (!exportPathMap['/404']) {
exportPathMap['/404.html'] = exportPathMap['/404.html'] || {
if (!exportPathMap['/404'] && !exportPathMap['/404.html']) {
exportPathMap['/404'] = exportPathMap['/404.html'] = {
page: '/_error',
}
}
......
......@@ -58,11 +58,11 @@ export default function(context) {
expect(html).toMatch(/404.*page.*not.*found/i)
})
it('should not render _error on /404/index.html', async () => {
it('should render _error on /404/index.html', async () => {
const html = await renderViaHTTP(context.port, '/404/index.html')
// The default error page from the test server
// contains "404", so need to be specific here
expect(html).not.toMatch(/404.*page.*not.*found/i)
expect(html).toMatch(/404.*page.*not.*found/i)
})
it('Should serve static files', async () => {
......
......@@ -27,6 +27,8 @@ const writeFile = promisify(fs.writeFile)
const mkdir = promisify(fs.mkdir)
const access = promisify(fs.access)
const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')
const outNoTrailSlash = join(appDir, 'outNoTrailSlash')
const context = {}
context.appDir = appDir
const devContext = {}
......@@ -34,7 +36,6 @@ const nextConfig = new File(join(appDir, 'next.config.js'))
describe('Static Export', () => {
it('should delete existing exported files', async () => {
const outdir = join(appDir, 'out')
const tempfile = join(outdir, 'temp.txt')
await mkdir(outdir).catch(e => {
......@@ -52,9 +53,6 @@ describe('Static Export', () => {
expect(doesNotExist).toBe(true)
})
beforeAll(async () => {
const outdir = join(appDir, 'out')
const outNoTrailSlash = join(appDir, 'outNoTrailSlash')
await nextBuild(appDir)
await nextExport(appDir, { outdir })
......@@ -93,6 +91,35 @@ describe('Static Export', () => {
])
})
it('should honor exportTrailingSlash for 404 page', async () => {
expect(
await access(join(outdir, '404/index.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
// we still output 404.html for backwards compat
expect(
await access(join(outdir, '404.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
})
it('should only output 404.html without exportTrailingSlash', async () => {
expect(
await access(join(outNoTrailSlash, '404/index.html'))
.then(() => true)
.catch(() => false)
).toBe(false)
expect(
await access(join(outNoTrailSlash, '404.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
})
ssr(context)
browser(context)
dev(devContext)
......
......@@ -58,11 +58,12 @@ export default function(context) {
expect(html).toMatch(/404.*page.*not.*found/i)
})
it('should not render _error on /404/index.html', async () => {
// since exportTrailingSlash is enabled we should allow this
it('should render _error on /404/index.html', async () => {
const html = await renderViaHTTP(context.port, '/404/index.html')
// The default error page from the test server
// contains "404", so need to be specific here
expect(html).not.toMatch(/404.*page.*not.*found/i)
expect(html).toMatch(/404.*page.*not.*found/i)
})
it('Should serve static files', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment