From 8d979b62333cc2732dccf85838c41338f5c12732 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Tue, 26 Mar 2024 14:47:22 -0700 Subject: [PATCH] de-flake prerender-prefetch test (#63739) This test frequently fails, likely because it's possible to navigate before the revalidation finishes [x-ref](https://github.com/vercel/next.js/actions/runs/8441089149/job/23119594182#step:27:299) [x-ref](https://github.com/vercel/next.js/actions/runs/8441133466/job/23119898500?pr=63606#step:27:297) Closes NEXT-2942 --- .../prerender-prefetch/index.test.ts | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/production/prerender-prefetch/index.test.ts b/test/production/prerender-prefetch/index.test.ts index 579c200daf9da..9b314e58b1d8a 100644 --- a/test/production/prerender-prefetch/index.test.ts +++ b/test/production/prerender-prefetch/index.test.ts @@ -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' @@ -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" })' @@ -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" })'