Commit b320f5bd authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Add handling for exportTrailingSlash for iSSG pages (#9258)

* Add handling for exportTrailingSlash for iSSG pages

* Update index.test.js
parent aafbd53c
...@@ -3,7 +3,7 @@ import { copyFile as copyFileOrig, existsSync, readFileSync } from 'fs' ...@@ -3,7 +3,7 @@ import { copyFile as copyFileOrig, existsSync, readFileSync } from 'fs'
import Worker from 'jest-worker' import Worker from 'jest-worker'
import mkdirpModule from 'mkdirp' import mkdirpModule from 'mkdirp'
import { cpus } from 'os' import { cpus } from 'os'
import { dirname, join, resolve } from 'path' import { dirname, join, resolve, sep } from 'path'
import { promisify } from 'util' import { promisify } from 'util'
import { AmpPageStatus, formatAmpMessages } from '../build/output/index' import { AmpPageStatus, formatAmpMessages } from '../build/output/index'
...@@ -321,7 +321,12 @@ export default async function( ...@@ -321,7 +321,12 @@ export default async function(
Object.keys(prerenderManifest.routes).map(async route => { Object.keys(prerenderManifest.routes).map(async route => {
route = route === '/' ? '/index' : route route = route === '/' ? '/index' : route
const orig = join(distPagesDir, route) const orig = join(distPagesDir, route)
const htmlDest = join(outDir, `${route}.html`) const htmlDest = join(
outDir,
`${route}${
subFolders && route !== '/index' ? `${sep}index` : ''
}.html`
)
const jsonDest = join(sprDataDir, `${route}.json`) const jsonDest = join(sprDataDir, `${route}.json`)
await mkdirp(dirname(htmlDest)) await mkdirp(dirname(htmlDest))
......
import React from 'react'
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps () {
return {
props: {
slugs: ['post-1', 'post-2'],
time: (await import('perf_hooks')).performance.now()
},
revalidate: 10
}
}
export default ({ slugs, time }) => {
return (
<>
<p>Posts: {JSON.stringify(slugs)}</p>
<span>time: {time}</span>
<Link href='/'>
<a id='home'>to home</a>
</Link>
</>
)
}
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
waitFor, waitFor,
nextBuild, nextBuild,
nextStart, nextStart,
stopApp,
nextExport, nextExport,
startStaticServer, startStaticServer,
initNextServerScript initNextServerScript
...@@ -85,6 +86,11 @@ const expectedManifestRoutes = () => ({ ...@@ -85,6 +86,11 @@ const expectedManifestRoutes = () => ({
initialRevalidateSeconds: 0, initialRevalidateSeconds: 0,
srcRoute: null srcRoute: null
}, },
'/blog': {
dataRoute: `/_next/data/${buildId}/blog.json`,
initialRevalidateSeconds: 10,
srcRoute: null
},
'/default-revalidate': { '/default-revalidate': {
dataRoute: `/_next/data/${buildId}/default-revalidate.json`, dataRoute: `/_next/data/${buildId}/default-revalidate.json`,
initialRevalidateSeconds: 1, initialRevalidateSeconds: 1,
...@@ -449,9 +455,7 @@ describe('SPR Prerender', () => { ...@@ -449,9 +455,7 @@ describe('SPR Prerender', () => {
describe('production mode', () => { describe('production mode', () => {
beforeAll(async () => { beforeAll(async () => {
try { await fs.remove(nextConfig)
await fs.unlink(nextConfig)
} catch (_) {}
await nextBuild(appDir) await nextBuild(appDir)
stderr = '' stderr = ''
appPort = await findPort() appPort = await findPort()
...@@ -471,15 +475,22 @@ describe('SPR Prerender', () => { ...@@ -471,15 +475,22 @@ describe('SPR Prerender', () => {
describe('export mode', () => { describe('export mode', () => {
beforeAll(async () => { beforeAll(async () => {
exportDir = join(appDir, 'out') exportDir = join(appDir, 'out')
await fs.writeFile(
nextConfig,
`module.exports = { exportTrailingSlash: true }`
)
await nextBuild(appDir) await nextBuild(appDir)
await nextExport(appDir, { outdir: exportDir }) await nextExport(appDir, { outdir: exportDir })
app = await startStaticServer(exportDir) app = await startStaticServer(exportDir)
appPort = app.address().port appPort = app.address().port
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8') buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
}) })
afterAll(() => killApp(app)) afterAll(async () => {
await stopApp(app)
await fs.remove(nextConfig)
})
it('should copy prerender files correctly', async () => { it('should copy prerender files and honor exportTrailingSlash', async () => {
const routes = [ const routes = [
'/another', '/another',
'/something', '/something',
...@@ -488,7 +499,7 @@ describe('SPR Prerender', () => { ...@@ -488,7 +499,7 @@ describe('SPR Prerender', () => {
] ]
for (const route of routes) { for (const route of routes) {
await fs.access(join(exportDir, `${route}.html`)) await fs.access(join(exportDir, `${route}/index.html`))
await fs.access(join(exportDir, '_next/data', buildId, `${route}.json`)) await fs.access(join(exportDir, '_next/data', buildId, `${route}.json`))
} }
}) })
......
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