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
c61b479d
Unverified
Commit
c61b479d
authored
Apr 17, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Apr 17, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Improve coverage for fetch errors in Edge runtime (#78257)
parent
605126ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
20 deletions
+39
-20
fetch-failures-have-good-stack-traces-in-edge-runtime.test.ts
...h-failures-have-good-stack-traces-in-edge-runtime.test.ts
+37
-18
unknown-domain-no-await.ts
...aces-in-edge-runtime/pages/api/unknown-domain-no-await.ts
+2
-2
No files found.
test/e2e/fetch-failures-have-good-stack-traces-in-edge-runtime/fetch-failures-have-good-stack-traces-in-edge-runtime.test.ts
View file @
c61b479d
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
nextTestSetup
}
from
'e2e-utils'
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
import
{
import
{
check
}
from
'next-test-utils'
assertHasRedbox
,
getRedboxSource
,
getRedboxDescription
,
check
,
}
from
'next-test-utils'
import
stripAnsi
from
'strip-ansi'
import
stripAnsi
from
'strip-ansi'
describe
(
'fetch failures have good stack traces in edge runtime'
,
()
=>
{
describe
(
'fetch failures have good stack traces in edge runtime'
,
()
=>
{
const
{
next
,
isNextStart
,
isNextDev
,
skipped
}
=
nextTestSetup
({
const
{
isTurbopack
,
next
,
isNextStart
,
isNextDev
,
skipped
}
=
nextTestSetup
({
files
:
__dirname
,
files
:
__dirname
,
// don't have access to runtime logs on deploy
// don't have access to runtime logs on deploy
skipDeployment
:
true
,
skipDeployment
:
true
,
...
@@ -20,22 +15,46 @@ describe('fetch failures have good stack traces in edge runtime', () => {
...
@@ -20,22 +15,46 @@ describe('fetch failures have good stack traces in edge runtime', () => {
}
}
it
(
'when awaiting `fetch` using an unknown domain, stack traces are preserved'
,
async
()
=>
{
it
(
'when awaiting `fetch` using an unknown domain, stack traces are preserved'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
webdriver
(
next
.
url
,
'/api/unknown-domain'
)
const
browser
=
await
webdriver
(
next
.
url
,
'/api/unknown-domain'
)
if
(
isNextStart
)
{
if
(
isNextStart
)
{
expect
(
next
.
cliOutput
).
toMatch
(
/at.+
\/
pages
\/
api
\/
unknown-domain.js/
)
expect
(
next
.
cliOutput
.
slice
(
outputIndex
)).
toMatch
(
/at.+
\/
pages
\/
api
\/
unknown-domain.js/
)
}
else
if
(
isNextDev
)
{
}
else
if
(
isNextDev
)
{
// TODO(veil): Apply sourcemap
expect
(
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
))).
toContain
(
expect
(
next
.
cliOutput
).
toContain
(
'
\
n at anotherFetcher ('
)
''
+
'
\
n ⨯ Error [TypeError]: fetch failed'
+
'
\
n at anotherFetcher (src/fetcher.js:6:15)'
+
'
\
n at fetcher (src/fetcher.js:2:15)'
+
'
\
n at UnknownDomainEndpoint (pages/api/unknown-domain.js:6:16)'
+
'
\
n 4 |'
+
'
\
n 5 | async function anotherFetcher(...args) {'
+
'
\
n> 6 | return await fetch(...args)'
+
'
\
n | ^'
+
'
\
n 7 | }'
+
'
\
n 8 |'
+
// TODO(veil): Why double error?
'
\
n ⨯ Error [TypeError]: fetch failed'
)
await
assertHasRedbox
(
browser
)
// TODO(veil): Why column off by one?
const
source
=
await
getRedboxSource
(
browser
)
await
expect
(
browser
).
toDisplayRedbox
(
`
{
expect
(
source
).
toContain
(
'async function anotherFetcher(...args)'
)
"description": "TypeError: fetch failed",
expect
(
source
).
toContain
(
`fetch(...args)`
)
"environmentLabel": null,
"label": "Runtime Error",
const
description
=
await
getRedboxDescription
(
browser
)
"source": "src/fetcher.js (6:16) @ anotherFetcher
expect
(
description
).
toEqual
(
'TypeError: fetch failed'
)
> 6 | return await fetch(...args)
| ^",
"stack": [
"anotherFetcher src/fetcher.js (6:16)",
"fetcher src/fetcher.js (2:16)",
"UnknownDomainEndpoint pages/api/unknown-domain.js (6:
${
isTurbopack
?
15
:
16
}
)",
],
}
`
)
}
}
})
})
...
...
test/e2e/fetch-failures-have-good-stack-traces-in-edge-runtime/pages/api/unknown-domain-no-await.ts
View file @
c61b479d
export
const
config
=
{
runtime
:
'edge'
}
export
const
config
=
{
runtime
:
'edge'
}
export
default
async
function
UnknownDomainEndpoint
()
{
export
default
async
function
UnknownDomainEndpoint
()
{
fetch
(
'http://an.unknown.domain.nextjs'
).
catch
((
err
)
=>
{
fetch
(
'http://an.unknown.domain.nextjs'
).
catch
((
reason
)
=>
{
console
.
error
(
`stack is:`
,
err
.
stack
)
console
.
error
(
reason
)
})
})
return
new
Response
(
'okay.'
)
return
new
Response
(
'okay.'
)
...
...
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