Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

de-flake prerender-prefetch test #63739

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion test/production/prerender-prefetch/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { NextInstance } from 'test/lib/next-modes/base'
import { createNext, FileRef } from 'e2e-utils'
import { check, fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils'
import {
check,
fetchViaHTTP,
renderViaHTTP,
retry,
waitFor,
} from 'next-test-utils'
import { join } from 'path'
import webdriver from 'next-webdriver'
import assert from 'assert'
Expand Down Expand Up @@ -95,6 +101,22 @@ describe('Prerender prefetch', () => {
return next.cliOutput.substring(outputIndex)
}, /revalidating \/blog first/)

// wait for the revalidation to finish by comparing timestamps
await retry(async () => {
const timeRes = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}/blog/first.json`,
undefined,
{
headers: {
purpose: 'prefetch',
},
}
)
const updatedTime = (await timeRes.json()).pageProps.now
expect(updatedTime).not.toBe(startTime)
})

// now trigger cache update and navigate again
await browser.eval(
'next.router.prefetch("/blog/first", undefined, { unstable_skipClientCache: true }).finally(() => { window.prefetchDone = "yes" })'
Expand Down Expand Up @@ -142,6 +164,22 @@ describe('Prerender prefetch', () => {
return next.cliOutput.substring(outputIndex)
}, /revalidating \/blog first/)

// wait for the revalidation to finish by comparing timestamps
await retry(async () => {
const timeRes = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}/blog/first.json`,
undefined,
{
headers: {
purpose: 'prefetch',
},
}
)
const updatedTime = (await timeRes.json()).pageProps.now
expect(updatedTime).not.toBe(startTime)
})

// now trigger cache update and navigate again
await browser.eval(
'next.router.push("/blog/first", undefined, { unstable_skipClientCache: true }).finally(() => { window.prefetchDone = "yes" })'
Expand Down