Skip to content

Commit 3c6936c

Browse files
authored
[ppr] Test fixes for deployment tests (vercel#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.
1 parent f7d5e14 commit 3c6936c

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

test/e2e/app-dir/ppr-navigations/incremental/incremental.test.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { NextInstance, nextTestSetup } from 'e2e-utils'
22
import { links, locales } from './components/page'
33
import glob from 'glob'
44
import { promisify } from 'node:util'
5+
import { waitForHydration } from 'development-sandbox'
6+
import { setTimeout } from 'node:timers/promises'
57

68
const globp = promisify(glob)
79

@@ -15,15 +17,22 @@ async function getDotNextFiles(next: NextInstance): Promise<Array<string>> {
1517
}
1618

1719
describe('ppr-navigations incremental', () => {
18-
const { next, isNextDev, isTurbopack } = nextTestSetup({
20+
const { next, isNextDev, isTurbopack, isNextDeploy } = nextTestSetup({
1921
files: __dirname,
2022
})
2123

2224
it('can navigate between all the links and back without writing to disk', async () => {
23-
const before = !isNextDev && !isTurbopack ? await getDotNextFiles(next) : []
25+
const before =
26+
!isNextDev && !isTurbopack && !isNextDeploy
27+
? await getDotNextFiles(next)
28+
: []
2429

2530
const browser = await next.browser('/')
2631

32+
await browser.waitForIdleNetwork()
33+
await waitForHydration(browser)
34+
await setTimeout(500)
35+
2736
// Add a variable to the window so we can tell if it MPA navigated. If this
2837
// value is still true at the end of the test, then we know that the page
2938
// didn't MPA navigate.
@@ -33,14 +42,11 @@ describe('ppr-navigations incremental', () => {
3342
try {
3443
for (const { href } of links) {
3544
// Find the link element for the href and click it.
36-
await browser.elementByCss(`a[href="/api/flow.js?q=https%3A%2F%2Fgithub.com%2Felibobcoder%2Fnext.js%2Fcommit%2F%253Cspan%2520class%3D"pl-s1">${href}"]`).click()
45+
await browser.waitForElementByCss(`a[href="/api/flow.js?q=https%3A%2F%2Fgithub.com%2Felibobcoder%2Fnext.js%2Fcommit%2F%253Cspan%2520class%3D"pl-s1">${href}"]`).click()
3746

38-
// Wait for the network to be idle. This seems odd, but this is to help
39-
// catch the condition where a rouge 404 triggers a MPA navigation.
4047
await browser.waitForIdleNetwork()
41-
42-
// Check if the page navigated.
43-
expect(await browser.eval(`window.random`)).toBe(random)
48+
await waitForHydration(browser)
49+
await setTimeout(500)
4450

4551
// Wait for that page to load.
4652
if (href === '/') {
@@ -50,13 +56,16 @@ describe('ppr-navigations incremental', () => {
5056
await browser.waitForElementByCss(`[data-value="${href}"]`)
5157
}
5258

53-
await browser.elementByCss('#dynamic')
59+
await browser.waitForElementByCss('#dynamic', 1500)
60+
61+
// Check if the page navigated.
62+
expect(await browser.eval(`window.random`)).toBe(random)
5463
}
5564
} finally {
5665
await browser.close()
5766
}
5867

59-
if (!isNextDev && !isTurbopack) {
68+
if (!isNextDev && !isTurbopack && !isNextDeploy) {
6069
const after = await getDotNextFiles(next)
6170

6271
// Ensure that no new files were written to disk. If this test fails, it's

0 commit comments

Comments
 (0)