From 9832f6c1dcedee7d7e75666f635c24adaa8f9ead Mon Sep 17 00:00:00 2001 From: feugy Date: Wed, 10 Aug 2022 10:54:23 +0200 Subject: [PATCH] chore: restores removed tests --- test/e2e/middleware-matcher/index.test.ts | 116 +++++++++++----------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/test/e2e/middleware-matcher/index.test.ts b/test/e2e/middleware-matcher/index.test.ts index d31d2e37aba9..812e19c69475 100644 --- a/test/e2e/middleware-matcher/index.test.ts +++ b/test/e2e/middleware-matcher/index.test.ts @@ -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

{message}

@@ -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

catchall page

@@ -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) => { @@ -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: { @@ -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: '' },