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 { createNext, FileRef } from 'e2e-utils'
import { check, fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils'
import cheerio from 'cheerio'
import { join } from 'path'
import webdriver from 'next-webdriver'
import assert from 'assert'
......@@ -15,59 +14,29 @@ describe('Prerender prefetch', () => {
optimisticClientCache?: boolean
}) => {
it('should not revalidate during prefetching', async () => {
// restart revalidate period
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 = {}
// 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']) {
const res = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}${path}.json`,
undefined,
{
headers: {
purpose: 'prefetch',
},
}
)
expect(res.status).toBe(200)
}
// ensure revalidate did not occur from prefetch
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())
expect(props).toEqual(reqs[path])
const cliOutputStart = next.cliOutput.length
for (let i = 0; i < 3; i++) {
for (const path of ['/blog/first', '/blog/second']) {
const res = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}${path}.json`,
undefined,
{
headers: {
purpose: 'prefetch',
},
}
)
expect(res.status).toBe(200)
}
// do requests three times with 1 second between
// to go over revalidate period
await waitFor(1000)
}
expect(next.cliOutput.substring(cliOutputStart)).not.toContain(
'revalidating /blog'
)
})
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