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
639dbbd3
Unverified
Commit
639dbbd3
authored
Mar 05, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Mar 05, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Use new Redbox matchers in pages/ middleware-errors (#76797)
parent
51ffc255
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
186 additions
and
26 deletions
+186
-26
index.test.ts
test/development/middleware-errors/index.test.ts
+186
-26
No files found.
test/development/middleware-errors/index.test.ts
View file @
639dbbd3
import
{
import
{
assertNoRedbox
,
check
,
retry
}
from
'next-test-utils'
assertHasRedbox
,
assertNoRedbox
,
check
,
getRedboxDescription
,
getRedboxSource
,
retry
,
}
from
'next-test-utils'
import
stripAnsi
from
'strip-ansi'
import
stripAnsi
from
'strip-ansi'
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
nextTestSetup
}
from
'e2e-utils'
...
@@ -57,8 +50,42 @@ describe('middleware - development errors', () => {
...
@@ -57,8 +50,42 @@ describe('middleware - development errors', () => {
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
assertHasRedbox
(
browser
)
if
(
isTurbopack
)
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: boom",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:15) @
{default export}
> 3 | throw new Error('boom')
| ^",
"stack": [
"{default export} middleware.js (3:15)",
],
}
`
)
}
else
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: boom",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:15) @ default
> 3 | throw new Error('boom')
| ^",
"stack": [
"default middleware.js (3:15)",
],
}
`
)
}
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
assertNoRedbox
(
browser
)
await
assertNoRedbox
(
browser
)
})
})
})
})
...
@@ -173,11 +200,44 @@ describe('middleware - development errors', () => {
...
@@ -173,11 +200,44 @@ describe('middleware - development errors', () => {
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
assertHasRedbox
(
browser
)
const
lengthOfLogs
=
next
.
cliOutput
.
length
if
(
isTurbopack
)
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "ReferenceError: test is not defined",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (4:9) @ eval
> 4 | eval('test')
| ^",
"stack": [
"eval middleware.js (4:9)",
"<unknown> middleware.js (4:9)",
"{default export} middleware.js (3:22)",
],
}
`
)
}
else
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "ReferenceError: test is not defined",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (4:9) @ eval
> 4 | eval('test')
| ^",
"stack": [
"<FIXME-file-protocol>",
"eval middleware.js (4:9)",
"default middleware.js (4:9)",
],
}
`
)
}
expect
(
await
getRedboxSource
(
browser
)).
toContain
(
`eval('test')`
)
const
lengthOfLogs
=
next
.
cliOutput
.
length
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
retry
(()
=>
{
retry
(()
=>
{
...
@@ -225,12 +285,50 @@ describe('middleware - development errors', () => {
...
@@ -225,12 +285,50 @@ describe('middleware - development errors', () => {
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
assertHasRedbox
(
browser
)
const
source
=
await
getRedboxSource
(
browser
)
if
(
isTurbopack
)
{
expect
(
source
).
toContain
(
`throw new Error('booooom!')`
)
await
expect
(
browser
).
toDisplayRedbox
(
`
expect
(
source
).
toContain
(
'middleware.js'
)
{
expect
(
source
).
not
.
toContain
(
'//middleware.js'
)
"count": 1,
"description": "Error: booooom!",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:13) @ [project]/middleware.js [middleware-edge] (ecmascript)
> 3 | throw new Error('booooom!')
| ^",
"stack": [
"[project]/middleware.js [middleware-edge] (ecmascript) middleware.js (3:13)",
],
}
`
)
}
else
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: booooom!",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:13) @ eval
> 3 | throw new Error('booooom!')
| ^",
"stack": [
"<unknown> middleware.js (3:0)",
"eval middleware.js (3:13)",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
],
}
`
)
}
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
assertNoRedbox
(
browser
)
await
assertNoRedbox
(
browser
)
})
})
})
})
...
@@ -330,18 +428,43 @@ describe('middleware - development errors', () => {
...
@@ -330,18 +428,43 @@ describe('middleware - development errors', () => {
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
assertHasRedbox
(
browser
)
const
description
=
await
getRedboxDescription
(
browser
)
if
(
isTurbopack
)
{
if
(
isTurbopack
)
{
expect
(
description
).
toMatchInlineSnapshot
(
await
expect
(
browser
).
toDisplayRedbox
(
`
`"Parsing ecmascript source code failed"`
{
)
"count": 1,
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./middleware.js (1:28)
Parsing ecmascript source code failed
> 1 | export default function () }
| ^",
"stack": [],
}
`
)
}
else
{
}
else
{
expect
(
description
).
toMatchInlineSnapshot
(
await
expect
(
browser
).
toDisplayRedbox
(
`
`"Error: x Expected '{', got '}'"`
{
)
"count": 1,
"description": "Error: x Expected '{', got '}'",
"environmentLabel": null,
"label": "Build Error",
"source": "./middleware.js
Error: x Expected '{', got '}'
,----
1 | export default function () }
: ^
\`----
Caused by:
Syntax Error",
"stack": [],
}
`
)
}
}
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
assertNoRedbox
(
browser
)
await
assertNoRedbox
(
browser
)
expect
(
await
browser
.
elementByCss
(
'#page-title'
)).
toBeTruthy
()
expect
(
await
browser
.
elementByCss
(
'#page-title'
)).
toBeTruthy
()
})
})
...
@@ -369,10 +492,47 @@ describe('middleware - development errors', () => {
...
@@ -369,10 +492,47 @@ describe('middleware - development errors', () => {
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
it
(
'renders the error correctly and recovers'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
const
browser
=
await
next
.
browser
(
'/'
)
await
assertNoRedbox
(
browser
)
await
assertNoRedbox
(
browser
)
await
next
.
patchFile
(
'middleware.js'
,
`export default function () }`
)
await
next
.
patchFile
(
'middleware.js'
,
`export default function () }`
)
await
assertHasRedbox
(
browser
)
if
(
isTurbopack
)
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./middleware.js (1:28)
Parsing ecmascript source code failed
> 1 | export default function () }
| ^",
"stack": [],
}
`
)
}
else
{
await
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 1,
"description": "Error: x Expected '{', got '}'",
"environmentLabel": null,
"label": "Build Error",
"source": "./middleware.js
Error: x Expected '{', got '}'
,----
1 | export default function () }
: ^
\`----
Caused by:
Syntax Error",
"stack": [],
}
`
)
}
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
next
.
patchFile
(
'middleware.js'
,
`export default function () {}`
)
await
assertNoRedbox
(
browser
)
await
assertNoRedbox
(
browser
)
expect
(
await
browser
.
elementByCss
(
'#page-title'
)).
toBeTruthy
()
expect
(
await
browser
.
elementByCss
(
'#page-title'
)).
toBeTruthy
()
})
})
...
...
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