Files
next.js/test/e2e/fetch-failures-have-good-stack-traces-in-edge-runtime/fetch-failures-have-good-stack-traces-in-edge-runtime.test.ts
Tim NeutkensandGitHub e860cec656 test: migrate webdriver callers to next.browser (#93941)
### What?

Migrate remaining direct `next-webdriver` test callers that have a
`NextInstance` to `next.browser()`, and expose the shared `Playwright`
browser type from `e2e-utils`.

### Why?

`NextInstance.browser` should be the supported browser-opening interface
for test fixtures, with `next-webdriver` kept as the private
implementation detail.

### How?

Updated affected development, e2e, and production tests to call
`next.browser()` directly, passing `baseUrl` where tests intentionally
target a manually spawned or proxied server. Shared helpers now receive
browser callbacks from the test context, and browser types import
`Playwright` from `e2e-utils` instead of deriving from `next.browser` or
importing from private paths.

<!-- NEXT_JS_LLM_PR -->
2026-05-22 14:01:58 +02:00

77 lines
2.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
describe('fetch failures have good stack traces in edge runtime', () => {
const { next, isNextStart, isNextDev, skipped } = nextTestSetup({
files: __dirname,
// don't have access to runtime logs on deploy
skipDeployment: true,
})
if (skipped) {
return
}
// TODO: Failure is not specific to Turbopack, edge runtime errors don't have source maps applied.
;(process.env.IS_TURBOPACK_TEST && isNextStart ? it.skip : it)(
'when awaiting `fetch` using an unknown domain, stack traces are preserved',
async () => {
const outputIndex = next.cliOutput.length
const browser = await next.browser('/api/unknown-domain')
if (isNextStart) {
// eslint-disable-next-line jest/no-standalone-expect
expect(next.cliOutput.slice(outputIndex)).toMatch(
/at.+\/pages\/api\/unknown-domain.js/
)
} else if (isNextDev) {
// eslint-disable-next-line jest/no-standalone-expect
expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain(
'⨯ Error [TypeError]: fetch failed' +
'\n at anotherFetcher (src/fetcher.js:6:16)' +
'\n at fetcher (src/fetcher.js:2:16)' +
'\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'
)
// Turbopack produces incorrect mappings in the sourcemap.
// eslint-disable-next-line jest/no-standalone-expect
await expect(browser).toDisplayRedbox(`
{
"code": "E394",
"description": "fetch failed",
"environmentLabel": null,
"label": "Runtime TypeError",
"source": "src/fetcher.js (6:16) @ anotherFetcher
> 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:16)",
],
}
`)
}
}
)
// TODO: It need to have source maps picked up by node.js
it.skip('when returning `fetch` using an unknown domain, stack traces are preserved', async () => {
await next.browser('/api/unknown-domain-no-await')
await check(
() => stripAnsi(next.cliOutput),
/at.+\/pages\/api\/unknown-domain-no-await.ts:4/
)
})
})