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
b60bb5e7
Unverified
Commit
b60bb5e7
authored
Feb 24, 2025
by
Michael Wenzel
Committed by
GitHub
Feb 24, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Testing] Update middleware/next-config tests to include search params (#76354)
parent
51984a96
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
config-testing-utils.test.ts
.../experimental/testing/server/config-testing-utils.test.ts
+21
-0
config-testing-utils.ts
...t/src/experimental/testing/server/config-testing-utils.ts
+5
-1
No files found.
packages/next/src/experimental/testing/server/config-testing-utils.test.ts
View file @
b60bb5e7
...
@@ -49,6 +49,27 @@ describe('config-testing-utils', () => {
...
@@ -49,6 +49,27 @@ describe('config-testing-utils', () => {
)
)
})
})
it
(
'handles redirect with query params'
,
async
()
=>
{
const
response
=
await
unstable_getResponseFromNextConfig
({
url
:
'https://nextjs.org/test/foo'
,
nextConfig
:
{
async
redirects
()
{
return
[
{
source
:
'/test/:slug'
,
destination
:
'/test2?slug=:slug'
,
permanent
:
true
,
},
]
},
},
})
expect
(
response
.
status
).
toEqual
(
308
)
expect
(
response
.
headers
.
get
(
'location'
)).
toEqual
(
'https://nextjs.org/test2?slug=foo'
)
})
it
(
"ignores redirect that doesn't match has"
,
async
()
=>
{
it
(
"ignores redirect that doesn't match has"
,
async
()
=>
{
const
response
=
await
unstable_getResponseFromNextConfig
({
const
response
=
await
unstable_getResponseFromNextConfig
({
url
:
'https://nextjs.org/test/foo'
,
url
:
'https://nextjs.org/test/foo'
,
...
...
packages/next/src/experimental/testing/server/config-testing-utils.ts
View file @
b60bb5e7
...
@@ -18,6 +18,7 @@ import type {
...
@@ -18,6 +18,7 @@ import type {
import
type
{
BaseNextRequest
}
from
'../../../server/base-http'
import
type
{
BaseNextRequest
}
from
'../../../server/base-http'
import
type
{
Params
}
from
'../../../server/request/params'
import
type
{
Params
}
from
'../../../server/request/params'
import
{
constructRequest
}
from
'./utils'
import
{
constructRequest
}
from
'./utils'
import
{
parsedUrlQueryToParams
}
from
'../../../server/route-modules/app-route/helpers/parsed-url-query-to-params'
/**
/**
* Tries to match the current request against the provided route. If there is
* Tries to match the current request against the provided route. If there is
...
@@ -122,8 +123,11 @@ export async function unstable_getResponseFromNextConfig({
...
@@ -122,8 +123,11 @@ export async function unstable_getResponseFromNextConfig({
params
,
params
,
query
:
parsedUrl
.
query
,
query
:
parsedUrl
.
query
,
})
})
const
searchParams
=
new
URLSearchParams
(
parsedUrlQueryToParams
(
parsedDestination
.
query
)
as
Record
<
string
,
string
>
)
return
new
URL
(
return
new
URL
(
newUrl
,
searchParams
.
size
>
0
?
`
${
newUrl
}
?
${
searchParams
.
toString
()}
`
:
newUrl
,
parsedDestination
.
hostname
parsedDestination
.
hostname
?
`
${
parsedDestination
.
protocol
}
//
${
parsedDestination
.
hostname
}
`
?
`
${
parsedDestination
.
protocol
}
//
${
parsedDestination
.
hostname
}
`
:
parsedUrl
.
host
:
parsedUrl
.
host
...
...
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