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,59 +14,29 @@ describe('Prerender prefetch', () => { ...@@ -15,59 +14,29 @@ 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) for (let i = 0; i < 3; i++) {
await check( for (const path of ['/blog/first', '/blog/second']) {
// eslint-disable-next-line no-loop-func const res = await fetchViaHTTP(
async () => { next.url,
return fetchViaHTTP(next.url, path).then((res) => `/_next/data/${next.buildId}${path}.json`,
res.headers.get('x-nextjs-cache') undefined,
) {
}, headers: {
/HIT/ purpose: 'prefetch',
) },
} }
)
const reqs = {} expect(res.status).toBe(200)
}
// get initial values // do requests three times with 1 second between
for (const path of ['/blog/first', '/blog/second']) { // to go over revalidate period
const res = await fetchViaHTTP(next.url, path) await waitFor(1000)
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])
} }
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