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
df774690
Unverified
Commit
df774690
authored
Mar 04, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Mar 04, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Use new Redbox matchers in server-navigation-error (#76787)
parent
ab00c876
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
99 deletions
+109
-99
server-navigation-error.test.ts
...r/server-navigation-error/server-navigation-error.test.ts
+109
-99
No files found.
test/development/app-dir/server-navigation-error/server-navigation-error.test.ts
View file @
df774690
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
assertHasRedbox
,
getRedboxDescription
,
getRedboxSource
,
}
from
'next-test-utils'
describe
(
'server-navigation-error'
,
()
=>
{
const
{
isTurbopack
,
next
}
=
nextTestSetup
({
...
...
@@ -13,64 +8,74 @@ describe('server-navigation-error', () => {
describe
(
'pages router'
,
()
=>
{
it
(
'should error on navigation API redirect'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/pages/redirect'
)
await
assertHasRedbox
(
browser
)
expect
(
await
getRedboxDescription
(
browser
)).
toMatch
(
`Next.js navigation API is not allowed to be used in Pages Router.`
)
const
source
=
await
getRedboxSource
(
browser
)
if
(
isTurbopack
)
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"pages/pages/redirect.tsx (4:10) @ Page
2 |
3 | export default function Page() {
> 4 | redirect('/')
| ^
5 | }
6 |"
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if
(
isTurbopack
)
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/redirect.tsx (4:10) @ Page
> 4 | redirect('/')
| ^",
"stack": [
"Page pages/pages/redirect.tsx (4:10)",
],
}
`
)
}
else
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"pages/pages/redirect.tsx (4:11) @ Page
2 |
3 | export default function Page() {
> 4 | redirect('/')
| ^
5 | }
6 |"
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/redirect.tsx (4:11) @ Page
> 4 | redirect('/')
| ^",
"stack": [
"Page pages/pages/redirect.tsx (4:11)",
],
}
`
)
}
})
it
(
'should error on navigation API notFound'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/pages/not-found'
)
await
assertHasRedbox
(
browser
)
expect
(
await
getRedboxDescription
(
browser
)).
toMatch
(
`Next.js navigation API is not allowed to be used in Pages Router.`
)
const
source
=
await
getRedboxSource
(
browser
)
if
(
isTurbopack
)
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"pages/pages/not-found.tsx (4:10) @ Page
2 |
3 | export default function Page() {
> 4 | notFound()
| ^
5 | }
6 |"
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if
(
isTurbopack
)
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/not-found.tsx (4:10) @ Page
> 4 | notFound()
| ^",
"stack": [
"Page pages/pages/not-found.tsx (4:10)",
],
}
`
)
}
else
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"pages/pages/not-found.tsx (4:11) @ Page
2 |
3 | export default function Page() {
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Pages Router.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/pages/not-found.tsx (4:11) @ Page
> 4 | notFound()
| ^
5 | }
6 |"
| ^",
"stack": [
"Page pages/pages/not-found.tsx (4:11)",
],
}
`
)
}
})
...
...
@@ -81,69 +86,74 @@ describe('server-navigation-error', () => {
const
browser
=
await
next
.
browser
(
'/middleware/redirect'
)
// FIXME: the first request to middleware error load didn't show the redbox, need one more reload
await
browser
.
refresh
()
await
assertHasRedbox
(
browser
)
expect
(
await
getRedboxDescription
(
browser
)).
toMatch
(
`Next.js navigation API is not allowed to be used in Middleware.`
)
const
source
=
await
getRedboxSource
(
browser
)
if
(
isTurbopack
)
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"middleware.ts (8:12) @ middleware
6 | notFound()
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
> 8 | redirect('/')
| ^
9 | }
10 | }
11 |"
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if
(
isTurbopack
)
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (8:12) @ middleware
> 8 | redirect('/')
| ^",
"stack": [
"middleware middleware.ts (8:12)",
],
}
`
)
}
else
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"middleware.ts (8:13) @ middleware
6 | notFound()
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
> 8 | redirect('/')
| ^
9 | }
10 | }
11 |"
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (8:13) @ middleware
> 8 | redirect('/')
| ^",
"stack": [
"middleware middleware.ts (8:13)",
],
}
`
)
}
})
it
(
'should error on navigation API not-found'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/middleware/not-found'
)
await
assertHasRedbox
(
browser
)
expect
(
await
getRedboxDescription
(
browser
)).
toMatch
(
`Next.js navigation API is not allowed to be used in Middleware.`
)
const
source
=
await
getRedboxSource
(
browser
)
// TODO(veil): investigate the column number is off by 1 between turbo and webpack
if
(
isTurbopack
)
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"middleware.ts (6:12) @ middleware
4 | export default function middleware(req: NextRequest) {
5 | if (req.nextUrl.pathname === '/middleware/not-found') {
> 6 | notFound()
| ^
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
8 | redirect('/')
9 | }"
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (6:12) @ middleware
> 6 | notFound()
| ^",
"stack": [
"middleware middleware.ts (6:12)",
],
}
`
)
}
else
{
expect
(
source
).
toMatchInlineSnapshot
(
`
"middleware.ts (6:13) @ middleware
4 | export default function middleware(req: NextRequest) {
5 | if (req.nextUrl.pathname === '/middleware/not-found') {
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: Next.js navigation API is not allowed to be used in Middleware.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.ts (6:13) @ middleware
> 6 | notFound()
| ^
7 | } else if (req.nextUrl.pathname === '/middleware/redirect') {
8 | redirect('/')
9 | }"
| ^",
"stack": [
"middleware middleware.ts (6:13)",
],
}
`
)
}
})
...
...
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