Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 25, 2024
1 parent 81ba686 commit e6eec4c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ function getOriginalStackFrame(
}

// TODO: merge this section into ignoredList handling
if (
source.file === 'file://' ||
source.file?.match(/https?:\/\//)
) {
if (source.file === 'file://' || source.file?.match(/https?:\/\//)) {
return Promise.resolve({
error: false,
reason: null,
Expand Down
21 changes: 0 additions & 21 deletions test/development/acceptance/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,25 +769,4 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {

expect(callStackFrames.length).toBeGreaterThan(9)
})

test('should show anonymous frames in stack trace', async () => {
await using sandbox = await createSandbox(
next,
new Map([
[
'pages/index.js',
outdent`
export default function Page() {
[1, 2, 3].map(() => {
throw new Error("anonymous error!");
})
}`,
],
])
)
const { session, browser } = sandbox
await session.assertHasRedbox()
const texts = await getRedboxCallStack(browser)
expect(texts).toMatchSnapshot()
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions test/development/errors/anonymous-stack-frame.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { nextTestSetup } from 'e2e-utils'
import { assertHasRedbox, getStackFramesContent } from 'next-test-utils'
import { outdent } from 'outdent'

describe('errors - anonymous-stack-frame', () => {
const { next } = nextTestSetup({
files: {
'pages/index.js': outdent`
export default function Page() {
[1, 2, 3].map(() => {
throw new Error("anonymous error!");
})
}`,
},
})

// TODO: hide the anonymous frames between 2 ignored frames
test('should show anonymous frames from stack trace', async () => {
const browser = await next.browser('/')

await assertHasRedbox(browser)

const stack = await getStackFramesContent(browser)
expect(stack).toMatchInlineSnapshot(`
"at Array.map ()
at Page (pages/index.js (2:13))"
`)
})
})
22 changes: 12 additions & 10 deletions test/development/errors/node-internal-stack-frame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ describe('errors - node-internal-stack-frame', () => {
'pages/index.js': outdent`
export default function Page() {}
function createURL() {
new URL("/", "invalid")
}
export function getServerSideProps() {
new URL("/", "invalid");
return { props: {} };
createURL()
return { props: {} }
}`,
},
})

test('should hide unrelated frames in stack trace with node:internal calls', async () => {
test('should hide nodejs internal stack frames from stack trace', async () => {
const browser = await next.browser('/')

await assertHasRedbox(browser)
Expand Down Expand Up @@ -47,14 +51,12 @@ describe('errors - node-internal-stack-frame', () => {
`)
} else {
expect(stack).toMatchInlineSnapshot(`
"at eval ()
at renderToHTMLImpl ()"
"at getServerSideProps (pages/index.js (8:3))"
`)
}
await toggleCollapseCallStackFrames(browser)

// TODO: Since there're still the locations
const expandedStack = await getStackFramesContent(browser)
expect(expandedStack).toContain(`at new URL ()`)
await toggleCollapseCallStackFrames(browser)
const stackCollapsed = await getStackFramesContent(browser)
expect(stackCollapsed).toContain('at new URL ()')
}
})
})

0 comments on commit e6eec4c

Please sign in to comment.