Skip to content

Instantly share code, notes, and snippets.

@sommeeeer
Last active March 18, 2025 08:16
Show Gist options
  • Select an option

  • Save sommeeeer/61bdb0f05dba6bdcd43710bfa358ae68 to your computer and use it in GitHub Desktop.

Select an option

Save sommeeeer/61bdb0f05dba6bdcd43710bfa358ae68 to your computer and use it in GitHub Desktop.
e2e test
test("revalidate should work in GET route handler", async ({
request,
page,
}) => {
let time = Date.parse(
(await request.get("/methods/get/revalidate").then((res) => res.json()))
.time,
);
let newTime: number;
let tempTime = time;
do {
await page.waitForTimeout(1000);
time = tempTime;
const newTimeRes = await request.get("/methods/get/revalidate");
newTime = Date.parse((await newTimeRes.json()).time);
tempTime = newTime;
} while (time !== newTime);
const midTime = Date.parse(
(await request.get("/methods/get/revalidate").then((res) => res.json()))
.time,
);
await page.waitForTimeout(1000);
// Expect that the time is still stale
expect(midTime).toEqual(newTime);
// Wait 5 + 1 seconds for ISR to regenerate time
await page.waitForTimeout(6000);
let finalTime = newTime;
do {
await page.waitForTimeout(2000);
finalTime = Date.parse(
(await request.get("/methods/get/revalidate").then((res) => res.json()))
.time,
);
}
while (newTime === finalTime);
expect(newTime).not.toEqual(finalTime);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment