Unverified Commit 0b7e96f4 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

test: cover dynamic APIs with i18n base path (#97367)

Recreation of https://github.com/vercel/next.js/pull/96910

### What?

Adds a test for i18n basepath fallbacks.

### Why?

We had this test in `vercel/vercel`:
https://github.com/vercel/vercel/blob/main/packages/next/test/fixtures/00-i18n-basepath-fallback-false-404/index.test.js

We're getting rid of it in favor of moving it to here in Next.js. This
new test is meant to be equivalent to the original.
Co-authored-by: 's avatarAnthony Shew <anthonyshew@gmail.com>
parent 6be68703
import { nextTestSetup } from 'e2e-utils'
describe('i18n-basepath-fallback-false-404', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it.each([
['/docs/api/blog/first', { slug: 'first' }],
['/docs/api/catchall/hello/world', { rest: ['hello', 'world'] }],
])('should resolve the dynamic API route %s', async (pathname, expected) => {
const res = await next.fetch(pathname)
expect(res.status).toBe(200)
expect(await res.json()).toEqual(expected)
})
})
module.exports = {
basePath: '/docs',
i18n: {
locales: ['en', 'fr'],
defaultLocale: 'en',
},
}
export default function NotFound() {
return 'not found page'
}
import type { NextApiRequest, NextApiResponse } from 'next'
export default function handler(req: NextApiRequest, res: NextApiResponse) {
res.json({ slug: req.query.slug })
}
import type { NextApiRequest, NextApiResponse } from 'next'
export default function handler(req: NextApiRequest, res: NextApiResponse) {
res.json({ rest: req.query.rest })
}
export default function Page() {
return 'dynamic page'
}
export function getStaticProps() {
return { props: {} }
}
export function getStaticPaths() {
return {
paths: [{ params: { slug: 'first' } }],
fallback: false,
}
}
export default function Page() {
return <p>hello world</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