Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions test/development/acceptance-app/dynamic-error.test.ts
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New matcher makes it easier to find duplicate tests. This was a lesser test than dynamic-error-trace since it wasn't testing how the stack is displayed if it ends in node_modules.

This file was deleted.

62 changes: 14 additions & 48 deletions test/development/app-dir/dynamic-error-trace/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
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({
Expand All @@ -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 |
`
)
})
})
Loading