Skip to content

Commit 24b0b1d

Browse files
committed
Fix existing tests
1 parent 60b49b3 commit 24b0b1d

File tree

7 files changed

+74
-3
lines changed

7 files changed

+74
-3
lines changed

test/e2e/middleware-general/app/middleware-node.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { getSomeData } from './lib/some-data'
44
import magicValue from 'shared-package'
55

66
export const config = {
7+
// Matcher needed to test internal routes /_next/ (skipped by default)
8+
matcher: [
9+
'/:path*',
10+
{
11+
source: '/_next/:path*',
12+
locale: false,
13+
},
14+
],
715
regions: 'auto',
816
runtime: 'nodejs',
917
}

test/e2e/middleware-general/app/middleware.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { getSomeData } from './lib/some-data'
44
import magicValue from 'shared-package'
55

66
export const config = {
7+
// Matcher needed to test internal routes /_next/ (skipped by default)
8+
matcher: [
9+
'/:path*',
10+
{
11+
source: '/_next/:path*',
12+
locale: false,
13+
},
14+
],
715
regions: 'auto',
816
}
917

test/e2e/middleware-general/test/index.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ describe('Middleware Runtime', () => {
201201
)
202202
const matchers = await res.json()
203203
expect(matchers).toEqual([
204-
{ regexp: '^/.*$', originalSource: '/:path*' },
204+
{
205+
regexp:
206+
'^(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/((?!_next\\/)[^/.]{1,}))(?:\\/((?:[^\\/#\\?]+?)(?:\\/(?:[^\\/#\\?]+?))*))?(\\.json)?[\\/#\\?]?$',
207+
originalSource: '/:path*',
208+
},
205209
])
206210
})
207211
}
@@ -228,7 +232,13 @@ describe('Middleware Runtime', () => {
228232
]),
229233
name: 'middleware',
230234
page: '/',
231-
matchers: [{ regexp: '^/.*$', originalSource: '/:path*' }],
235+
matchers: [
236+
{
237+
regexp:
238+
'^(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/((?!_next\\/)[^/.]{1,}))(?:\\/((?:[^\\/#\\?]+?)(?:\\/(?:[^\\/#\\?]+?))*))?(\\.json)?[\\/#\\?]?$',
239+
originalSource: '/:path*',
240+
},
241+
],
232242
wasm: [],
233243
assets: process.env.IS_TURBOPACK_TEST ? expect.toBeArray() : [],
234244
regions: 'auto',

test/e2e/middleware-trailing-slash/app/middleware.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,14 @@ const params = (url) => {
104104
}
105105
return result
106106
}
107+
108+
// Matcher needed to test internal routes /_next/ (skipped by default)
109+
export const config = {
110+
matcher: [
111+
'/:path*',
112+
{
113+
source: '/_next/:path*',
114+
locale: false,
115+
},
116+
],
117+
}

test/e2e/middleware-trailing-slash/test/index.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,19 @@ describe('Middleware Runtime trailing slash', () => {
122122
]),
123123
name: 'middleware',
124124
page: '/',
125-
matchers: [{ regexp: '^/.*$', originalSource: '/:path*' }],
125+
matchers: [
126+
{
127+
originalSource: '/:path*',
128+
regexp:
129+
'^(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/((?:[^\\/#\\?]+?)(?:\\/(?:[^\\/#\\?]+?))*))?(\\.json)?[\\/#\\?]?$',
130+
},
131+
{
132+
locale: false,
133+
originalSource: '/_next/:path*',
134+
regexp:
135+
'^(?:\\/(_next\\/data\\/[^/]{1,}))?\\/_next(?:\\/((?:[^\\/#\\?]+?)(?:\\/(?:[^\\/#\\?]+?))*))?(\\.json)?[\\/#\\?]?$',
136+
},
137+
],
126138
wasm: [],
127139
assets: process.env.IS_TURBOPACK_TEST ? expect.toBeArray() : [],
128140
})

test/e2e/skip-trailing-slash-redirect/app/middleware.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,14 @@ export default function handler(req) {
8787

8888
return NextResponse.next()
8989
}
90+
91+
// Matcher needed to test internal routes /_next/ (skipped by default)
92+
export const config = {
93+
matcher: [
94+
'/:path*',
95+
{
96+
source: '/_next/:path*',
97+
locale: false,
98+
},
99+
],
100+
}

test/integration/next-image-new/middleware/middleware.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ export async function middleware(request) {
88
console.log(`x-_next-image: ${request.nextUrl.searchParams.get('url')}`)
99
}
1010
}
11+
12+
// Matcher needed to test internal routes /_next/ (skipped by default)
13+
export const config = {
14+
matcher: [
15+
'/:path*',
16+
{
17+
source: '/_next/:path*',
18+
locale: false,
19+
},
20+
],
21+
}

0 commit comments

Comments
 (0)