Skip to content

Commit

Permalink
chore: restores removed tests (#39452)
Browse files Browse the repository at this point in the history
### 📖 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
  • Loading branch information
feugy committed Aug 10, 2022
1 parent b899d01 commit 01888dc
Showing 1 changed file with 58 additions and 58 deletions.
116 changes: 58 additions & 58 deletions test/e2e/middleware-matcher/index.test.ts
Expand Up @@ -322,14 +322,15 @@ describe('using root matcher', () => {
})
})

describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
'using a single matcher with i18n$title',
({ trailingSlash }) => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
describe.each([
{ title: '' },
{ title: ' and trailingSlash', trailingSlash: true },
])('using a single matcher with i18n$title', ({ trailingSlash }) => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page({ message }) {
return <div>
<p>{message}</p>
Expand All @@ -339,7 +340,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
props: { message: \`(\${locale}) Hello from /\` }
})
`,
'pages/[...route].js': `
'pages/[...route].js': `
export default function Page({ message }) {
return <div>
<p>catchall page</p>
Expand All @@ -350,7 +351,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
props: { message: \`(\${locale}) Hello from /\` + params.route.join("/") }
})
`,
'middleware.js': `
'middleware.js': `
import { NextResponse } from 'next/server'
export const config = { matcher: '/' };
export default (req) => {
Expand All @@ -359,7 +360,7 @@ describe.each([{ title: ' and trailingSlash', trailingSlash: true }])(
return res;
}
`,
'next.config.js': `
'next.config.js': `
module.exports = {
${trailingSlash ? 'trailingSlash: true,' : ''}
i18n: {
Expand All @@ -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 () => {
const res1 = await fetchViaHTTP(next.url, `/`)
expect(await res1.text()).toContain(`(en) Hello from /`)
expect(res1.headers.get('X-From-Middleware')).toBe('true')
const res2 = await fetchViaHTTP(next.url, `/es`)
expect(await res2.text()).toContain(`(es) Hello from /`)
expect(res2.headers.get('X-From-Middleware')).toBe('true')
})
it(`adds the header for a matched path`, async () => {
const res1 = await fetchViaHTTP(next.url, `/`)
expect(await res1.text()).toContain(`(en) Hello from /`)
expect(res1.headers.get('X-From-Middleware')).toBe('true')
const res2 = await fetchViaHTTP(next.url, `/es`)
expect(await res2.text()).toContain(`(es) Hello from /`)
expect(res2.headers.get('X-From-Middleware')).toBe('true')
})

it('adds the header for a mathed root path with /index', async () => {
const res1 = await fetchViaHTTP(next.url, `/index`)
expect(await res1.text()).toContain(`(en) Hello from /`)
expect(res1.headers.get('X-From-Middleware')).toBe('true')
const res2 = await fetchViaHTTP(next.url, `/es/index`)
expect(await res2.text()).toContain(`(es) Hello from /`)
expect(res2.headers.get('X-From-Middleware')).toBe('true')
})
it('adds the header for a mathed root path with /index', async () => {
const res1 = await fetchViaHTTP(next.url, `/index`)
expect(await res1.text()).toContain(`(en) Hello from /`)
expect(res1.headers.get('X-From-Middleware')).toBe('true')
const res2 = await fetchViaHTTP(next.url, `/es/index`)
expect(await res2.text()).toContain(`(es) Hello from /`)
expect(res2.headers.get('X-From-Middleware')).toBe('true')
})

it(`adds the headers for a matched data path`, async () => {
const res1 = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}/en.json`,
undefined,
{ headers: { 'x-nextjs-data': '1' } }
)
expect(await res1.json()).toMatchObject({
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')
it(`adds the headers for a matched data path`, async () => {
const res1 = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}/en.json`,
undefined,
{ headers: { 'x-nextjs-data': '1' } }
)
expect(await res1.json()).toMatchObject({
pageProps: { message: `(en) Hello from /` },
})

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()
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')
})

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([
{ title: '' },
Expand Down

0 comments on commit 01888dc

Please sign in to comment.