Unverified Commit 415e0df7 authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

[Instant] speed up test instant-validation suite (#90214)

This PR speeds up the `instant-validation` test suite from 450s down to
~100s. We were wasting a lot of time in `waitForNoErrorToast()`, which
ends up waiting almost 15s by default.

The trick is to add some debug logs inside app-render to track when
instant validation started/ended. If we know that the validation is
finished, we can just wait for a short time, because if there were
errors, a toast would be displayed very quickly.

Note that is a stopgap -- when we add a "Validating..." indicator, we
won't have to emit the log and can just wait for the indicator instead.
But in the meantime, waiting for the tests is pretty painful, so this is
worth doing.
parent ca0957df
...@@ -3615,13 +3615,39 @@ async function logMessagesAndSendErrorsToBrowser( ...@@ -3615,13 +3615,39 @@ async function logMessagesAndSendErrorsToBrowser(
} }
} }
async function spawnStaticShellValidationInDev(
...args: Parameters<typeof spawnStaticShellValidationInDevImpl>
) {
if (process.env.__NEXT_TEST_MODE && process.env.NEXT_TEST_LOG_VALIDATION) {
const ctx: AppRenderContext = args[5]
const requestId = ctx.requestId
const url = ctx.url.href
console.log(
'<VALIDATION_MESSAGE>' +
JSON.stringify({ type: 'validation_start', requestId, url }) +
'</VALIDATION_MESSAGE>'
)
try {
return await spawnStaticShellValidationInDevImpl(...args)
} finally {
console.log(
'<VALIDATION_MESSAGE>' +
JSON.stringify({ type: 'validation_end', requestId, url }) +
'</VALIDATION_MESSAGE>'
)
}
} else {
return await spawnStaticShellValidationInDevImpl(...args)
}
}
/** /**
* This function is a fork of prerenderToStream cacheComponents branch. * This function is a fork of prerenderToStream cacheComponents branch.
* While it doesn't return a stream we want it to have identical * While it doesn't return a stream we want it to have identical
* prerender semantics to prerenderToStream and should update it * prerender semantics to prerenderToStream and should update it
* in conjunction with any changes to that function. * in conjunction with any changes to that function.
*/ */
async function spawnStaticShellValidationInDev( async function spawnStaticShellValidationInDevImpl(
accumulatedChunksPromise: Promise<AccumulatedStreamChunks>, accumulatedChunksPromise: Promise<AccumulatedStreamChunks>,
syncInterruptReason: Error | null, syncInterruptReason: Error | null,
startTime: number, startTime: number,
......
...@@ -28,7 +28,6 @@ async function Runtime() { ...@@ -28,7 +28,6 @@ async function Runtime() {
} }
async function Dynamic() { async function Dynamic() {
await new Promise((resolve) => setTimeout(resolve, 1000))
await connection() await connection()
return <div id="dynamic-content">Dynamic content from page</div> return <div id="dynamic-content">Dynamic content from page</div>
} }
...@@ -896,11 +896,14 @@ export async function waitForNoRedbox( ...@@ -896,11 +896,14 @@ export async function waitForNoRedbox(
} }
} }
export async function waitForNoErrorToast(browser: Playwright): Promise<void> { export async function waitForNoErrorToast(
browser: Playwright,
{ waitInMs }: { waitInMs?: number } = {}
): Promise<void> {
let didOpenRedbox = false let didOpenRedbox = false
try { try {
await browser.waitForElementByCss('[data-issues]').click() await browser.waitForElementByCss('[data-issues]', waitInMs).click()
didOpenRedbox = true didOpenRedbox = true
} catch { } catch {
// We expect this to fail. // We expect this to fail.
......
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