Skip to content

Commit

Permalink
Honor exportTrailingSlash for default 404 (#10109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 15, 2020
1 parent d672167 commit 563f3c0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/next/export/index.ts
Expand Up @@ -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',
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/export-serverless/test/ssr.js
Expand Up @@ -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 () => {
Expand Down
35 changes: 31 additions & 4 deletions test/integration/export/test/index.test.js
Expand Up @@ -27,14 +27,15 @@ 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 = {}
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 => {
Expand All @@ -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 })

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/integration/export/test/ssr.js
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 563f3c0

Please sign in to comment.