Unverified Commit 3c6936cf authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

[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.
parent f7d5e148
...@@ -2,6 +2,8 @@ import { NextInstance, nextTestSetup } from 'e2e-utils' ...@@ -2,6 +2,8 @@ import { NextInstance, nextTestSetup } from 'e2e-utils'
import { links, locales } from './components/page' import { links, locales } from './components/page'
import glob from 'glob' import glob from 'glob'
import { promisify } from 'node:util' import { promisify } from 'node:util'
import { waitForHydration } from 'development-sandbox'
import { setTimeout } from 'node:timers/promises'
const globp = promisify(glob) const globp = promisify(glob)
...@@ -15,15 +17,22 @@ async function getDotNextFiles(next: NextInstance): Promise<Array<string>> { ...@@ -15,15 +17,22 @@ async function getDotNextFiles(next: NextInstance): Promise<Array<string>> {
} }
describe('ppr-navigations incremental', () => { describe('ppr-navigations incremental', () => {
const { next, isNextDev, isTurbopack } = nextTestSetup({ const { next, isNextDev, isTurbopack, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('can navigate between all the links and back without writing to disk', async () => { 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('/') 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 // 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 // value is still true at the end of the test, then we know that the page
// didn't MPA navigate. // didn't MPA navigate.
...@@ -33,14 +42,11 @@ describe('ppr-navigations incremental', () => { ...@@ -33,14 +42,11 @@ describe('ppr-navigations incremental', () => {
try { try {
for (const { href } of links) { for (const { href } of links) {
// Find the link element for the href and click it. // 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() await browser.waitForIdleNetwork()
await waitForHydration(browser)
// Check if the page navigated. await setTimeout(500)
expect(await browser.eval(`window.random`)).toBe(random)
// Wait for that page to load. // Wait for that page to load.
if (href === '/') { if (href === '/') {
...@@ -50,13 +56,16 @@ describe('ppr-navigations incremental', () => { ...@@ -50,13 +56,16 @@ describe('ppr-navigations incremental', () => {
await browser.waitForElementByCss(`[data-value="${href}"]`) 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 { } finally {
await browser.close() await browser.close()
} }
if (!isNextDev && !isTurbopack) { if (!isNextDev && !isTurbopack && !isNextDeploy) {
const after = await getDotNextFiles(next) const after = await getDotNextFiles(next)
// Ensure that no new files were written to disk. If this test fails, it's // Ensure that no new files were written to disk. If this test fails, it's
......
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