Unverified Commit a135e7fb authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Improve error digest test suite (#71209)

parent 2112cebf
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { assertHasRedbox, getRedboxHeader, retry } from 'next-test-utils' import { assertHasRedbox, getRedboxHeader, retry } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
describe('app-dir - errors', () => { describe('app-dir - errors', () => {
const { next, isNextDev, isNextStart, skipped } = nextTestSetup({ const { next, isNextDev, isNextStart, skipped } = nextTestSetup({
...@@ -22,12 +23,8 @@ describe('app-dir - errors', () => { ...@@ -22,12 +23,8 @@ 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/)
} else { } else {
await browser
expect( expect(
await browser await browser.waitForElementByCss('#error-boundary-message').text()
.waitForElementByCss('#error-boundary-message')
.elementByCss('#error-boundary-message')
.text()
).toBe('An error occurred: this is a test') ).toBe('An error occurred: this is a test')
} }
}) })
...@@ -35,32 +32,45 @@ describe('app-dir - errors', () => { ...@@ -35,32 +32,45 @@ describe('app-dir - errors', () => {
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 browser = await next.browser('/server-component')
if (isNextDev) {
expect( expect(
await browser await browser.waitForElementByCss('#error-boundary-message').text()
.waitForElementByCss('#error-boundary-message') ).toBe(
.elementByCss('#error-boundary-message') isNextDev
.text() ? 'this is a test'
).toBe('this is a test') : 'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
)
expect( expect(
await browser.waitForElementByCss('#error-boundary-digest').text() await browser.waitForElementByCss('#error-boundary-digest').text()
// Digest of the error message should be stable. // Digest of the error message should be stable.
).not.toBe('') ).not.toBe('')
if (isNextDev) {
// TODO-APP: ensure error overlay is shown for errors that happened before/during hydration // TODO-APP: ensure error overlay is shown for errors that happened before/during hydration
// await assertHasRedbox(browser) // await assertHasRedbox(browser)
// expect(await getRedboxHeader(browser)).toMatch(/this is a test/) // expect(await getRedboxHeader(browser)).toMatch(/this is a test/)
} else { }
await browser })
it('should preserve custom digests', async () => {
const browser = await next.browser('/server-component/custom-digest')
expect( expect(
await browser.waitForElementByCss('#error-boundary-message').text() await browser.waitForElementByCss('#error-boundary-message').text()
).toBe( ).toBe(
'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.' isNextDev
? 'this is a test'
: 'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
) )
expect( expect(
await browser.waitForElementByCss('#error-boundary-digest').text() await browser.waitForElementByCss('#error-boundary-digest').text()
// Digest of the error message should be stable. ).toBe('custom')
).not.toBe('') expect(stripAnsi(next.cliOutput)).toEqual(
} expect.stringMatching(
isNextDev
? /Error: this is a test.*digest: "custom"/s
: /Error: this is a test.*digest: 'custom'/s
)
)
}) })
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 () => {
...@@ -140,7 +150,7 @@ describe('app-dir - errors', () => { ...@@ -140,7 +150,7 @@ describe('app-dir - errors', () => {
const digest = await browser const digest = await browser
.waitForElementByCss('#error-boundary-digest') .waitForElementByCss('#error-boundary-digest')
.text() .text()
const output = next.cliOutput.slice(logIndex) const output = stripAnsi(next.cliOutput.slice(logIndex))
// Log the original rsc error trace // Log the original rsc error trace
expect(output).toContain('Error: this is a test') expect(output).toContain('Error: this is a test')
...@@ -164,7 +174,7 @@ describe('app-dir - errors', () => { ...@@ -164,7 +174,7 @@ describe('app-dir - errors', () => {
expect(digest).toMatch(/\d+/) expect(digest).toMatch(/\d+/)
}) })
const output = next.cliOutput.slice(logIndex) const output = stripAnsi(next.cliOutput.slice(logIndex))
// Log the original rsc error trace // Log the original rsc error trace
expect(output).toContain('Error: server action test error') expect(output).toContain('Error: server action test error')
// Does not include the react renderer error for server actions // Does not include the react renderer error for server actions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment