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
c02bca23
Unverified
Commit
c02bca23
authored
Feb 17, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Feb 17, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Current behavior for `reportError` (#76115)
parent
a7511f53
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
16 deletions
+119
-16
index.test.ts
test/development/pages-dir/client-navigation/index.test.ts
+73
-10
index.test.ts
test/e2e/app-dir/errors/index.test.ts
+44
-4
turbopack-dev-tests-manifest.json
test/turbopack-dev-tests-manifest.json
+2
-2
No files found.
test/development/pages-dir/client-navigation/index.test.ts
View file @
c02bca23
...
@@ -9,7 +9,7 @@ import {
...
@@ -9,7 +9,7 @@ import {
waitFor
,
waitFor
,
check
,
check
,
}
from
'next-test-utils'
}
from
'next-test-utils'
import
webdriver
from
'next-webdriver'
import
webdriver
,
{
BrowserInterface
}
from
'next-webdriver'
import
path
from
'path'
import
path
from
'path'
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
nextTestSetup
}
from
'e2e-utils'
...
@@ -56,12 +56,25 @@ describe('Client Navigation', () => {
...
@@ -56,12 +56,25 @@ describe('Client Navigation', () => {
await
browser
.
close
()
await
browser
.
close
()
})
})
it
(
'should have proper error when no children are provided'
,
async
()
=>
{
it
(
'should have a redbox when no children are provided'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
appPort
,
'/link-no-child'
)
const
pageErrors
:
unknown
[]
=
[]
const
browser
=
await
webdriver
(
next
.
appPort
,
'/link-no-child'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
})
await
assertHasRedbox
(
browser
)
await
assertHasRedbox
(
browser
)
expect
(
await
getRedboxHeader
(
browser
)).
toContain
(
expect
(
await
getRedboxHeader
(
browser
)).
toContain
(
'No children were passed to <Link> with `href` of `/about` but one child is required'
'No children were passed to <Link> with `href` of `/about` but one child is required'
)
)
expect
(
pageErrors
).
toEqual
([
expect
.
objectContaining
({
message
:
'No children were passed to <Link> with `href` of `/about` but one child is required https://nextjs.org/docs/messages/link-no-children'
,
}),
])
})
})
it
(
'should not throw error when one number type child is provided'
,
async
()
=>
{
it
(
'should not throw error when one number type child is provided'
,
async
()
=>
{
...
@@ -277,15 +290,28 @@ describe('Client Navigation', () => {
...
@@ -277,15 +290,28 @@ describe('Client Navigation', () => {
})
})
describe
(
'with empty getInitialProps()'
,
()
=>
{
describe
(
'with empty getInitialProps()'
,
()
=>
{
it
(
'should render a
n error
'
,
async
()
=>
{
it
(
'should render a
redbox
'
,
async
()
=>
{
let
browser
let
browser
:
BrowserInterface
try
{
try
{
browser
=
await
webdriver
(
next
.
appPort
,
'/nav'
)
const
pageErrors
:
unknown
[]
=
[]
browser
=
await
webdriver
(
next
.
appPort
,
'/nav'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
})
await
browser
.
elementByCss
(
'#empty-props'
).
click
()
await
browser
.
elementByCss
(
'#empty-props'
).
click
()
await
assertHasRedbox
(
browser
)
await
assertHasRedbox
(
browser
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
/should resolve to an object
\.
But found "null" instead
\.
/
/should resolve to an object
\.
But found "null" instead
\.
/
)
)
expect
(
pageErrors
).
toEqual
([
expect
.
objectContaining
({
message
:
'"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.'
,
}),
])
}
finally
{
}
finally
{
if
(
browser
)
{
if
(
browser
)
{
await
browser
.
close
()
await
browser
.
close
()
...
@@ -1377,13 +1403,39 @@ describe('Client Navigation', () => {
...
@@ -1377,13 +1403,39 @@ describe('Client Navigation', () => {
describe
(
'runtime errors'
,
()
=>
{
describe
(
'runtime errors'
,
()
=>
{
it
(
'should show redbox when a client side error is thrown inside a component'
,
async
()
=>
{
it
(
'should show redbox when a client side error is thrown inside a component'
,
async
()
=>
{
let
browser
const
isReact18
=
process
.
env
.
NEXT_TEST_REACT_VERSION
?.
startsWith
(
'18'
)
let
browser
:
BrowserInterface
try
{
try
{
browser
=
await
webdriver
(
next
.
appPort
,
'/error-inside-browser-page'
)
const
pageErrors
:
unknown
[]
=
[]
browser
=
await
webdriver
(
next
.
appPort
,
'/error-inside-browser-page'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
})
await
assertHasRedbox
(
browser
)
await
assertHasRedbox
(
browser
)
const
text
=
await
getRedboxSource
(
browser
)
const
text
=
await
getRedboxSource
(
browser
)
expect
(
text
).
toMatch
(
/An Expected error occurred/
)
expect
(
text
).
toMatch
(
/An Expected error occurred/
)
expect
(
text
).
toMatch
(
/pages
[\\/]
error-inside-browser-page
\.
js
\(
5:13
\)
/
)
expect
(
text
).
toMatch
(
/pages
[\\/]
error-inside-browser-page
\.
js
\(
5:13
\)
/
)
expect
(
pageErrors
).
toEqual
(
isReact18
?
[
expect
.
objectContaining
({
message
:
'An Expected error occurred'
,
}),
expect
.
objectContaining
({
message
:
'An Expected error occurred'
,
}),
expect
.
objectContaining
({
message
:
'There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.'
,
}),
]
:
// TODO(veil): Should contain thrown error
[]
)
}
finally
{
}
finally
{
if
(
browser
)
{
if
(
browser
)
{
await
browser
.
close
()
await
browser
.
close
()
...
@@ -1392,16 +1444,27 @@ describe('Client Navigation', () => {
...
@@ -1392,16 +1444,27 @@ describe('Client Navigation', () => {
})
})
it
(
'should show redbox when a client side error is thrown outside a component'
,
async
()
=>
{
it
(
'should show redbox when a client side error is thrown outside a component'
,
async
()
=>
{
let
browser
let
browser
:
BrowserInterface
try
{
try
{
const
pageErrors
:
unknown
[]
=
[]
browser
=
await
webdriver
(
browser
=
await
webdriver
(
next
.
appPort
,
next
.
appPort
,
'/error-in-the-browser-global-scope'
'/error-in-the-browser-global-scope'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
}
)
)
await
assertHasRedbox
(
browser
)
await
assertHasRedbox
(
browser
)
const
text
=
await
getRedboxSource
(
browser
)
const
text
=
await
getRedboxSource
(
browser
)
expect
(
text
).
toMatch
(
/An Expected error occurred/
)
expect
(
text
).
toMatch
(
/An Expected error occurred/
)
expect
(
text
).
toMatch
(
/error-in-the-browser-global-scope
\.
js
\(
2:9
\)
/
)
expect
(
text
).
toMatch
(
/error-in-the-browser-global-scope
\.
js
\(
2:9
\)
/
)
expect
(
pageErrors
).
toEqual
([
expect
.
objectContaining
({
message
:
'An Expected error occurred'
}),
])
}
finally
{
}
finally
{
if
(
browser
)
{
if
(
browser
)
{
await
browser
.
close
()
await
browser
.
close
()
...
...
test/e2e/app-dir/errors/index.test.ts
View file @
c02bca23
...
@@ -14,7 +14,14 @@ describe('app-dir - errors', () => {
...
@@ -14,7 +14,14 @@ describe('app-dir - errors', () => {
describe
(
'error component'
,
()
=>
{
describe
(
'error component'
,
()
=>
{
it
(
'should trigger error component when an error happens during rendering'
,
async
()
=>
{
it
(
'should trigger error component when an error happens during rendering'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/client-component'
)
const
pageErrors
:
unknown
[]
=
[]
const
browser
=
await
next
.
browser
(
'/client-component'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
})
await
browser
.
elementByCss
(
'#error-trigger-button'
).
click
()
await
browser
.
elementByCss
(
'#error-trigger-button'
).
click
()
if
(
isNextDev
)
{
if
(
isNextDev
)
{
...
@@ -27,10 +34,20 @@ describe('app-dir - errors', () => {
...
@@ -27,10 +34,20 @@ describe('app-dir - errors', () => {
await
browser
.
waitForElementByCss
(
'#error-boundary-message'
).
text
()
await
browser
.
waitForElementByCss
(
'#error-boundary-message'
).
text
()
).
toBe
(
'An error occurred: this is a test'
)
).
toBe
(
'An error occurred: this is a test'
)
}
}
// Handled by custom error boundary.
expect
(
pageErrors
).
toEqual
([])
})
})
it
(
'should trigger error component when an error happens during server components rendering'
,
async
()
=>
{
it
(
'should trigger error component when an error happens during server components rendering'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/server-component'
)
const
pageErrors
:
unknown
[]
=
[]
const
browser
=
await
next
.
browser
(
'/server-component'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
})
expect
(
expect
(
await
browser
.
waitForElementByCss
(
'#error-boundary-message'
).
text
()
await
browser
.
waitForElementByCss
(
'#error-boundary-message'
).
text
()
...
@@ -49,6 +66,9 @@ describe('app-dir - errors', () => {
...
@@ -49,6 +66,9 @@ describe('app-dir - errors', () => {
// await assertHasRedbox(browser)
// await assertHasRedbox(browser)
// expect(await getRedboxHeader(browser)).toMatch(/this is a test/)
// expect(await getRedboxHeader(browser)).toMatch(/this is a test/)
}
}
// Handled by custom error boundary.
expect
(
pageErrors
).
toEqual
([])
})
})
it
(
'should preserve custom digests'
,
async
()
=>
{
it
(
'should preserve custom digests'
,
async
()
=>
{
...
@@ -143,7 +163,14 @@ describe('app-dir - errors', () => {
...
@@ -143,7 +163,14 @@ describe('app-dir - errors', () => {
})
})
it
(
'should use default error boundary for prod and overlay for dev when no error component specified'
,
async
()
=>
{
it
(
'should use default error boundary for prod and overlay for dev when no error component specified'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/global-error-boundary/client'
)
const
pageErrors
:
unknown
[]
=
[]
const
browser
=
await
next
.
browser
(
'/global-error-boundary/client'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
})
await
browser
.
elementByCss
(
'#error-trigger-button'
).
click
()
await
browser
.
elementByCss
(
'#error-trigger-button'
).
click
()
if
(
isNextDev
)
{
if
(
isNextDev
)
{
...
@@ -156,10 +183,20 @@ describe('app-dir - errors', () => {
...
@@ -156,10 +183,20 @@ describe('app-dir - errors', () => {
'Application error: a client-side exception has occurred while loading localhost (see the browser console for more information).'
'Application error: a client-side exception has occurred while loading localhost (see the browser console for more information).'
)
)
}
}
// FIXME(veil): Should contain thrown error.
expect
(
pageErrors
).
toEqual
([])
})
})
it
(
'should display error digest for error in server component with default error boundary'
,
async
()
=>
{
it
(
'should display error digest for error in server component with default error boundary'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/global-error-boundary/server'
)
const
pageErrors
:
unknown
[]
=
[]
const
browser
=
await
next
.
browser
(
'/global-error-boundary/server'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'pageerror'
,
(
error
:
unknown
)
=>
{
pageErrors
.
push
(
error
)
})
},
})
if
(
isNextDev
)
{
if
(
isNextDev
)
{
await
assertHasRedbox
(
browser
)
await
assertHasRedbox
(
browser
)
...
@@ -174,6 +211,9 @@ describe('app-dir - errors', () => {
...
@@ -174,6 +211,9 @@ describe('app-dir - errors', () => {
await
browser
.
waitForElementByCss
(
'body'
).
elementByCss
(
'p'
).
text
()
await
browser
.
waitForElementByCss
(
'body'
).
elementByCss
(
'p'
).
text
()
).
toMatch
(
/Digest:
\w
+/
)
).
toMatch
(
/Digest:
\w
+/
)
}
}
// FIXME(veil): Should contain thrown error.
expect
(
pageErrors
).
toEqual
([])
})
})
// production tests
// production tests
...
...
test/turbopack-dev-tests-manifest.json
View file @
c02bca23
...
@@ -3231,7 +3231,7 @@
...
@@ -3231,7 +3231,7 @@
"Client Navigation with 404 pages should should not contain a page script in a 404 page"
,
"Client Navigation with 404 pages should should not contain a page script in a 404 page"
,
"Client Navigation with <Link/> should call mouse handlers with an absolute url"
,
"Client Navigation with <Link/> should call mouse handlers with an absolute url"
,
"Client Navigation with <Link/> should error when calling onClick without event"
,
"Client Navigation with <Link/> should error when calling onClick without event"
,
"Client Navigation with <Link/> should have
proper error
when no children are provided"
,
"Client Navigation with <Link/> should have
a redbox
when no children are provided"
,
"Client Navigation with <Link/> should navigate an absolute local url"
,
"Client Navigation with <Link/> should navigate an absolute local url"
,
"Client Navigation with <Link/> should navigate an absolute local url with as"
,
"Client Navigation with <Link/> should navigate an absolute local url with as"
,
"Client Navigation with <Link/> should navigate an absolute url"
,
"Client Navigation with <Link/> should navigate an absolute url"
,
...
@@ -3261,7 +3261,7 @@
...
@@ -3261,7 +3261,7 @@
"Client Navigation with different types of urls should work with / page"
,
"Client Navigation with different types of urls should work with / page"
,
"Client Navigation with different types of urls should work with dir/ page"
,
"Client Navigation with different types of urls should work with dir/ page"
,
"Client Navigation with different types of urls should work with normal page"
,
"Client Navigation with different types of urls should work with normal page"
,
"Client Navigation with empty getInitialProps() should render a
n error
"
,
"Client Navigation with empty getInitialProps() should render a
redbox
"
,
"Client Navigation with getInitialProp redirect should redirect the page via client side"
,
"Client Navigation with getInitialProp redirect should redirect the page via client side"
,
"Client Navigation with getInitialProp redirect should redirect the page when loading"
,
"Client Navigation with getInitialProp redirect should redirect the page when loading"
,
"Client Navigation with hash changes check hydration mis-match should not have hydration mis-match for hash link"
,
"Client Navigation with hash changes check hydration mis-match should not have hydration mis-match for hash link"
,
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