Skip to content

Commit d5170eb

Browse files
authored
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.
1 parent 1fffbca commit d5170eb

File tree

4 files changed

+66
-60
lines changed

4 files changed

+66
-60
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-env jest */
2+
import path from 'path'
3+
import { nextTestSetup, FileRef } from 'e2e-utils'
4+
5+
describe('app dir - middleware with middleware in src dir', () => {
6+
const { next } = nextTestSetup({
7+
files: {
8+
'src/app': new FileRef(path.join(__dirname, 'app')),
9+
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
10+
'src/middleware.js': `
11+
import { NextResponse } from 'next/server'
12+
import { cookies } from 'next/headers'
13+
14+
export async function middleware(request) {
15+
const cookie = (await cookies()).get('test-cookie')
16+
return NextResponse.json({ cookie })
17+
}
18+
`,
19+
},
20+
})
21+
22+
it('works without crashing when using RequestStore', async () => {
23+
const browser = await next.browser('/')
24+
await browser.addCookie({
25+
name: 'test-cookie',
26+
value: 'test-cookie-response',
27+
})
28+
await browser.refresh()
29+
30+
const html = await browser.eval('document.documentElement.innerHTML')
31+
32+
expect(html).toContain('test-cookie-response')
33+
})
34+
})
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-env jest */
2+
import path from 'path'
3+
import { nextTestSetup, FileRef } from 'e2e-utils'
4+
5+
describe('app dir - middleware without pages dir', () => {
6+
const { next } = nextTestSetup({
7+
files: {
8+
app: new FileRef(path.join(__dirname, 'app')),
9+
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
10+
'middleware.js': `
11+
import { NextResponse } from 'next/server'
12+
13+
export async function middleware(request) {
14+
return new NextResponse('redirected')
15+
}
16+
17+
export const config = {
18+
matcher: '/headers'
19+
}
20+
`,
21+
},
22+
})
23+
24+
it('Updates headers', async () => {
25+
const html = await next.render('/headers')
26+
27+
expect(html).toContain('redirected')
28+
})
29+
})

test/e2e/app-dir/app-middleware/app-middleware.test.ts

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-env jest */
2-
import path from 'path'
32
import cheerio from 'cheerio'
43
import { check, retry, withQuery } from 'next-test-utils'
5-
import { nextTestSetup, FileRef } from 'e2e-utils'
4+
import { nextTestSetup } from 'e2e-utils'
65
import type { Response } from 'node-fetch'
76

87
describe('app-dir with middleware', () => {
@@ -272,61 +271,3 @@ describe('app-dir with middleware', () => {
272271
})
273272
}
274273
})
275-
276-
describe('app dir - middleware without pages dir', () => {
277-
const { next } = nextTestSetup({
278-
files: {
279-
app: new FileRef(path.join(__dirname, 'app')),
280-
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
281-
'middleware.js': `
282-
import { NextResponse } from 'next/server'
283-
284-
export async function middleware(request) {
285-
return new NextResponse('redirected')
286-
}
287-
288-
export const config = {
289-
matcher: '/headers'
290-
}
291-
`,
292-
},
293-
})
294-
295-
// eslint-disable-next-line jest/no-identical-title
296-
it('Updates headers', async () => {
297-
const html = await next.render('/headers')
298-
299-
expect(html).toContain('redirected')
300-
})
301-
})
302-
303-
describe('app dir - middleware with middleware in src dir', () => {
304-
const { next } = nextTestSetup({
305-
files: {
306-
'src/app': new FileRef(path.join(__dirname, 'app')),
307-
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
308-
'src/middleware.js': `
309-
import { NextResponse } from 'next/server'
310-
import { cookies } from 'next/headers'
311-
312-
export async function middleware(request) {
313-
const cookie = (await cookies()).get('test-cookie')
314-
return NextResponse.json({ cookie })
315-
}
316-
`,
317-
},
318-
})
319-
320-
it('works without crashing when using RequestStore', async () => {
321-
const browser = await next.browser('/')
322-
await browser.addCookie({
323-
name: 'test-cookie',
324-
value: 'test-cookie-response',
325-
})
326-
await browser.refresh()
327-
328-
const html = await browser.eval('document.documentElement.innerHTML')
329-
330-
expect(html).toContain('test-cookie-response')
331-
})
332-
})

test/experimental-tests-manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
"test/e2e/app-dir/app-inline-css/index.test.ts",
123123
"test/e2e/app-dir/app-invalid-revalidate/app-invalid-revalidate.test.ts",
124124
"test/e2e/app-dir/app-middleware/app-middleware.test.ts",
125+
"test/e2e/app-dir/app-middleware/app-middleware-in-src-dir.test.ts",
126+
"test/e2e/app-dir/app-middleware/app-middleware-without-pages-dir.test.ts",
125127
"test/e2e/app-dir/app-prefetch*/**/*",
126128
"test/e2e/app-dir/app-rendering/rendering.test.ts",
127129
"test/e2e/app-dir/app-root-params/generate-static-params.test.ts",

0 commit comments

Comments
 (0)