Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
57c5e2a0
Unverified
Commit
57c5e2a0
authored
Jun 23, 2022
by
JJ Kasper
Committed by
GitHub
Jun 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update middleware matcher test for root (#37961)
parent
7bb247ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
middleware.js
test/e2e/middleware-matcher/app/middleware.js
+1
-0
index.test.ts
test/e2e/middleware-matcher/index.test.ts
+19
-4
No files found.
test/e2e/middleware-matcher/app/middleware.js
View file @
57c5e2a0
...
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
...
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
export
const
config
=
{
export
const
config
=
{
matcher
:
[
matcher
:
[
'/'
,
'/with-middleware/:path*'
,
'/with-middleware/:path*'
,
'/another-middleware/:path*'
,
'/another-middleware/:path*'
,
// the below is testing special characters don't break the build
// the below is testing special characters don't break the build
...
...
test/e2e/middleware-matcher/index.test.ts
View file @
57c5e2a0
...
@@ -15,9 +15,9 @@ describe('Middleware can set the matcher in its config', () => {
...
@@ -15,9 +15,9 @@ describe('Middleware can set the matcher in its config', () => {
})
})
afterAll
(()
=>
next
.
destroy
())
afterAll
(()
=>
next
.
destroy
())
it
(
'does
not
add the header for root request'
,
async
()
=>
{
it
(
'does add the header for root request'
,
async
()
=>
{
const
response
=
await
fetchViaHTTP
(
next
.
url
,
'/'
)
const
response
=
await
fetchViaHTTP
(
next
.
url
,
'/'
)
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBe
Null
(
)
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBe
(
'true'
)
expect
(
await
response
.
text
()).
toContain
(
'root page'
)
expect
(
await
response
.
text
()).
toContain
(
'root page'
)
})
})
...
@@ -65,7 +65,7 @@ describe('Middleware can set the matcher in its config', () => {
...
@@ -65,7 +65,7 @@ describe('Middleware can set the matcher in its config', () => {
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBe
(
'true'
)
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBe
(
'true'
)
})
})
it
(
'does
not
add the header for root data request'
,
async
()
=>
{
it
(
'does add the header for root data request'
,
async
()
=>
{
const
response
=
await
fetchViaHTTP
(
const
response
=
await
fetchViaHTTP
(
next
.
url
,
next
.
url
,
`/_next/data/
${
next
.
buildId
}
/index.json`
,
`/_next/data/
${
next
.
buildId
}
/index.json`
,
...
@@ -77,7 +77,7 @@ describe('Middleware can set the matcher in its config', () => {
...
@@ -77,7 +77,7 @@ describe('Middleware can set the matcher in its config', () => {
message
:
'Hello, world.'
,
message
:
'Hello, world.'
,
},
},
})
})
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBe
Null
(
)
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBe
(
'true'
)
})
})
it
(
'should load matches in client manifest correctly'
,
async
()
=>
{
it
(
'should load matches in client manifest correctly'
,
async
()
=>
{
...
@@ -173,6 +173,21 @@ describe('using a single matcher', () => {
...
@@ -173,6 +173,21 @@ describe('using a single matcher', () => {
})
})
afterAll
(()
=>
next
.
destroy
())
afterAll
(()
=>
next
.
destroy
())
it
(
'does not add the header for root request'
,
async
()
=>
{
const
response
=
await
fetchViaHTTP
(
next
.
url
,
'/'
)
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBeFalsy
()
})
it
(
'does not add the header for root data request'
,
async
()
=>
{
const
response
=
await
fetchViaHTTP
(
next
.
url
,
`/_next/data/
${
next
.
buildId
}
/index.json`
,
undefined
,
{
headers
:
{
'x-nextjs-data'
:
'1'
}
}
)
expect
(
response
.
headers
.
get
(
'X-From-Middleware'
)).
toBeFalsy
()
})
it
(
'adds the header for a matched path'
,
async
()
=>
{
it
(
'adds the header for a matched path'
,
async
()
=>
{
const
response
=
await
fetchViaHTTP
(
next
.
url
,
'/middleware/works'
)
const
response
=
await
fetchViaHTTP
(
next
.
url
,
'/middleware/works'
)
expect
(
await
response
.
text
()).
toContain
(
'Hello from /middleware/works'
)
expect
(
await
response
.
text
()).
toContain
(
'Hello from /middleware/works'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment