Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to honor exportTrailingSlash for default 404 #10109

Merged
merged 3 commits into from Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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