mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-14 17:43:04 +00:00
Some checks are pending
Deploy / preflight (push) Waiting to run
Deploy / verify (push) Blocked by required conditions
Deploy / deploy staging (teqo-staging) (push) Blocked by required conditions
Deploy / requeue when main advanced (push) Blocked by required conditions
Deploy / deploy production (teqo-1313) (push) Blocked by required conditions
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import type { APIRequestContext } from '@playwright/test'
|
|
|
|
/**
|
|
* S39/S44 — the shared ISR poll of the specs that own home sections. The home
|
|
* is served stale while it regenerates after a `revalidateTag` (slower under
|
|
* the parallel suite), and a navigation that lands on the stale body never
|
|
* refreshes its DOM. Poll the server HTML positively until it converges to the
|
|
* expected state; the navigation that follows then always lands on the fresh
|
|
* page. 12 attempts preserves the S1 convergence budget.
|
|
*/
|
|
export const waitForHomeHTML = async (
|
|
request: APIRequestContext,
|
|
baseUrl: string,
|
|
includes: string[],
|
|
excludes: string[] = [],
|
|
attempts = 12,
|
|
): Promise<void> => {
|
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
const response = await request.get(`${baseUrl}/`).catch(() => undefined)
|
|
if (response?.ok()) {
|
|
const html = await response.text()
|
|
const allIncluded = includes.every((needle) => html.includes(needle))
|
|
const anyExcluded = excludes.some((needle) => html.includes(needle))
|
|
if (allIncluded && !anyExcluded) return
|
|
}
|
|
await new Promise((resolve) => setTimeout(resolve, 1_000))
|
|
}
|
|
|
|
throw new Error(
|
|
`A home não convergiu após ${attempts}s (includes: ${includes.join(', ')}, excludes: ${excludes.join(', ')}).`,
|
|
)
|
|
}
|
|
|
|
/** The kill-switch/section-presence specialization of the HTML poll above. */
|
|
export const waitForHomeSection = async (
|
|
request: APIRequestContext,
|
|
baseUrl: string,
|
|
section: string,
|
|
expected: 'present' | 'absent',
|
|
attempts = 12,
|
|
): Promise<void> => {
|
|
const needle = `data-home-section="${section}"`
|
|
|
|
try {
|
|
await waitForHomeHTML(
|
|
request,
|
|
baseUrl,
|
|
expected === 'present' ? [needle] : [],
|
|
expected === 'present' ? [] : [needle],
|
|
attempts,
|
|
)
|
|
} catch (error) {
|
|
throw new Error(
|
|
`A seção "${section}" da home não convergiu para "${expected}" em ${attempts}s (${(error as Error).message}).`,
|
|
)
|
|
}
|
|
}
|