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

[test] Remove `getStackFramesContent` (#90571)

parent d7db7440
...@@ -3,7 +3,7 @@ import { createSandbox } from 'development-sandbox' ...@@ -3,7 +3,7 @@ import { createSandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup } from 'e2e-utils'
import { import {
getRedboxTotalErrorCount, getRedboxTotalErrorCount,
getStackFramesContent, getRedboxCallStack,
retry, retry,
toggleCollapseCallStackFrames, toggleCollapseCallStackFrames,
} from 'next-test-utils' } from 'next-test-utils'
...@@ -1435,7 +1435,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -1435,7 +1435,7 @@ describe('ReactRefreshLogBox', () => {
} }
}) })
test('should collapse nodejs internal stack frames from stack trace', async () => { test('should collapse nodejs internal stack frames from stack trace by default', async () => {
await using sandbox = await createSandbox( await using sandbox = await createSandbox(
next, next,
new Map([ new Map([
...@@ -1474,7 +1474,15 @@ describe('ReactRefreshLogBox', () => { ...@@ -1474,7 +1474,15 @@ describe('ReactRefreshLogBox', () => {
`) `)
await toggleCollapseCallStackFrames(browser) await toggleCollapseCallStackFrames(browser)
const stackCollapsed = await getStackFramesContent(browser) const stackExpanded = await getRedboxCallStack(browser)
expect(stackCollapsed).toContain('at new URL ()') expect(stackExpanded).toEqual(
expect.arrayContaining([
expect.stringContaining(
// ignore exact location.
// If this breaks, choose a different error that contains Node.js internals in its stack.
'new URL node:internal/url ('
),
])
)
}) })
}) })
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import {
waitForRedbox, waitForRedbox,
getStackFramesContent, getRedboxCallStack,
toggleCollapseCallStackFrames, toggleCollapseCallStackFrames,
} from 'next-test-utils' } from 'next-test-utils'
...@@ -14,81 +14,101 @@ describe('error-ignored-frames', () => { ...@@ -14,81 +14,101 @@ describe('error-ignored-frames', () => {
const browser = await next.browser('/') const browser = await next.browser('/')
await waitForRedbox(browser) await waitForRedbox(browser)
const defaultStack = await getStackFramesContent(browser) const defaultStack = await getRedboxCallStack(browser)
expect(defaultStack).toMatchInlineSnapshot(`"at Page (app/page.tsx (2:9))"`) expect(defaultStack).toMatchInlineSnapshot(`
[
"Page app/page.tsx (2:9)",
]
`)
await toggleCollapseCallStackFrames(browser) await toggleCollapseCallStackFrames(browser)
const expandedStack = await getStackFramesContent(browser) const expandedStack = await getRedboxCallStack(browser)
const ignoreListedStack = expandedStack.replace(defaultStack, '') const ignoreListedStack = expandedStack.filter(
(line) => !defaultStack.includes(line)
)
// We don't care about the exact stack trace that was ignore-listed. // We don't care about the exact stack trace that was ignore-listed.
// It'll contain implementation details that may change and // It'll contain implementation details that may change and
// shouldn't break this test. // shouldn't break this test.
expect(ignoreListedStack.trim()).toMatch(/at .*/) expect(ignoreListedStack).not.toHaveLength(0)
}) })
it('should be able to collapse ignored frames in client component', async () => { it('should be able to collapse ignored frames in client component', async () => {
const browser = await next.browser('/client') const browser = await next.browser('/client')
await waitForRedbox(browser) await waitForRedbox(browser)
const defaultStack = await getStackFramesContent(browser) const defaultStack = await getRedboxCallStack(browser)
expect(defaultStack).toMatchInlineSnapshot( expect(defaultStack).toMatchInlineSnapshot(`
`"at Page (app/client/page.tsx (4:9))"` [
) "Page app/client/page.tsx (4:9)",
]
`)
await toggleCollapseCallStackFrames(browser) await toggleCollapseCallStackFrames(browser)
const expandedStack = await getStackFramesContent(browser) const expandedStack = await getRedboxCallStack(browser)
const ignoreListedStack = expandedStack.replace(defaultStack, '') const ignoreListedStack = expandedStack.filter(
(line) => !defaultStack.includes(line)
)
// We don't care about the exact stack trace that was ignore-listed. // We don't care about the exact stack trace that was ignore-listed.
// It'll contain implementation details that may change and // It'll contain implementation details that may change and
// shouldn't break this test. // shouldn't break this test.
expect(ignoreListedStack.trim()).toMatch(/at .*/) expect(ignoreListedStack).not.toHaveLength(0)
}) })
it('should be able to collapse ignored frames in interleaved call stack', async () => { it('should be able to collapse ignored frames in interleaved call stack', async () => {
const browser = await next.browser('/interleaved') const browser = await next.browser('/interleaved')
await waitForRedbox(browser) await waitForRedbox(browser)
const defaultStack = await getStackFramesContent(browser) const defaultStack = await getRedboxCallStack(browser)
if (isTurbopack) { if (isTurbopack) {
expect(defaultStack).toMatchInlineSnapshot(` expect(defaultStack).toMatchInlineSnapshot(`
"at <unknown> (app/interleaved/page.tsx (7:11)) [
at Page (app/interleaved/page.tsx (6:36))" "<unknown> app/interleaved/page.tsx (7:11)",
"Page app/interleaved/page.tsx (6:36)",
]
`) `)
} else { } else {
expect(defaultStack).toMatchInlineSnapshot(` expect(defaultStack).toMatchInlineSnapshot(`
"at eval (app/interleaved/page.tsx (7:11)) [
at Page (app/interleaved/page.tsx (6:36))" "eval app/interleaved/page.tsx (7:11)",
"Page app/interleaved/page.tsx (6:36)",
]
`) `)
} }
await toggleCollapseCallStackFrames(browser) await toggleCollapseCallStackFrames(browser)
const expandedStack = await getStackFramesContent(browser) const expandedStack = await getRedboxCallStack(browser)
const ignoreListedStack = expandedStack.replace(defaultStack, '') const ignoreListedStack = expandedStack.filter(
(line) => !defaultStack.includes(line)
)
// We don't care about the exact stack trace that was ignore-listed. // We don't care about the exact stack trace that was ignore-listed.
// It'll contain implementation details that may change and // It'll contain implementation details that may change and
// shouldn't break this test. // shouldn't break this test.
expect(ignoreListedStack.trim()).toMatch(/at .*/) expect(ignoreListedStack).not.toHaveLength(0)
}) })
it('should be able to collapse pages router ignored frames', async () => { it('should be able to collapse pages router ignored frames', async () => {
const browser = await next.browser('/pages') const browser = await next.browser('/pages')
await waitForRedbox(browser) await waitForRedbox(browser)
const defaultStack = await getStackFramesContent(browser) const defaultStack = await getRedboxCallStack(browser)
expect(defaultStack).toMatchInlineSnapshot( expect(defaultStack).toMatchInlineSnapshot(`
`"at Page (pages/pages.tsx (2:9))"` [
) "Page pages/pages.tsx (2:9)",
]
`)
await toggleCollapseCallStackFrames(browser) await toggleCollapseCallStackFrames(browser)
const expandedStack = await getStackFramesContent(browser) const expandedStack = await getRedboxCallStack(browser)
const ignoreListedStack = expandedStack.replace(defaultStack, '') const ignoreListedStack = expandedStack.filter(
(line) => !defaultStack.includes(line)
)
// We don't care about the exact stack trace that was ignore-listed. // We don't care about the exact stack trace that was ignore-listed.
// It'll contain implementation details that may change and // It'll contain implementation details that may change and
// shouldn't break this test. // shouldn't break this test.
expect(ignoreListedStack.trim()).toMatch(/at .*/) expect(ignoreListedStack).not.toHaveLength(0)
}) })
}) })
...@@ -2,7 +2,7 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,7 +2,7 @@ import { nextTestSetup } from 'e2e-utils'
import { import {
getRedboxSource, getRedboxSource,
openRedbox, openRedbox,
getStackFramesContent, getRedboxCallStack,
} from 'next-test-utils' } from 'next-test-utils'
describe('app-dir - owner-stack-react-missing-key-prop', () => { describe('app-dir - owner-stack-react-missing-key-prop', () => {
...@@ -14,15 +14,17 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => { ...@@ -14,15 +14,17 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => {
const browser = await next.browser('/rsc') const browser = await next.browser('/rsc')
await openRedbox(browser) await openRedbox(browser)
const stackFramesContent = await getStackFramesContent(browser) const stackFramesContent = await getRedboxCallStack(browser)
const source = await getRedboxSource(browser) const source = await getRedboxSource(browser)
if (isTurbopack) { if (isTurbopack) {
expect(stackFramesContent).toMatchInlineSnapshot(` expect(stackFramesContent).toMatchInlineSnapshot(`
"at span () [
at <anonymous> (app/rsc/page.tsx (7:9)) "span <anonymous>",
at Array.map () "<anonymous> app/rsc/page.tsx (7:9)",
at Page (app/rsc/page.tsx (6:13))" "Array.map <anonymous>",
"Page app/rsc/page.tsx (6:13)",
]
`) `)
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"app/rsc/page.tsx (7:9) @ <anonymous> "app/rsc/page.tsx (7:9) @ <anonymous>
...@@ -37,10 +39,12 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => { ...@@ -37,10 +39,12 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => {
`) `)
} else { } else {
expect(stackFramesContent).toMatchInlineSnapshot(` expect(stackFramesContent).toMatchInlineSnapshot(`
"at span () [
at eval (app/rsc/page.tsx (7:9)) "span <anonymous>",
at Array.map () "eval app/rsc/page.tsx (7:9)",
at Page (app/rsc/page.tsx (6:13))" "Array.map <anonymous>",
"Page app/rsc/page.tsx (6:13)",
]
`) `)
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"app/rsc/page.tsx (7:9) @ eval "app/rsc/page.tsx (7:9) @ eval
...@@ -60,15 +64,17 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => { ...@@ -60,15 +64,17 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => {
const browser = await next.browser('/ssr') const browser = await next.browser('/ssr')
await openRedbox(browser) await openRedbox(browser)
const stackFramesContent = await getStackFramesContent(browser) const stackFramesContent = await getRedboxCallStack(browser)
const source = await getRedboxSource(browser) const source = await getRedboxSource(browser)
if (isTurbopack) { if (isTurbopack) {
expect(stackFramesContent).toMatchInlineSnapshot(` expect(stackFramesContent).toMatchInlineSnapshot(`
"at p () [
at <unknown> (app/ssr/page.tsx (9:9)) "p <anonymous>",
at Array.map () "<unknown> app/ssr/page.tsx (9:9)",
at Page (app/ssr/page.tsx (8:13))" "Array.map <anonymous>",
`) "Page app/ssr/page.tsx (8:13)",
]
`)
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"app/ssr/page.tsx (9:9) @ <unknown> "app/ssr/page.tsx (9:9) @ <unknown>
...@@ -82,11 +88,13 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => { ...@@ -82,11 +88,13 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => {
`) `)
} else { } else {
expect(stackFramesContent).toMatchInlineSnapshot(` expect(stackFramesContent).toMatchInlineSnapshot(`
"at p () [
at eval (app/ssr/page.tsx (9:9)) "p <anonymous>",
at Array.map () "eval app/ssr/page.tsx (9:9)",
at Page (app/ssr/page.tsx (8:13))" "Array.map <anonymous>",
`) "Page app/ssr/page.tsx (8:13)",
]
`)
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"app/ssr/page.tsx (9:9) @ eval "app/ssr/page.tsx (9:9) @ eval
......
...@@ -1858,33 +1858,6 @@ export const checkLink = ( ...@@ -1858,33 +1858,6 @@ export const checkLink = (
content: string | string[] content: string | string[]
) => checkMeta(browser, rel, content, 'rel', 'link', 'href') ) => checkMeta(browser, rel, content, 'rel', 'link', 'href')
export async function getStackFramesContent(browser) {
const stackFrameElements = await browser.elementsByCss(
'[data-nextjs-call-stack-frame]'
)
const stackFramesContent = (
await Promise.all(
stackFrameElements.map(async (frame) => {
const functionNameEl = await frame.$('.call-stack-frame-method-name')
const fileEl = await frame.$('[data-has-original-code-frame="true"]')
const functionName = functionNameEl
? await functionNameEl.innerText()
: ''
const file = fileEl ? await fileEl.innerText() : ''
if (!functionName) {
return ''
}
return `at ${functionName} (${file})`
})
)
)
.filter(Boolean)
.join('\n')
return stackFramesContent
}
export async function toggleCollapseCallStackFrames(browser: Playwright) { export async function toggleCollapseCallStackFrames(browser: Playwright) {
const button = await browser.elementByCss( const button = await browser.elementByCss(
'[data-nextjs-call-stack-ignored-list-toggle-button]' '[data-nextjs-call-stack-ignored-list-toggle-button]'
......
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