Unverified Commit 35e16f75 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Tweak flakey prefetch test handling (#53391)

Seems this one is still finicky so re-works it some more. 

x-ref: https://github.com/vercel/next.js/actions/runs/5716005333/job/15486690109
parent de873d02
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
import { createNext, FileRef } from 'e2e-utils' import { createNext, FileRef } from 'e2e-utils'
import { check, fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils' import { check, fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils'
import cheerio from 'cheerio'
import { join } from 'path' import { join } from 'path'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import assert from 'assert' import assert from 'assert'
...@@ -15,36 +14,9 @@ describe('Prerender prefetch', () => { ...@@ -15,36 +14,9 @@ describe('Prerender prefetch', () => {
optimisticClientCache?: boolean optimisticClientCache?: boolean
}) => { }) => {
it('should not revalidate during prefetching', async () => { it('should not revalidate during prefetching', async () => {
// restart revalidate period const cliOutputStart = next.cliOutput.length
for (const path of ['/blog/first', '/blog/second']) {
await fetchViaHTTP(next.url, path)
await check(
// eslint-disable-next-line no-loop-func
async () => {
return fetchViaHTTP(next.url, path).then((res) =>
res.headers.get('x-nextjs-cache')
)
},
/HIT/
)
}
const reqs = {} for (let i = 0; i < 3; i++) {
// get initial values
for (const path of ['/blog/first', '/blog/second']) {
const res = await fetchViaHTTP(next.url, path)
expect(res.status).toBe(200)
const $ = cheerio.load(await res.text())
const props = JSON.parse($('#props').text())
reqs[path] = props
}
// wait revalidate period
await waitFor(3000)
// do prefetch requests
for (const path of ['/blog/first', '/blog/second']) { for (const path of ['/blog/first', '/blog/second']) {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
next.url, next.url,
...@@ -58,16 +30,13 @@ describe('Prerender prefetch', () => { ...@@ -58,16 +30,13 @@ describe('Prerender prefetch', () => {
) )
expect(res.status).toBe(200) expect(res.status).toBe(200)
} }
// do requests three times with 1 second between
// ensure revalidate did not occur from prefetch // to go over revalidate period
for (const path of ['/blog/first', '/blog/second']) { await waitFor(1000)
const res = await fetchViaHTTP(next.url, path)
expect(res.status).toBe(200)
const $ = cheerio.load(await res.text())
const props = JSON.parse($('#props').text())
expect(props).toEqual(reqs[path])
} }
expect(next.cliOutput.substring(cliOutputStart)).not.toContain(
'revalidating /blog'
)
}) })
it('should trigger revalidation after navigation', async () => { it('should trigger revalidation after navigation', async () => {
......
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