Commit 17353cc6 authored by Tim Neutkens's avatar Tim Neutkens

Port test from vercel/vercel

parent 93af1eb0
import { nextTestSetup } from 'e2e-utils'
import fs from 'fs'
import path from 'path'
describe('i18n-beforefiles-rewrite', () => {
const { next } = nextTestSetup({
files: __dirname,
})
const locales = ['en', 'fr']
// Auto-static pages (no getStaticProps / getServerSideProps) that should
// only have locale-prefixed HTML in server/pages/ when i18n is configured.
const autoStaticPages = [
'index',
'home/a',
'home/b',
'dynamic/static',
'dynamic/[id]',
'[teamId]/[slug]',
]
it('should not produce non-locale-prefixed HTML files for auto-static pages', () => {
const pagesDir = path.join(next.testDir, '.next/server/pages')
for (const page of autoStaticPages) {
const orphanPath = path.join(pagesDir, `${page}.html`)
expect({
page,
exists: fs.existsSync(orphanPath),
}).toEqual({ page, exists: false })
}
})
it('should have locale-prefixed HTML files for auto-static pages', () => {
const pagesDir = path.join(next.testDir, '.next/server/pages')
for (const page of autoStaticPages) {
for (const locale of locales) {
const localePath =
page === 'index'
? path.join(pagesDir, `${locale}.html`)
: path.join(pagesDir, locale, `${page}.html`)
expect({
page: `${locale}/${page}`,
exists: fs.existsSync(localePath),
}).toEqual({ page: `${locale}/${page}`, exists: true })
}
}
})
it('should 404 for /rewrite-before-files', async () => {
// beforeFiles rewrites /rewrite-before-files to /somewhere.
// /somewhere does not match any page, so this should 404.
// Before the fix, orphan [teamId]/[slug].html would incorrectly match.
const res = await next.fetch('/rewrite-before-files')
expect(res.status).toBe(404)
})
})
import { NextResponse } from 'next/server'
export function middleware(request) {
return NextResponse.next()
}
module.exports = {
i18n: {
locales: ['en', 'fr'],
defaultLocale: 'en',
},
rewrites() {
return {
beforeFiles: [
{
source: '/rewrite-before-files',
destination: '/somewhere',
},
],
afterFiles: [],
}
},
}
export default function Page() {
return <p>/[teamId]/[slug]</p>
}
export default function Page() {
return <p>dynamic route</p>
}
export default function Page() {
return <p>static route</p>
}
export default function Page() {
return <p>Home A</p>
}
export default function Page() {
return <p>Home B</p>
}
export default function Page() {
return <p>index</p>
}
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