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

fix: not-found.tsx with output: export #52526

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions test/integration/app-dir-export/app/not-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function NotFound() {
return <h1>My custom not found page</h1>
}
10 changes: 5 additions & 5 deletions test/integration/app-dir-export/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'path'
import {
appDir,
distDir,
expectedFiles,
expectedWhenTrailingSlashTrue,
exportDir,
getFiles,
nextConfig,
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('app dir with output export (next dev / next build)', () => {
await fs.remove(distDir)
await fs.remove(exportDir)
await nextBuild(appDir)
expect(await getFiles()).toEqual(expectedFiles)
expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
let stdout = ''
let stderr = ''
await nextExportDefault(appDir, {
Expand All @@ -51,13 +51,13 @@ describe('app dir with output export (next dev / next build)', () => {
'- warn "next export" is no longer needed when "output: export" is configured in next.config.js'
)
expect(stdout).toContain('Export successful. Files written to')
expect(await getFiles()).toEqual(expectedFiles)
expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
})
it('should error when "next export -o <dir>" is used with config', async () => {
await fs.remove(distDir)
await fs.remove(exportDir)
await nextBuild(appDir)
expect(await getFiles()).toEqual(expectedFiles)
expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
let stdout = ''
let stderr = ''
let error = undefined
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('app dir with output export (next dev / next build)', () => {
)
try {
await nextBuild(appDir)
expect(await getFiles(outputDir)).toEqual(expectedFiles)
expect(await getFiles(outputDir)).toEqual(expectedWhenTrailingSlashTrue)
} finally {
nextConfig.restore()
await fs.remove(distDir)
Expand Down
40 changes: 33 additions & 7 deletions test/integration/app-dir-export/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const nextConfig = new File(join(appDir, 'next.config.js'))
const slugPage = new File(join(appDir, 'app/another/[slug]/page.js'))
const apiJson = new File(join(appDir, 'app/api/json/route.js'))

export const expectedFiles = [
export const expectedWhenTrailingSlashTrue = [
'404.html',
'404/index.html',
'_next/static/media/test.3f1a293b.png',
Expand All @@ -49,6 +49,27 @@ export const expectedFiles = [
'robots.txt',
]

const expectedWhenTrailingSlashFalse = [
'404.html',
'_next/static/media/test.3f1a293b.png',
'_next/static/test-build-id/_buildManifest.js',
'_next/static/test-build-id/_ssgManifest.js',
'another.html',
'another.txt',
'another/first.html',
'another/first.txt',
'another/second.html',
'another/second.txt',
'api/json',
'api/txt',
'favicon.ico',
'image-import.html',
'image-import.txt',
'index.html',
'index.txt',
'robots.txt',
]

export async function getFiles(cwd = exportDir) {
const opts = { cwd, nodir: true }
const files = ((await glob('**/*', opts)) as string[])
Expand All @@ -74,19 +95,19 @@ export async function runTests({
dynamicApiRoute?: string
expectedErrMsg?: string
}) {
if (trailingSlash) {
if (trailingSlash !== undefined) {
nextConfig.replace(
'trailingSlash: true,',
`trailingSlash: ${trailingSlash},`
)
}
if (dynamicPage) {
if (dynamicPage !== undefined) {
slugPage.replace(
`const dynamic = 'force-static'`,
`const dynamic = ${dynamicPage}`
)
}
if (dynamicApiRoute) {
if (dynamicApiRoute !== undefined) {
apiJson.replace(
`const dynamic = 'force-static'`,
`const dynamic = ${dynamicApiRoute}`
Expand Down Expand Up @@ -156,7 +177,6 @@ export async function runTests({
await check(() => browser.elementByCss('h1').text(), 'Home')
expect(await browser.elementByCss(a(3)).text()).toBe('another first page')
await browser.elementByCss(a(3)).click()

await check(() => browser.elementByCss('h1').text(), 'first')
expect(await browser.elementByCss(a(1)).text()).toBe('Visit another page')
await browser.elementByCss(a(1)).click()
Expand Down Expand Up @@ -188,8 +208,14 @@ export async function runTests({
expect(res2.status).toBe(200)
expect(await res2.text()).toEqual('this is plain text')

if (!isDev && trailingSlash) {
expect(await getFiles()).toEqual(expectedFiles)
if (!isDev) {
if (trailingSlash) {
expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
} else {
expect(await getFiles()).toEqual(expectedWhenTrailingSlashFalse)
}
const html404 = await fs.readFile(join(exportDir, '404.html'), 'utf8')
expect(html404).toContain('<h1>My custom not found page</h1>')
}
}
} finally {
Expand Down