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

[test] Use new Redbox matchers in app/ dynamic-error-trace (#76783)

parent 059c255c
/* eslint-env jest */
import { createSandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
describe('dynamic = "error" in devmode', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
})
it('should show error overlay when dynamic is forced', async () => {
await using sandbox = await createSandbox(
next,
new Map([
[
'app/server/page.js',
outdent`
import { cookies } from 'next/headers';
export default async function Page() {
await cookies()
return null
}
export const dynamic = "error"
`,
],
]),
'/server'
)
const { browser } = sandbox
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "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",
"environmentLabel": "Server",
"label": "Unhandled Runtime Error",
"source": "app/server/page.js (4:16) @ Page
> 4 | await cookies()
| ^",
"stack": [
"Page app/server/page.js (4:16)",
],
}
`)
})
})
import { nextTestSetup } from 'e2e-utils'
import {
assertHasRedbox,
getRedboxSource,
hasRedboxCallStack,
} from 'next-test-utils'
import { outdent } from 'outdent'
function normalizeStackTrace(trace) {
return trace.replace(/ \(.*\)/g, '')
}
describe('app dir - dynamic error trace', () => {
const { next, skipped } = nextTestSetup({
......@@ -20,44 +10,20 @@ describe('app dir - dynamic error trace', () => {
it('should show the error trace', async () => {
const browser = await next.browser('/')
await assertHasRedbox(browser)
await expect(
browser.hasElementByCssSelector(
'[data-nextjs-data-runtime-error-collapsed-action]'
)
).resolves.toEqual(false)
await hasRedboxCallStack(browser)
const stackFrameElements = await browser.elementsByCss(
'[data-nextjs-call-stack-frame]'
)
const stackFramesContent = // TODO: Why is this text empty?
(await Promise.all(stackFrameElements.map((f) => f.innerText())))
// Filter out the frames having code snippet but without methodName and source
.filter(Boolean)
.join('\n')
// TODO: Show useful stack
const normalizedStack = normalizeStackTrace(stackFramesContent)
expect(normalizedStack).toMatchInlineSnapshot(`
"Foo
app/lib.js"
// TODO(veil): Where is the stackframe for app/page.js?
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Route / with \`dynamic = "error"\` couldn't be rendered statically because it used \`headers\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"environmentLabel": "Server",
"label": "Unhandled Runtime Error",
"source": "app/lib.js (4:13) @ Foo
> 4 | useHeaders()
| ^",
"stack": [
"Foo app/lib.js (4:13)",
],
}
`)
const codeframe = await getRedboxSource(browser)
expect(codeframe).toEqual(
outdent`
app/lib.js (4:13) @ Foo
2 |
3 | export function Foo() {
> 4 | useHeaders()
| ^
5 | return 'foo'
6 | }
7 |
`
)
})
})
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