Skip to content

Commit c59754e

Browse files
committed
fix flaky test
1 parent 31c8a6f commit c59754e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

examples/overrides/memory-queue/e2e/base.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ test.describe("memory-queue", () => {
66
await expect(page.getByText("Hello from a Statically generated page")).toBeVisible();
77
});
88

9-
test("the index page should revalidate", async ({ page }) => {
9+
test("the index page should revalidate", async ({ page, request }) => {
10+
// We need to make sure the page is loaded and is a HIT
11+
// If it is STALE, the next hit may have an updated date and thus fail the test
12+
let cacheHeaders = "";
13+
do {
14+
const req = await request.get("/");
15+
cacheHeaders = req.headers()["x-nextjs-cache"];
16+
await page.waitForTimeout(500);
17+
} while (cacheHeaders !== "HIT");
18+
1019
await page.goto("/");
1120
const firstDate = await page.getByTestId("date-local").textContent();
12-
await page.waitForTimeout(5000);
13-
await page.reload();
1421

22+
await page.reload();
1523
let newDate = await page.getByTestId("date-local").textContent();
1624
expect(newDate).toBe(firstDate);
1725

26+
await page.waitForTimeout(5000);
27+
1828
do {
1929
await page.reload();
2030
newDate = await page.getByTestId("date-local").textContent();

0 commit comments

Comments
 (0)