Unverified Commit 2549514a authored by dan's avatar dan Committed by GitHub

[test] Add source-mapping coverage of React's fake stack frame scripts in `use cache` (#95945)

Adds tests verifying that`use cache` stacks get symbolicated.

We noticed insufficient coverage in
https://github.com/vercel/next.js/pull/95936, which should have failed
the tests (it broke symbolication) but tests passed. So this restores
the missing stack assertions. This also adds some new coverage that
specifically verifies that symbolicating via CDP also works.
parent 2802106d
...@@ -95,6 +95,14 @@ describe('Cache Components Dev Errors', () => { ...@@ -95,6 +95,14 @@ describe('Cache Components Dev Errors', () => {
expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain( expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain(
'https://nextjs.org/docs/messages/blocking-prerender-dynamic' 'https://nextjs.org/docs/messages/blocking-prerender-dynamic'
) )
expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain(
'\n at Page (app/no-accessed-data/page.js:2:9)' +
'\n 1 | export default async function Page() {' +
'\n> 2 | await new Promise((r) => setTimeout(r, 200))' +
'\n | ^' +
'\n 3 | return <p>Page</p>' +
'\n 4 | }'
)
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
......
import { connection } from 'next/server'
async function throwsInCache() {
'use cache'
throw new Error('rsc-error-throw-cached')
}
export default async function Page() {
await connection()
await throwsInCache()
return null
}
...@@ -537,6 +537,47 @@ describe('app-dir - server source maps', () => { ...@@ -537,6 +537,47 @@ describe('app-dir - server source maps', () => {
} }
}) })
it('thrown errors from "use cache" have a sourcemapped stack with a codeframe', async () => {
if (isNextDev) {
const outputIndex = next.cliOutput.length
await next.render('/rsc-error-throw-cached')
await retry(() => {
expect(next.cliOutput.slice(outputIndex)).toContain(
'Error: rsc-error-throw-cached'
)
})
const cliOutput = normalizeCliOutput(next.cliOutput.slice(outputIndex))
expect(cliOutput).toContain(
'Error: rsc-error-throw-cached' +
'\n at throwsInCache (app/rsc-error-throw-cached/page.js:5:9)' +
'\n 3 | async function throwsInCache() {' +
"\n 4 | 'use cache'" +
"\n> 5 | throw new Error('rsc-error-throw-cached')" +
'\n | ^' +
'\n 6 | }' +
'\n 7 |' +
'\n 8 | export default async function Page() {'
)
// The logged error is the one revived by the consuming Flight client,
// not the original from the cache environment.
expect(cliOutput).toContain("environmentName: 'Cache'")
} else {
const outputIndex = next.cliOutput.length
await next.render('/rsc-error-throw-cached')
await retry(() => {
expect(next.cliOutput.slice(outputIndex)).toContain(
'Error: rsc-error-throw-cached'
)
})
// React only creates fake stack frames in development.
expect(
normalizeCliOutput(next.cliOutput.slice(outputIndex))
).not.toContain('about://React/')
}
})
it('logged errors preserve their name', async () => { it('logged errors preserve their name', async () => {
let cliOutput = next.cliOutput let cliOutput = next.cliOutput
if (isNextDev) { if (isNextDev) {
......
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