Skip to content

Commit

Permalink
Return null if Redbox has no component stack
Browse files Browse the repository at this point in the history
and stop waiting for it. The util is supposed to be
called after `assertHasRedbox` (hence the "get" prefix).
Waiting just makes failing tests slower.
  • Loading branch information
eps1lon committed Feb 6, 2025
1 parent 1fc0262 commit 6af6e7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions test/lib/development-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ export async function createSandbox(
}
return source
},
/**
* @returns `null` if there are no frames
*/
async getRedboxComponentStack() {
return getRedboxComponentStack(browser)
},
Expand Down
13 changes: 8 additions & 5 deletions test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,17 +1285,20 @@ export function getSnapshotTestDescribe(variant: TestVariants) {
return shouldSkip ? describe.skip : describe
}

/**
* @returns `null` if there are no frames
*/
export async function getRedboxComponentStack(
browser: BrowserInterface
): Promise<string> {
await browser.waitForElementByCss(
'[data-nextjs-container-errors-pseudo-html] code',
30000
)
): Promise<string | null> {
// TODO: the type for elementsByCss is incorrect
const componentStackFrameElements: any = await browser.elementsByCss(
'[data-nextjs-container-errors-pseudo-html] code'
)
if (componentStackFrameElements.length === 0) {
return null
}

const componentStackFrameTexts = await Promise.all(
componentStackFrameElements.map((f) => f.innerText())
)
Expand Down

0 comments on commit 6af6e7f

Please sign in to comment.