Skip to content

Commit

Permalink
Track errors where frames are not sourcemapped properly in the Redbox
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Nov 24, 2024
1 parent f3b06b9 commit f8ee886
Show file tree
Hide file tree
Showing 49 changed files with 400 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
])
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ describe('ReactRefreshRegression app', () => {
`export default function () { throw new Error('boom'); }`
)

await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })

const source = await session.getRedboxSource()
expect(source.split(/\r?\n/g).slice(2).join('\n')).toMatchInlineSnapshot(`
Expand All @@ -295,7 +295,7 @@ describe('ReactRefreshRegression app', () => {
`export default function Page() { throw new Error('boom'); }`
)

await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })

const source = await session.getRedboxSource()
expect(source.split(/\r?\n/g).slice(2).join('\n')).toMatchInlineSnapshot(`
Expand Down
2 changes: 2 additions & 0 deletions test/development/acceptance-app/app-hmr-changes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ describe('Error overlay - RSC build errors', () => {
await session.patch(pagePath, break2.replace('break 3', '<Hello />'))

await session.patch(pagePath, break2)
// TODO: remove
console.log({ i })
await session.assertHasRedbox()

await session.patch(pagePath, break1)
Expand Down
4 changes: 3 additions & 1 deletion test/development/acceptance-app/dynamic-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ describe('dynamic = "error" in devmode', () => {
'/server'
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
fixmeStackFramesHaveBrokenSourcemaps: true,
})
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"[ Server ] Error: Route /server with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering"`
)
Expand Down
20 changes: 15 additions & 5 deletions test/development/acceptance-app/rsc-runtime-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('Error overlay - RSC runtime errors', () => {

const browser = await next.browser('/server')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})
const errorDescription = await getRedboxDescription(browser)

expect(errorDescription).toContain(
Expand Down Expand Up @@ -69,7 +71,9 @@ describe('Error overlay - RSC runtime errors', () => {
)

const browser = await next.browser('/server')
await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})

const errorDescription = await getRedboxDescription(browser)

Expand All @@ -87,7 +91,9 @@ describe('Error overlay - RSC runtime errors', () => {
`
)
const browser = await next.browser('/server')
await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})

const source = await getRedboxSource(browser)
// Can show the original source code
Expand All @@ -106,7 +112,9 @@ describe('Error overlay - RSC runtime errors', () => {
)
const browser = await next.browser('/server')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})
const versionText = await getVersionCheckerText(browser)
expect(versionText).toMatch(/Next.js \([\w.-]+\)/)
})
Expand All @@ -122,7 +130,9 @@ describe('Error overlay - RSC runtime errors', () => {
)
const browser = await next.browser('/server')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})
const source = await getRedboxSource(browser)
expect(source).toContain('app/server/page.js')
expect(source).not.toContain('//app/server/page.js')
Expand Down
2 changes: 1 addition & 1 deletion test/development/acceptance-app/server-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ describe('Error Overlay for server components', () => {
])
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })
// In webpack when the message too long it gets truncated with ` | ` with new lines.
// So we need to check for the first part of the message.
const normalizedSource = await session.getRedboxSource()
Expand Down
18 changes: 14 additions & 4 deletions test/development/acceptance-app/undefined-default-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ describe('Undefined default export', () => {
'/specific-path/server'
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
// TODO: Unclear why the test is navigating to the page twice
pageResponseCode: [500, 500],
})
expect(await session.getRedboxDescription()).toInclude(
'The default export is not a React Component in "/specific-path/server/page"'
)
Expand All @@ -39,7 +42,9 @@ describe('Undefined default export', () => {
'/will-not-found'
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
pageResponseCode: 500,
})
expect(await session.getRedboxDescription()).toInclude(
'The default export is not a React Component in "/will-not-found/not-found"'
)
Expand All @@ -55,7 +60,10 @@ describe('Undefined default export', () => {
// Wait for the DOM node #__next to be present
await browser.waitForElementByCss('#__next')

await session.assertHasRedbox()
await session.assertHasRedbox({
// TODO: really?
fixmeStackFramesHaveBrokenSourcemaps: true,
})
expect(await session.getRedboxDescription()).toInclude(
'The default export is not a React Component in "/page"'
)
Expand All @@ -73,7 +81,9 @@ describe('Undefined default export', () => {
'/server-with-errors/page-export-initial-error'
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
pageResponseCode: 500,
})
expect(await session.getRedboxDescription()).toInclude(
'The default export is not a React Component in "/server-with-errors/page-export-initial-error/page"'
)
Expand Down
16 changes: 12 additions & 4 deletions test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe.each(['default', 'turbo'])(
new Map([['pages/_app.js', ``]])
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
pageResponseCode: 500,
})
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: The default export is not a React Component in page: "/_app""`
)
Expand All @@ -41,7 +43,9 @@ describe.each(['default', 'turbo'])(
new Map([['pages/_document.js', ``]])
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
pageResponseCode: 500,
})
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: The default export is not a React Component in page: "/_document""`
)
Expand Down Expand Up @@ -92,7 +96,9 @@ describe.each(['default', 'turbo'])(
])
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
pageResponseCode: 500,
})
const content = await session.getRedboxSource()
const source = next.normalizeTestDirContent(content)
if (process.env.TURBOPACK) {
Expand Down Expand Up @@ -178,7 +184,9 @@ describe.each(['default', 'turbo'])(
])
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({
pageResponseCode: 500,
})
const source = next.normalizeTestDirContent(
await session.getRedboxSource()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
])
)
const { session } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
Expand Down
8 changes: 4 additions & 4 deletions test/development/acceptance/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
`
)

await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })
expect(await session.getRedboxSource()).toMatchSnapshot()
})

Expand Down Expand Up @@ -644,7 +644,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
`
)

await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: {"a":1,"b":"x"}"`
)
Expand Down Expand Up @@ -792,7 +792,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
])
)
const { session, browser } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })
let callStackFrames = await browser.elementsByCss(
'[data-nextjs-call-stack-frame]'
)
Expand Down Expand Up @@ -820,7 +820,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
])
)
const { session, browser } = sandbox
await session.assertHasRedbox()
await session.assertHasRedbox({ pageResponseCode: 500 })

// Should still show the errored line in source code
const source = await session.getRedboxSource()
Expand Down
6 changes: 5 additions & 1 deletion test/development/acceptance/ReactRefreshRegression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ describe('ReactRefreshRegression', () => {
)
expect(didNotReload).toBe(false)

await session.assertHasRedbox()
await session.assertHasRedbox({
pageResponseCode:
// TODO: Unclear why the test is navigating to the page twice
[500, 500],
})

const source = await session.getRedboxSource()
expect(source.split(/\r?\n/g).slice(2).join('\n')).toMatchInlineSnapshot(`
Expand Down
4 changes: 3 additions & 1 deletion test/development/app-dir/dynamic-error-trace/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe('app dir - dynamic error trace', () => {
it('should show the error trace', async () => {
const browser = await next.browser('/')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})

await expect(
browser.hasElementByCssSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('Dynamic IO Dev Errors', () => {
])
)
const { browser, session } = sandbox
await assertHasRedbox(browser)
await assertHasRedbox(browser, { pageResponseCode: 500 })
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('unstable_after() - invalid usages', () => {
it('errors at compile time when used in a client module', async () => {
const session = await next.browser('/invalid-in-client')

await assertHasRedbox(session)
await assertHasRedbox(session, { pageResponseCode: 500 })
expect(await getRedboxSource(session)).toMatch(
/You're importing a component that needs "?unstable_after"?\. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component\./
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const isOwnerStackEnabled =
it('should catch invalid element from a rsc component', async () => {
const browser = await next.browser('/rsc')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
pageResponseCode: 500,
})
const stackFramesContent = await getStackFramesContent(browser)
const source = await getRedboxSource(browser)

Expand Down Expand Up @@ -96,7 +98,9 @@ const isOwnerStackEnabled =
it('should catch invalid element from on ssr client component', async () => {
const browser = await next.browser('/ssr')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
pageResponseCode: 500,
})

const stackFramesContent = await getStackFramesContent(browser)
const source = await getRedboxSource(browser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const isOwnerStackEnabled =
it('should catch invalid element from a rsc component', async () => {
const browser = await next.browser('/rsc')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})
const stackFramesContent = await getStackFramesContent(browser)
const source = await getRedboxSource(browser)

Expand Down Expand Up @@ -106,7 +108,9 @@ const isOwnerStackEnabled =
it('should catch invalid element from on ssr client component', async () => {
const browser = await next.browser('/ssr')

await assertHasRedbox(browser)
await assertHasRedbox(browser, {
fixmeStackFramesHaveBrokenSourcemaps: true,
})

const stackFramesContent = await getStackFramesContent(browser)
const source = await getRedboxSource(browser)
Expand Down
2 changes: 1 addition & 1 deletion test/development/app-dir/owner-stack/owner-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('app-dir - owner-stack', () => {
it('should log stitched error for SSR errors', async () => {
const browser = await next.browser('/ssr')

await assertHasRedbox(browser)
await assertHasRedbox(browser, { pageResponseCode: 500 })

const stackFramesContent = await getStackFramesContent(browser)
if (process.env.TURBOPACK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('serialize-circular-error', () => {

it('should serialize the object from server component in console correctly', async () => {
const browser = await next.browser('/')
await assertHasRedbox(browser)
await assertHasRedbox(browser, { pageResponseCode: 500 })

const description = await getRedboxDescription(browser)
// React cannot serialize thrown objects with circular references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => {

it('should error when use dynamic ssr:false in server component', async () => {
const browser = await next.browser('/')
await assertHasRedbox(browser)
await assertHasRedbox(browser, { pageResponseCode: 500 })
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
Expand Down
Loading

0 comments on commit f8ee886

Please sign in to comment.