Unverified Commit d5170ebd authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

test: split app-middleware test per describe (#84130)

A single test file is starting 3 next instances sequentially. This can be paralleled from different test files. This PR splits tests per "describe" and does not change its content.
parent 1fffbcac
/* eslint-env jest */
import path from 'path'
import { nextTestSetup, FileRef } from 'e2e-utils'
describe('app dir - middleware with middleware in src dir', () => {
const { next } = nextTestSetup({
files: {
'src/app': new FileRef(path.join(__dirname, 'app')),
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
'src/middleware.js': `
import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
export async function middleware(request) {
const cookie = (await cookies()).get('test-cookie')
return NextResponse.json({ cookie })
}
`,
},
})
it('works without crashing when using RequestStore', async () => {
const browser = await next.browser('/')
await browser.addCookie({
name: 'test-cookie',
value: 'test-cookie-response',
})
await browser.refresh()
const html = await browser.eval('document.documentElement.innerHTML')
expect(html).toContain('test-cookie-response')
})
})
/* eslint-env jest */
import path from 'path'
import { nextTestSetup, FileRef } from 'e2e-utils'
describe('app dir - middleware without pages dir', () => {
const { next } = nextTestSetup({
files: {
app: new FileRef(path.join(__dirname, 'app')),
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
'middleware.js': `
import { NextResponse } from 'next/server'
export async function middleware(request) {
return new NextResponse('redirected')
}
export const config = {
matcher: '/headers'
}
`,
},
})
it('Updates headers', async () => {
const html = await next.render('/headers')
expect(html).toContain('redirected')
})
})
/* eslint-env jest */ /* eslint-env jest */
import path from 'path'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { check, retry, withQuery } from 'next-test-utils' import { check, retry, withQuery } from 'next-test-utils'
import { nextTestSetup, FileRef } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import type { Response } from 'node-fetch' import type { Response } from 'node-fetch'
describe('app-dir with middleware', () => { describe('app-dir with middleware', () => {
...@@ -272,61 +271,3 @@ describe('app-dir with middleware', () => { ...@@ -272,61 +271,3 @@ describe('app-dir with middleware', () => {
}) })
} }
}) })
describe('app dir - middleware without pages dir', () => {
const { next } = nextTestSetup({
files: {
app: new FileRef(path.join(__dirname, 'app')),
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
'middleware.js': `
import { NextResponse } from 'next/server'
export async function middleware(request) {
return new NextResponse('redirected')
}
export const config = {
matcher: '/headers'
}
`,
},
})
// eslint-disable-next-line jest/no-identical-title
it('Updates headers', async () => {
const html = await next.render('/headers')
expect(html).toContain('redirected')
})
})
describe('app dir - middleware with middleware in src dir', () => {
const { next } = nextTestSetup({
files: {
'src/app': new FileRef(path.join(__dirname, 'app')),
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
'src/middleware.js': `
import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
export async function middleware(request) {
const cookie = (await cookies()).get('test-cookie')
return NextResponse.json({ cookie })
}
`,
},
})
it('works without crashing when using RequestStore', async () => {
const browser = await next.browser('/')
await browser.addCookie({
name: 'test-cookie',
value: 'test-cookie-response',
})
await browser.refresh()
const html = await browser.eval('document.documentElement.innerHTML')
expect(html).toContain('test-cookie-response')
})
})
...@@ -122,6 +122,8 @@ ...@@ -122,6 +122,8 @@
"test/e2e/app-dir/app-inline-css/index.test.ts", "test/e2e/app-dir/app-inline-css/index.test.ts",
"test/e2e/app-dir/app-invalid-revalidate/app-invalid-revalidate.test.ts", "test/e2e/app-dir/app-invalid-revalidate/app-invalid-revalidate.test.ts",
"test/e2e/app-dir/app-middleware/app-middleware.test.ts", "test/e2e/app-dir/app-middleware/app-middleware.test.ts",
"test/e2e/app-dir/app-middleware/app-middleware-in-src-dir.test.ts",
"test/e2e/app-dir/app-middleware/app-middleware-without-pages-dir.test.ts",
"test/e2e/app-dir/app-prefetch*/**/*", "test/e2e/app-dir/app-prefetch*/**/*",
"test/e2e/app-dir/app-rendering/rendering.test.ts", "test/e2e/app-dir/app-rendering/rendering.test.ts",
"test/e2e/app-dir/app-root-params/generate-static-params.test.ts", "test/e2e/app-dir/app-root-params/generate-static-params.test.ts",
......
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