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

Tweak flakey on-demand revalidate test #63953

Merged
merged 2 commits into from
Apr 1, 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
33 changes: 15 additions & 18 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
hasRedbox,
normalizeRegEx,
renderViaHTTP,
retry,
waitFor,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
Expand Down Expand Up @@ -2132,18 +2133,11 @@ describe('Prerender', () => {

if (!isDev) {
it('should handle on-demand revalidate for fallback: blocking', async () => {
const beforeRevalidate = Date.now()
const res = await fetchViaHTTP(
next.url,
'/blocking-fallback/test-manual-1'
)

if (!isDeploy) {
await waitForCacheWrite(
'/blocking-fallback/test-manual-1',
beforeRevalidate
)
}
const html = await res.text()
const $ = cheerio.load(html)
const initialTime = $('#time').text()
Expand All @@ -2153,15 +2147,19 @@ describe('Prerender', () => {
expect($('p').text()).toMatch(/Post:.*?test-manual-1/)

if (!isDeploy) {
const res2 = await fetchViaHTTP(
next.url,
'/blocking-fallback/test-manual-1'
)
const html2 = await res2.text()
const $2 = cheerio.load(html2)
// we use retry here as the cache might still be
// writing to disk even after the above request has finished
await retry(async () => {
const res2 = await fetchViaHTTP(
next.url,
'/blocking-fallback/test-manual-1'
)
const html2 = await res2.text()
const $2 = cheerio.load(html2)

expect(res2.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/)
expect(initialTime).toBe($2('#time').text())
expect(res2.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/)
expect(initialTime).toBe($2('#time').text())
})
}

const res3 = await fetchViaHTTP(
Expand All @@ -2177,7 +2175,7 @@ describe('Prerender', () => {
const revalidateData = await res3.json()
expect(revalidateData.revalidated).toBe(true)

await check(async () => {
await retry(async () => {
const res4 = await fetchViaHTTP(
next.url,
'/blocking-fallback/test-manual-1'
Expand All @@ -2186,8 +2184,7 @@ describe('Prerender', () => {
const $4 = cheerio.load(html4)
expect($4('#time').text()).not.toBe(initialTime)
expect(res4.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/)
return 'success'
}, 'success')
})
})
}

Expand Down