Unverified Commit 01888dcb authored by Damien Simonin Feugas's avatar Damien Simonin Feugas Committed by GitHub

chore: restores removed tests (#39452)

### 📖 What's in there?

As part of the 4 hands work done in #39397, we accidentally removed a describe for middleware "using a single matcher with i18n" (and no base path nor trailing slash).

This PR restores it.

### 🧪 How to test?

```
pnpm testheadless --testPathPattern middleware-matcher
```

### 🆙 Note to reviewers

There's only a couple lines with meaningful change in this PR. Hide whitespaces in github's diff screen to find it more easily: https://github.com/vercel/next.js/pull/39452/files?diff=split&w=1
parent b899d01f
...@@ -322,14 +322,15 @@ describe('using root matcher', () => { ...@@ -322,14 +322,15 @@ describe('using root matcher', () => {
}) })
}) })
describe.each([{ title: ' and trailingSlash', trailingSlash: true }])( describe.each([
'using a single matcher with i18n$title', { title: '' },
({ trailingSlash }) => { { title: ' and trailingSlash', trailingSlash: true },
let next: NextInstance ])('using a single matcher with i18n$title', ({ trailingSlash }) => {
beforeAll(async () => { let next: NextInstance
next = await createNext({ beforeAll(async () => {
files: { next = await createNext({
'pages/index.js': ` files: {
'pages/index.js': `
export default function Page({ message }) { export default function Page({ message }) {
return <div> return <div>
<p>{message}</p> <p>{message}</p>
...@@ -339,7 +340,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])( ...@@ -339,7 +340,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
props: { message: \`(\${locale}) Hello from /\` } props: { message: \`(\${locale}) Hello from /\` }
}) })
`, `,
'pages/[...route].js': ` 'pages/[...route].js': `
export default function Page({ message }) { export default function Page({ message }) {
return <div> return <div>
<p>catchall page</p> <p>catchall page</p>
...@@ -350,7 +351,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])( ...@@ -350,7 +351,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
props: { message: \`(\${locale}) Hello from /\` + params.route.join("/") } props: { message: \`(\${locale}) Hello from /\` + params.route.join("/") }
}) })
`, `,
'middleware.js': ` 'middleware.js': `
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
export const config = { matcher: '/' }; export const config = { matcher: '/' };
export default (req) => { export default (req) => {
...@@ -359,7 +360,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])( ...@@ -359,7 +360,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
return res; return res;
} }
`, `,
'next.config.js': ` 'next.config.js': `
module.exports = { module.exports = {
${trailingSlash ? 'trailingSlash: true,' : ''} ${trailingSlash ? 'trailingSlash: true,' : ''}
i18n: { i18n: {
...@@ -369,59 +370,58 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])( ...@@ -369,59 +370,58 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
} }
} }
`, `,
}, },
dependencies: {}, dependencies: {},
})
}) })
afterAll(() => next.destroy()) })
afterAll(() => next.destroy())
it(`adds the header for a matched path`, async () => { it(`adds the header for a matched path`, async () => {
const res1 = await fetchViaHTTP(next.url, `/`) const res1 = await fetchViaHTTP(next.url, `/`)
expect(await res1.text()).toContain(`(en) Hello from /`) expect(await res1.text()).toContain(`(en) Hello from /`)
expect(res1.headers.get('X-From-Middleware')).toBe('true') expect(res1.headers.get('X-From-Middleware')).toBe('true')
const res2 = await fetchViaHTTP(next.url, `/es`) const res2 = await fetchViaHTTP(next.url, `/es`)
expect(await res2.text()).toContain(`(es) Hello from /`) expect(await res2.text()).toContain(`(es) Hello from /`)
expect(res2.headers.get('X-From-Middleware')).toBe('true') expect(res2.headers.get('X-From-Middleware')).toBe('true')
}) })
it('adds the header for a mathed root path with /index', async () => { it('adds the header for a mathed root path with /index', async () => {
const res1 = await fetchViaHTTP(next.url, `/index`) const res1 = await fetchViaHTTP(next.url, `/index`)
expect(await res1.text()).toContain(`(en) Hello from /`) expect(await res1.text()).toContain(`(en) Hello from /`)
expect(res1.headers.get('X-From-Middleware')).toBe('true') expect(res1.headers.get('X-From-Middleware')).toBe('true')
const res2 = await fetchViaHTTP(next.url, `/es/index`) const res2 = await fetchViaHTTP(next.url, `/es/index`)
expect(await res2.text()).toContain(`(es) Hello from /`) expect(await res2.text()).toContain(`(es) Hello from /`)
expect(res2.headers.get('X-From-Middleware')).toBe('true') expect(res2.headers.get('X-From-Middleware')).toBe('true')
}) })
it(`adds the headers for a matched data path`, async () => { it(`adds the headers for a matched data path`, async () => {
const res1 = await fetchViaHTTP( const res1 = await fetchViaHTTP(
next.url, next.url,
`/_next/data/${next.buildId}/en.json`, `/_next/data/${next.buildId}/en.json`,
undefined, undefined,
{ headers: { 'x-nextjs-data': '1' } } { headers: { 'x-nextjs-data': '1' } }
) )
expect(await res1.json()).toMatchObject({ expect(await res1.json()).toMatchObject({
pageProps: { message: `(en) Hello from /` }, pageProps: { message: `(en) Hello from /` },
})
expect(res1.headers.get('X-From-Middleware')).toBe('true')
const res2 = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}/es.json`,
undefined
)
expect(await res2.json()).toMatchObject({
pageProps: { message: `(es) Hello from /` },
})
expect(res2.headers.get('X-From-Middleware')).toBe('true')
}) })
expect(res1.headers.get('X-From-Middleware')).toBe('true')
it(`does not add the header for an unmatched path`, async () => { const res2 = await fetchViaHTTP(
const response = await fetchViaHTTP(next.url, `/about/me`) next.url,
expect(await response.text()).toContain('Hello from /about/me') `/_next/data/${next.buildId}/es.json`,
expect(response.headers.get('X-From-Middleware')).toBeNull() undefined
)
expect(await res2.json()).toMatchObject({
pageProps: { message: `(es) Hello from /` },
}) })
} expect(res2.headers.get('X-From-Middleware')).toBe('true')
) })
it(`does not add the header for an unmatched path`, async () => {
const response = await fetchViaHTTP(next.url, `/about/me`)
expect(await response.text()).toContain('Hello from /about/me')
expect(response.headers.get('X-From-Middleware')).toBeNull()
})
})
describe.each([ describe.each([
{ title: '' }, { title: '' },
......
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