Files
next.js/test/development/error-overlay/index.test.tsx
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

211 lines
6.7 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { waitForRedbox } from 'next-test-utils'
describe('DevErrorOverlay', () => {
const { next } = nextTestSetup({
files: __dirname,
env: {
NEXT_TELEMETRY_DISABLED: '',
},
})
it('can get error code from RSC error thrown by framework', async () => {
const browser = await next.browser('/known-rsc-error')
const errorCode = await browser.elementByCss('[data-nextjs-error-code]')
const code = await errorCode.getAttribute('data-nextjs-error-code')
expect(code).toBe('E40')
})
it('sends feedback when clicking helpful button', async () => {
const feedbackRequests: string[] = []
const browser = await next.browser('/known-client-error', {
beforePageLoad(page) {
page.route(/__nextjs_error_feedback/, (route) => {
const url = new URL(route.request().url())
feedbackRequests.push(url.pathname + url.search)
route.fulfill({ status: 204, body: 'No Content' })
})
},
})
await browser.elementByCss('button').click() // clicked "break on client"
await browser.getByRole('button', { name: 'Mark as helpful' }).click()
expect(
await browser
.getByRole('region', { name: 'Error feedback' })
.getByRole('status')
.textContent()
).toEqual('Thanks for your feedback!')
expect(feedbackRequests).toEqual([
'/__nextjs_error_feedback?errorCode=E40&wasHelpful=true',
])
})
it('sends feedback when clicking not helpful button', async () => {
const feedbackRequests: string[] = []
const browser = await next.browser('/known-client-error', {
beforePageLoad(page) {
page.route(/__nextjs_error_feedback/, (route) => {
const url = new URL(route.request().url())
feedbackRequests.push(url.pathname + url.search)
route.fulfill({ status: 204, body: 'No Content' })
})
},
})
await browser.elementByCss('button').click() // clicked "break on client"
await browser.getByRole('button', { name: 'Mark as not helpful' }).click()
expect(
await browser
.getByRole('region', { name: 'Error feedback' })
.getByRole('status')
.textContent()
).toEqual('Thanks for your feedback!')
expect(feedbackRequests).toEqual([
'/__nextjs_error_feedback?errorCode=E40&wasHelpful=false',
])
})
it('loads fonts successfully', async () => {
const woff2Requests: { url: string; status: number }[] = []
const browser = await next.browser('/known-rsc-error', {
beforePageLoad: (page) => {
page.route('**/*.woff2', async (route) => {
const response = await route.fetch()
woff2Requests.push({
url: route.request().url(),
status: response.status(),
})
await route.continue()
})
},
})
await waitForRedbox(browser)
await browser.waitForIdleNetwork()
// Verify woff2 files were requested and loaded successfully
expect(woff2Requests.length).toBeGreaterThan(0)
for (const request of woff2Requests) {
expect(request.status).toBe(200)
}
})
it('shows Error.cause in the error overlay', async () => {
const browser = await next.browser('/error-cause')
await expect({ browser, next }).toDisplayCollapsedRedbox(`
{
"cause": [
{
"label": "Caused by: TypeError",
"message": "Connection refused",
"source": "app/error-cause/page.tsx (6:16) @ Page
> 6 | const root = new TypeError('Connection refused')
| ^",
"stack": [
"Page app/error-cause/page.tsx (6:16)",
],
},
],
"description": "Database query failed",
"environmentLabel": null,
"label": "Console Error",
"source": "app/error-cause/page.tsx (7:15) @ Page
> 7 | const mid = new Error('Database query failed', { cause: root })
| ^",
"stack": [
"Page app/error-cause/page.tsx (7:15)",
],
}
`)
})
it('shows nested Error.cause chain in the error overlay', async () => {
const browser = await next.browser('/error-cause-nested')
await expect({ browser, next }).toDisplayCollapsedRedbox(`
{
"cause": [
{
"label": "Caused by: Error",
"message": "Database query failed",
"source": "app/error-cause-nested/page.tsx (7:15) @ Page
> 7 | const mid = new Error('Database query failed', { cause: root })
| ^",
"stack": [
"Page app/error-cause-nested/page.tsx (7:15)",
],
},
{
"label": "Caused by: TypeError",
"message": "Connection refused",
"source": "app/error-cause-nested/page.tsx (6:16) @ Page
> 6 | const root = new TypeError('Connection refused')
| ^",
"stack": [
"Page app/error-cause-nested/page.tsx (6:16)",
],
},
],
"description": "Failed to load user",
"environmentLabel": null,
"label": "Console Error",
"source": "app/error-cause-nested/page.tsx (8:15) @ Page
> 8 | const top = new Error('Failed to load user', { cause: mid })
| ^",
"stack": [
"Page app/error-cause-nested/page.tsx (8:15)",
],
}
`)
})
it('ignores non-Error cause in the error overlay', async () => {
const browser = await next.browser('/error-cause-non-error')
await expect({ browser, next }).toDisplayCollapsedRedbox(`
{
"description": "Something went wrong",
"environmentLabel": null,
"label": "Console Error",
"source": "app/error-cause-non-error/page.tsx (6:15) @ Page
> 6 | const err = new Error('Something went wrong', {
| ^",
"stack": [
"Page app/error-cause-non-error/page.tsx (6:15)",
],
}
`)
})
it('should load dev overlay styles successfully', async () => {
const browser = await next.browser('/hydration-error')
await waitForRedbox(browser)
const redbox = browser.locateRedbox()
// check the data-nextjs-dialog-header="true" DOM element styles under redbox is applied
const dialogHeader = redbox.locator('[data-nextjs-dialog-header="true"]')
expect(await dialogHeader.isVisible()).toBe(true)
// get computed styles
const computedStyles = await dialogHeader.evaluate((element) => {
return window.getComputedStyle(element)
})
const styles = {
backgroundColor: computedStyles.backgroundColor,
color: computedStyles.color,
}
expect(styles).toEqual({
backgroundColor: 'rgba(0, 0, 0, 0)',
color: 'rgb(117, 117, 117)',
})
})
})