[ppr] Test fixes for deployment tests (#67256)
Fixes some possible race conditions by adding a few delays to the navigation test to ensure that we wait for hydration to occur and prefetches to finish.
This commit is contained in:
parent
f7d5e14863
commit
3c6936cfbd
1 changed files with 19 additions and 10 deletions
|
@ -2,6 +2,8 @@ import { NextInstance, nextTestSetup } from 'e2e-utils'
|
|||
import { links, locales } from './components/page'
|
||||
import glob from 'glob'
|
||||
import { promisify } from 'node:util'
|
||||
import { waitForHydration } from 'development-sandbox'
|
||||
import { setTimeout } from 'node:timers/promises'
|
||||
|
||||
const globp = promisify(glob)
|
||||
|
||||
|
@ -15,15 +17,22 @@ async function getDotNextFiles(next: NextInstance): Promise<Array<string>> {
|
|||
}
|
||||
|
||||
describe('ppr-navigations incremental', () => {
|
||||
const { next, isNextDev, isTurbopack } = nextTestSetup({
|
||||
const { next, isNextDev, isTurbopack, isNextDeploy } = nextTestSetup({
|
||||
files: __dirname,
|
||||
})
|
||||
|
||||
it('can navigate between all the links and back without writing to disk', async () => {
|
||||
const before = !isNextDev && !isTurbopack ? await getDotNextFiles(next) : []
|
||||
const before =
|
||||
!isNextDev && !isTurbopack && !isNextDeploy
|
||||
? await getDotNextFiles(next)
|
||||
: []
|
||||
|
||||
const browser = await next.browser('/')
|
||||
|
||||
await browser.waitForIdleNetwork()
|
||||
await waitForHydration(browser)
|
||||
await setTimeout(500)
|
||||
|
||||
// Add a variable to the window so we can tell if it MPA navigated. If this
|
||||
// value is still true at the end of the test, then we know that the page
|
||||
// didn't MPA navigate.
|
||||
|
@ -33,14 +42,11 @@ describe('ppr-navigations incremental', () => {
|
|||
try {
|
||||
for (const { href } of links) {
|
||||
// Find the link element for the href and click it.
|
||||
await browser.elementByCss(`a[href="${href}"]`).click()
|
||||
await browser.waitForElementByCss(`a[href="${href}"]`).click()
|
||||
|
||||
// Wait for the network to be idle. This seems odd, but this is to help
|
||||
// catch the condition where a rouge 404 triggers a MPA navigation.
|
||||
await browser.waitForIdleNetwork()
|
||||
|
||||
// Check if the page navigated.
|
||||
expect(await browser.eval(`window.random`)).toBe(random)
|
||||
await waitForHydration(browser)
|
||||
await setTimeout(500)
|
||||
|
||||
// Wait for that page to load.
|
||||
if (href === '/') {
|
||||
|
@ -50,13 +56,16 @@ describe('ppr-navigations incremental', () => {
|
|||
await browser.waitForElementByCss(`[data-value="${href}"]`)
|
||||
}
|
||||
|
||||
await browser.elementByCss('#dynamic')
|
||||
await browser.waitForElementByCss('#dynamic', 1500)
|
||||
|
||||
// Check if the page navigated.
|
||||
expect(await browser.eval(`window.random`)).toBe(random)
|
||||
}
|
||||
} finally {
|
||||
await browser.close()
|
||||
}
|
||||
|
||||
if (!isNextDev && !isTurbopack) {
|
||||
if (!isNextDev && !isTurbopack && !isNextDeploy) {
|
||||
const after = await getDotNextFiles(next)
|
||||
|
||||
// Ensure that no new files were written to disk. If this test fails, it's
|
||||
|
|
Loading…
Reference in a new issue