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: also check source code for node:internal related errors #62542

Merged
merged 3 commits into from
Feb 26, 2024
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
38 changes: 26 additions & 12 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,17 +839,17 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
await cleanup()
})

test('useless frames are hidden in stack trace', async () => {
test('should hide unrelated frames in stack trace with unknown anonymous calls', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
// TODO: repro stringify (<anonymous>)
outdent`
export default function Page() {
const e = new Error("Boom!");
e.stack += \`
// REVIEW: how to reliably test the presence of these stack frames?
at stringify (<anonymous>)
at <unknown> (<anonymous>)
at foo (bar:1:1)\`;
Expand All @@ -869,23 +869,37 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
expect(texts).not.toContain('<unknown>\n<anonymous>')
expect(texts).toContain('foo\nbar (1:1)')

// Test that node:internal errors should be hidden
await cleanup()
})

next.patchFile(
'app/page.js',
// Node.js will throw an error about the invalid URL since this is a server component
outdent`
export default function Page() {
new URL("/", "invalid");
}`
test('should hide unrelated frames in stack trace with node:internal calls', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
// Node.js will throw an error about the invalid URL since this is a server component
outdent`
export default function Page() {
new URL("/", "invalid");
}`,
],
])
)

expect(await session.hasRedbox()).toBe(true)
await expandCallStack(browser)
callStackFrames = await browser.elementsByCss(

// Should still show the errored line in source code
const source = await session.getRedboxSource()
expect(source).toContain('app/page.js')
expect(source).toContain(`new URL("/", "invalid")`)

await expandCallStack(browser)
const callStackFrames = await browser.elementsByCss(
'[data-nextjs-call-stack-frame]'
)
texts = await Promise.all(callStackFrames.map((f) => f.innerText()))
const texts = await Promise.all(callStackFrames.map((f) => f.innerText()))

expect(texts.filter((t) => t.includes('node:internal'))).toHaveLength(0)

Expand Down
34 changes: 23 additions & 11 deletions test/development/acceptance/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,17 +784,17 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
await cleanup()
})

test('useless frames are hidden in stack trace for pages error', async () => {
test('should hide unrelated frames in stack trace with unknown anonymous calls', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'pages/index.js',
// TODO: repro stringify (<anonymous>)
outdent`
export default function Page() {
const e = new Error("Client error!");
e.stack += \`
// REVIEW: how to reliably test the presence of these stack frames?
at stringify (<anonymous>)
at <unknown> (<anonymous>)
at foo (bar:1:1)\`;
Expand All @@ -814,26 +814,38 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
expect(texts).not.toContain('<unknown>\n<anonymous>')
expect(texts).toContain('foo\nbar (1:1)')

// Test that node:internal errors should be hidden
await cleanup()
})

next.patchFile(
'pages/index.js',
// Node.js will throw an error about the invalid URL since it happens server-side
outdent`
test('should hide unrelated frames in stack trace with node:internal calls', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'pages/index.js',
// Node.js will throw an error about the invalid URL since it happens server-side
outdent`
export default function Page() {}

export function getServerSideProps() {
new URL("/", "invalid");
return { props: {} };
}`
}`,
],
])
)

expect(await session.hasRedbox()).toBe(true)
await expandCallStack(browser)
callStackFrames = await browser.elementsByCss(

// Should still show the errored line in source code
const source = await session.getRedboxSource()
expect(source).toContain('pages/index.js')
expect(source).toContain(`new URL("/", "invalid")`)

const callStackFrames = await browser.elementsByCss(
'[data-nextjs-call-stack-frame]'
)
texts = await Promise.all(callStackFrames.map((f) => f.innerText()))
const texts = await Promise.all(callStackFrames.map((f) => f.innerText()))

expect(texts.filter((t) => t.includes('node:internal'))).toHaveLength(0)

Expand Down
Loading