Unverified Commit 2cf4ffee authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

more tests

parent 71a6fb90
...@@ -675,7 +675,13 @@ describe.each([ ...@@ -675,7 +675,13 @@ describe.each([
`, `,
'middleware.js': ` 'middleware.js': `
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
export const config = { matcher: '/' }; export const config = {
matcher: [
'/',
'/with-locale',
{ source: '/es/without-locale', locale: false },
],
};
export default (req) => { export default (req) => {
const res = NextResponse.next(); const res = NextResponse.next();
res.headers.set('X-From-Middleware', 'true'); res.headers.set('X-From-Middleware', 'true');
...@@ -697,6 +703,52 @@ describe.each([ ...@@ -697,6 +703,52 @@ describe.each([
dependencies: {}, dependencies: {},
}) })
it.each([
{ path: '/with-locale', locale: 'en', matched: true },
{ path: '/es/with-locale', locale: 'es', matched: true },
{ path: '/without-locale', locale: 'en', matched: false },
{ path: '/en/without-locale', locale: 'en', matched: false },
{ path: '/es/without-locale', locale: 'es', matched: true },
])(
'respects matcher locale settings for $path with basePath',
async ({ path, locale, matched }) => {
const response = await fetchViaHTTP(next.url, `/root${path}`)
expect(response.status).toBe(200)
expect(await response.text()).toContain(
`(${locale}) Hello from /${path.split('/').pop()}`
)
expect(response.headers.get('X-From-Middleware')).toBe(
matched ? 'true' : null
)
}
)
it.each([
{ path: 'en/with-locale', locale: 'en', matched: true },
{ path: 'es/with-locale', locale: 'es', matched: true },
{ path: 'en/without-locale', locale: 'en', matched: false },
{ path: 'es/without-locale', locale: 'es', matched: true },
])(
'respects matcher locale settings for the $path data route with basePath',
async ({ path, locale, matched }) => {
const response = await fetchViaHTTP(
next.url,
`/root/_next/data/${next.buildId}/${path}.json`,
undefined,
{ headers: { 'x-nextjs-data': '1' } }
)
expect(response.status).toBe(200)
expect(await response.json()).toMatchObject({
pageProps: {
message: `(${locale}) Hello from /${path.split('/').pop()}`,
},
})
expect(response.headers.get('X-From-Middleware')).toBe(
matched ? 'true' : null
)
}
)
it(`adds the header for a matched path`, async () => { it(`adds the header for a matched path`, async () => {
const res1 = await fetchViaHTTP(next.url, `/root`) const res1 = await fetchViaHTTP(next.url, `/root`)
expect(await res1.text()).toContain(`(en) Hello from /`) expect(await res1.text()).toContain(`(en) Hello from /`)
......
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