mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-23 16:13:04 +00:00
fix(e2e S1): poll positivo do HTML da home até convergir pós-revalidate
O warm-up único ainda deixava uma janela de stale-serve sob carga (a regeneração ISR não completava entre o GET e o goto, e o DOM carregado nunca refrescava — flake no cleanup sob a suíte paralela). Polling do estado esperado no HTML do servidor (12x1s) antes do goto torna o empty-state, o full-state e o cleanup determinísticos.
This commit is contained in:
parent
0949ded185
commit
f1c2daf4a2
1 changed files with 26 additions and 9 deletions
|
|
@ -481,11 +481,28 @@ test.describe('Campaign home content section', () => {
|
||||||
return doc
|
return doc
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISR serves the stale page once while it regenerates after a revalidateTag
|
// ISR serves the stale page while it regenerates after a revalidateTag
|
||||||
// (slower under the parallel suite). A warm-up GET triggers that
|
// (slower under the parallel suite), and a navigation that lands on it never
|
||||||
// regeneration so the navigation that follows always lands on fresh HTML.
|
// refreshes its DOM. Poll the server HTML positively until it converges to
|
||||||
const warmHome = async (request: APIRequestContext) => {
|
// the expected section state; the navigation that follows then always lands
|
||||||
await request.get(`${baseURL}/`).catch(() => undefined)
|
// on the fresh page.
|
||||||
|
const waitForHomeSectionState = async (
|
||||||
|
request: APIRequestContext,
|
||||||
|
expected: 'present' | 'absent',
|
||||||
|
attempts = 12,
|
||||||
|
) => {
|
||||||
|
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 present = html.includes('data-home-section="contents"')
|
||||||
|
if (present === (expected === 'present')) return
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1_000))
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
`A home não convergiu para o estado "${expected}" da seção de conteúdos após ${attempts}s.`,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
test('hides the content section while no articles are visible', async ({ page, request }) => {
|
test('hides the content section while no articles are visible', async ({ page, request }) => {
|
||||||
|
|
@ -497,7 +514,7 @@ test.describe('Campaign home content section', () => {
|
||||||
headers: { 'x-revalidate-secret': revalidateSecret },
|
headers: { 'x-revalidate-secret': revalidateSecret },
|
||||||
})
|
})
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
await warmHome(request)
|
await waitForHomeSectionState(request, 'absent')
|
||||||
|
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
await expect(page).toHaveURL(/\/$/)
|
await expect(page).toHaveURL(/\/$/)
|
||||||
|
|
@ -574,8 +591,8 @@ test.describe('Campaign home content section', () => {
|
||||||
try {
|
try {
|
||||||
await page.setViewportSize({ width: 1280, height: 900 })
|
await page.setViewportSize({ width: 1280, height: 900 })
|
||||||
// The create hooks revalidated the `posts` tag in the server process;
|
// The create hooks revalidated the `posts` tag in the server process;
|
||||||
// warm the home so the navigation lands on the regenerated page.
|
// wait until the regenerated page actually shows the section.
|
||||||
await warmHome(request)
|
await waitForHomeSectionState(request, 'present')
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
const section = page.locator('[data-home-section="contents"]')
|
const section = page.locator('[data-home-section="contents"]')
|
||||||
await expect(section).toBeVisible()
|
await expect(section).toBeVisible()
|
||||||
|
|
@ -663,7 +680,7 @@ test.describe('Campaign home content section', () => {
|
||||||
|
|
||||||
// Converge the persisted dev cache back to the empty state so the
|
// Converge the persisted dev cache back to the empty state so the
|
||||||
// next run starts deterministic (fail-closed on delete, too).
|
// next run starts deterministic (fail-closed on delete, too).
|
||||||
await warmHome(request)
|
await waitForHomeSectionState(request, 'absent')
|
||||||
await page.setViewportSize({ width: 1280, height: 900 })
|
await page.setViewportSize({ width: 1280, height: 900 })
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
await expect(page.locator('[data-home-section="contents"]')).toHaveCount(0)
|
await expect(page.locator('[data-home-section="contents"]')).toHaveCount(0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue