提交 b320f5bd 编写于 作者: J JJ Kasper 提交者: Joe Haddad

Add handling for exportTrailingSlash for iSSG pages (#9258)

* Add handling for exportTrailingSlash for iSSG pages

* Update index.test.js
上级 aafbd53c
......@@ -3,7 +3,7 @@ import { copyFile as copyFileOrig, existsSync, readFileSync } from 'fs'
import Worker from 'jest-worker'
import mkdirpModule from 'mkdirp'
import { cpus } from 'os'
import { dirname, join, resolve } from 'path'
import { dirname, join, resolve, sep } from 'path'
import { promisify } from 'util'
import { AmpPageStatus, formatAmpMessages } from '../build/output/index'
......@@ -321,7 +321,12 @@ export default async function(
Object.keys(prerenderManifest.routes).map(async route => {
route = route === '/' ? '/index' : 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`)
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 {
waitFor,
nextBuild,
nextStart,
stopApp,
nextExport,
startStaticServer,
initNextServerScript
......@@ -85,6 +86,11 @@ const expectedManifestRoutes = () => ({
initialRevalidateSeconds: 0,
srcRoute: null
},
'/blog': {
dataRoute: `/_next/data/${buildId}/blog.json`,
initialRevalidateSeconds: 10,
srcRoute: null
},
'/default-revalidate': {
dataRoute: `/_next/data/${buildId}/default-revalidate.json`,
initialRevalidateSeconds: 1,
......@@ -449,9 +455,7 @@ describe('SPR Prerender', () => {
describe('production mode', () => {
beforeAll(async () => {
try {
await fs.unlink(nextConfig)
} catch (_) {}
await fs.remove(nextConfig)
await nextBuild(appDir)
stderr = ''
appPort = await findPort()
......@@ -471,15 +475,22 @@ describe('SPR Prerender', () => {
describe('export mode', () => {
beforeAll(async () => {
exportDir = join(appDir, 'out')
await fs.writeFile(
nextConfig,
`module.exports = { exportTrailingSlash: true }`
)
await nextBuild(appDir)
await nextExport(appDir, { outdir: exportDir })
app = await startStaticServer(exportDir)
appPort = app.address().port
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 = [
'/another',
'/something',
......@@ -488,7 +499,7 @@ describe('SPR Prerender', () => {
]
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`))
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册