Unverified Commit 22e61a3c authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

test: align existing testing util (#75844)

parent fe45b74f
...@@ -36,10 +36,6 @@ export { shouldRunTurboDevTest } ...@@ -36,10 +36,6 @@ export { shouldRunTurboDevTest }
export const nextServer = server export const nextServer = server
export const pkg = _pkg export const pkg = _pkg
// TODO(jiwon): Remove this once we have a new dev overlay at stable.
const isNewDevOverlay =
process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true'
export function initNextServerScript( export function initNextServerScript(
scriptPath: string, scriptPath: string,
successRegexp: RegExp, successRegexp: RegExp,
...@@ -939,13 +935,7 @@ export async function getToastErrorCount( ...@@ -939,13 +935,7 @@ export async function getToastErrorCount(
*/ */
export async function openRedbox(browser: BrowserInterface): Promise<void> { export async function openRedbox(browser: BrowserInterface): Promise<void> {
try { try {
//TODO(jiwon): data-nextjs-toast won't open red box in new UI. await browser.waitForElementByCss('[data-issues]').click()
if (isNewDevOverlay) {
await browser.waitForElementByCss('[data-error-expanded="true"]')
await browser.waitForElementByCss('[data-issues-open]').click()
} else {
await browser.waitForElementByCss('[data-nextjs-toast]').click()
}
} catch (cause) { } catch (cause) {
const error = new Error('No Redbox to open.', { cause }) const error = new Error('No Redbox to open.', { cause })
Error.captureStackTrace(error, openRedbox) Error.captureStackTrace(error, openRedbox)
...@@ -1007,28 +997,21 @@ export function getRedboxHeader(browser: BrowserInterface) { ...@@ -1007,28 +997,21 @@ export function getRedboxHeader(browser: BrowserInterface) {
}) })
} }
export function getRedboxNavText(browser: BrowserInterface): Promise<string> { export async function getRedboxTotalErrorCount(
return browser.eval(() => { browser: BrowserInterface
): Promise<number> {
const text = await browser.eval(() => {
const portal = [].slice const portal = [].slice
.call(document.querySelectorAll('nextjs-portal')) .call(document.querySelectorAll('nextjs-portal'))
.find((p) => .find((p) =>
p.shadowRoot.querySelector('[data-nextjs-error-overlay-nav]') p.shadowRoot.querySelector('[data-nextjs-dialog-header-total-count]')
) )
const root = portal.shadowRoot
return root.querySelector('[data-nextjs-error-overlay-nav]')?.innerText
})
}
export async function getRedboxTotalErrorCount(browser: BrowserInterface) {
// TODO(jiwon): Remove this once we have a new dev overlay at stable.
if (isNewDevOverlay) {
// N/M\nNext.js X.Y.Z -> M
const text = (await getRedboxNavText(browser)) || ''
return parseInt(text.match(/\/(\d+)/)?.[1])
}
const header = (await getRedboxHeader(browser)) || '' const root = portal?.shadowRoot
return parseInt(header.match(/\d+ of (\d+) issue/)?.[1], 10) return root?.querySelector('[data-nextjs-dialog-header-total-count]')
?.innerText
})
return parseInt(text || '-1')
} }
export async function getRedboxSource(browser: BrowserInterface) { export async function getRedboxSource(browser: BrowserInterface) {
......
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