|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +test("Next after", async ({ request }) => { |
| 4 | + const initialSSG = await request.get("/api/after/ssg"); |
| 5 | + expect(initialSSG.status()).toEqual(200); |
| 6 | + const initialSSGJson = await initialSSG.json(); |
| 7 | + |
| 8 | + // We then fire a post request that will revalidate the SSG page 5 seconds after, but should respond immediately |
| 9 | + const dateNow = Date.now(); |
| 10 | + const revalidateSSG = await request.post("/api/after/revalidate"); |
| 11 | + expect(revalidateSSG.status()).toEqual(200); |
| 12 | + const revalidateSSGJson = await revalidateSSG.json(); |
| 13 | + expect(revalidateSSGJson.success).toEqual(true); |
| 14 | + // This request should take less than 5 seconds to respond |
| 15 | + expect(Date.now() - dateNow).toBeLessThan(5000); |
| 16 | + |
| 17 | + // We want to immediately check if the SSG page has been revalidated, it should not have been |
| 18 | + const notRevalidatedSSG = await request.get("/api/after/ssg"); |
| 19 | + expect(notRevalidatedSSG.status()).toEqual(200); |
| 20 | + const notRevalidatedSSGJson = await notRevalidatedSSG.json(); |
| 21 | + expect(notRevalidatedSSGJson.date).toEqual(initialSSGJson.date); |
| 22 | + |
| 23 | + // We then wait for 5 seconds to ensure the SSG page has been revalidated |
| 24 | + await new Promise((resolve) => setTimeout(resolve, 5000)); |
| 25 | + const revalidatedSSG = await request.get("/api/after/ssg"); |
| 26 | + expect(revalidatedSSG.status()).toEqual(200); |
| 27 | + const revalidatedSSGJson = await revalidatedSSG.json(); |
| 28 | + expect(revalidatedSSGJson.date).not.toEqual(initialSSGJson.date); |
| 29 | +}); |
0 commit comments