Skip to content

Commit

Permalink
test(vercel#30300): update intergration test case
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed May 11, 2022
1 parent e05a95a commit 375dc17
Showing 1 changed file with 18 additions and 44 deletions.
62 changes: 18 additions & 44 deletions test/integration/export/test/index.test.js
Expand Up @@ -20,7 +20,7 @@ import { promises } from 'fs'
import dynamic from './dynamic'
import apiRoutes from './api-routes'

const { access, mkdir, writeFile } = promises
const { access, mkdir, writeFile, stat } = promises
const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')
const outNoTrailSlash = join(appDir, 'outNoTrailSlash')
Expand All @@ -29,6 +29,12 @@ context.appDir = appDir
const devContext = {}
const nextConfig = new File(join(appDir, 'next.config.js'))

const fileExist = (path) =>
access(path)
.then(() => stat(path))
.then((stats) => (stats.isFile() ? true : false))
.catch(() => false)

describe('Static Export', () => {
it('should delete existing exported files', async () => {
const tempfile = join(outdir, 'temp.txt')
Expand Down Expand Up @@ -87,60 +93,28 @@ 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)
expect(await fileExist(join(outdir, '404/index.html'))).toBe(true)

// we still output 404.html for backwards compat
expect(
await access(join(outdir, '404.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
expect(await fileExist(join(outdir, '404.html'))).toBe(true)
})

it('should handle trailing slash in getStaticPaths', async () => {
expect(
await access(join(outdir, 'gssp/foo/index.html'))
.then(() => true)
.catch(() => false)
).toBe(true)

expect(
await access(join(outNoTrailSlash, 'gssp/foo.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
expect(await fileExist(join(outdir, 'gssp/foo/index.html'))).toBe(true)

expect(await fileExist(join(outNoTrailSlash, 'gssp/foo.html'))).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)
expect(await fileExist(join(outNoTrailSlash, '404/index.html'))).toBe(false)

expect(await fileExist(join(outNoTrailSlash, '404.html'))).toBe(true)
})

it('should not duplicate /index with exportTrailingSlash', async () => {
expect(
await access(join(outdir, 'index/index.html'))
.then(() => true)
.catch(() => false)
).toBe(false)

expect(
await access(join(outdir, 'index.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
expect(await fileExist(join(outdir, 'index/index.html'))).toBe(false)

expect(await fileExist(join(outdir, 'index.html'))).toBe(true)
})

ssr(context)
Expand Down

0 comments on commit 375dc17

Please sign in to comment.