-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathbase.spec.ts
More file actions
36 lines (29 loc) · 1.18 KB
/
base.spec.ts
File metadata and controls
36 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { test, expect } from "@playwright/test";
test.describe("r2-incremental-cache", () => {
test("the index page should work", async ({ page }) => {
await page.goto("/");
await expect(page.getByText("Hello from a Statically generated page")).toBeVisible();
});
test("the index page should revalidate", async ({ page, request }) => {
// We need to make sure the page is loaded and is a HIT
// If it is STALE, the next hit may have an updated date and thus fail the test
let cacheHeaders = "";
do {
const req = await request.get("/");
cacheHeaders = req.headers()["x-nextjs-cache"];
await page.waitForTimeout(500);
} while (cacheHeaders !== "HIT");
await page.goto("/");
const firstDate = await page.getByTestId("date-local").textContent();
await page.reload();
let newDate = await page.getByTestId("date-local").textContent();
expect(newDate).toBe(firstDate);
await page.waitForTimeout(5000);
do {
await page.reload();
newDate = await page.getByTestId("date-local").textContent();
await page.waitForTimeout(1000);
} while (newDate === firstDate);
expect(newDate).not.toBe(firstDate);
});
});