Unverified Commit 694b3756 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update flakey E2E deploy tests (#89792)

These have been flaking for quite a while but when going through the
steps manually on the deployments they do not repro issues so this
appears to be flakey assertions from timing.

x-ref:
https://github.com/vercel/next.js/actions/runs/21881258559/job/63170127185
parent 381aa36e
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { createRouterAct } from 'router-act' import { createRouterAct } from 'router-act'
import { setTimeout } from 'node:timers/promises' import { setTimeout } from 'node:timers/promises'
import { retry } from 'next-test-utils'
describe('parallel-routes-root-param-dynamic-child', () => { describe('parallel-routes-root-param-dynamic-child', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
async function createBrowserActor(url: string, errorPage: boolean = false) { async function createBrowserActor(
url: string,
{
errorPage = false,
waitForPrefetch = false,
}: {
errorPage?: boolean
waitForPrefetch?: boolean
} = {}
) {
let act: ReturnType<typeof createRouterAct> let act: ReturnType<typeof createRouterAct>
const browser = await next.browser(url, { const browser = await next.browser(url, {
beforePageLoad(page) { beforePageLoad(page) {
...@@ -22,6 +32,7 @@ describe('parallel-routes-root-param-dynamic-child', () => { ...@@ -22,6 +32,7 @@ describe('parallel-routes-root-param-dynamic-child', () => {
return { act, browser } return { act, browser }
} }
if (waitForPrefetch) {
// The page has navigation links that will be automatically prefetched. // The page has navigation links that will be automatically prefetched.
// Some routes will 404 (like /es which isn't in generateStaticParams), // Some routes will 404 (like /es which isn't in generateStaticParams),
// so we allow 404 status codes. Let's reveal the navigation links and let // so we allow 404 status codes. Let's reveal the navigation links and let
...@@ -45,6 +56,15 @@ describe('parallel-routes-root-param-dynamic-child', () => { ...@@ -45,6 +56,15 @@ describe('parallel-routes-root-param-dynamic-child', () => {
// If we're in development, we don't have any prefetching to wait for. // If we're in development, we don't have any prefetching to wait for.
isNextDev ? 'no-requests' : undefined isNextDev ? 'no-requests' : undefined
) )
} else {
// Most assertions only need the nav revealed, and should not block on
// background prefetch request completion.
await browser.elementByCss('#reveal').click()
await browser.elementByCss('#nav')
await setTimeout(500)
await browser.eval('window.scrollTo(0, document.body.scrollHeight)')
await setTimeout(500)
}
return { act, browser } return { act, browser }
} }
...@@ -52,7 +72,7 @@ describe('parallel-routes-root-param-dynamic-child', () => { ...@@ -52,7 +72,7 @@ describe('parallel-routes-root-param-dynamic-child', () => {
if (!isNextDev) { if (!isNextDev) {
describe('Prefetching', () => { describe('Prefetching', () => {
it('prefetches the 404 pages correctly', async () => { it('prefetches the 404 pages correctly', async () => {
await createBrowserActor('/en') await createBrowserActor('/en', { waitForPrefetch: true })
// If we got here without errors, the prefetch responses completed successfully // If we got here without errors, the prefetch responses completed successfully
// without problematic redirects (like 307). Those will throw because // without problematic redirects (like 307). Those will throw because
...@@ -67,14 +87,16 @@ describe('parallel-routes-root-param-dynamic-child', () => { ...@@ -67,14 +87,16 @@ describe('parallel-routes-root-param-dynamic-child', () => {
async (locale) => { async (locale) => {
const { browser } = await createBrowserActor(`/${locale}`) const { browser } = await createBrowserActor(`/${locale}`)
await retry(async () => {
expect(await browser.elementByCss('#locale-page').text()).toBe( expect(await browser.elementByCss('#locale-page').text()).toBe(
`Locale: ${locale}` `Locale: ${locale}`
) )
})
} }
) )
it('should render a 404 for /es (not in generateStaticParams)', async () => { it('should render a 404 for /es (not in generateStaticParams)', async () => {
const { browser } = await createBrowserActor('/es', true) const { browser } = await createBrowserActor('/es', { errorPage: true })
expect(await browser.elementByCss('.next-error-h1').text()).toBe('404') expect(await browser.elementByCss('.next-error-h1').text()).toBe('404')
}) })
...@@ -92,12 +114,14 @@ describe('parallel-routes-root-param-dynamic-child', () => { ...@@ -92,12 +114,14 @@ describe('parallel-routes-root-param-dynamic-child', () => {
.click() .click()
}) })
await retry(async () => {
expect(await browser.elementByCss('#story-locale').text()).toBe( expect(await browser.elementByCss('#story-locale').text()).toBe(
`Locale: ${locale}` `Locale: ${locale}`
) )
expect(await browser.elementByCss('#story-slug').text()).toBe( expect(await browser.elementByCss('#story-slug').text()).toBe(
'Story: dynamic-123' 'Story: dynamic-123'
) )
})
} }
) )
...@@ -130,12 +154,14 @@ describe('parallel-routes-root-param-dynamic-child', () => { ...@@ -130,12 +154,14 @@ describe('parallel-routes-root-param-dynamic-child', () => {
.click() .click()
}) })
await retry(async () => {
expect(await browser.elementByCss('#story-locale').text()).toBe( expect(await browser.elementByCss('#story-locale').text()).toBe(
`Locale: ${locale}` `Locale: ${locale}`
) )
expect(await browser.elementByCss('#story-slug').text()).toBe( expect(await browser.elementByCss('#story-slug').text()).toBe(
'Story: static-123' 'Story: static-123'
) )
})
} }
) )
...@@ -157,9 +183,11 @@ describe('parallel-routes-root-param-dynamic-child', () => { ...@@ -157,9 +183,11 @@ describe('parallel-routes-root-param-dynamic-child', () => {
.click() .click()
}) })
await retry(async () => {
expect(await browser.elementByCss('.next-error-h1').text()).toBe( expect(await browser.elementByCss('.next-error-h1').text()).toBe(
'404' '404'
) )
})
} }
) )
......
...@@ -81,7 +81,17 @@ describe('app-dir trailingSlash handling', () => { ...@@ -81,7 +81,17 @@ describe('app-dir trailingSlash handling', () => {
.elementById('generated-at') .elementById('generated-at')
.text() .text()
expect(refreshedGeneratedAt).toBe(initialGeneratedAt) // A previous test can trigger revalidation right before this one starts.
// Assert the page is stable across consecutive refreshes instead of
// requiring the very first refresh to always match the initial load.
await retry(async () => {
await browser.refresh()
const refreshedAgainGeneratedAt = await browser
.elementById('generated-at')
.text()
expect(refreshedAgainGeneratedAt).toBe(refreshedGeneratedAt)
})
} }
await browser await browser
......
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