|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +/** |
| 3 | + * This tests that the "redirect" config in next.config.js works |
| 4 | + * |
| 5 | + * redirects: () => { |
| 6 | + return [ |
| 7 | + { |
| 8 | + source: "/next-config-redirect", |
| 9 | + destination: "/config-redirect", |
| 10 | + permanent: true, |
| 11 | + missing: [{ type: "cookie", key: "missing-cookie" }], |
| 12 | + }, |
| 13 | + ]; |
| 14 | + }, |
| 15 | + */ |
| 16 | +test.describe("Next Config Redirect", () => { |
| 17 | + test("Missing cookies", async ({ page }) => { |
| 18 | + await page.goto("/"); |
| 19 | + await page.goto("/next-config-redirect-missing"); |
| 20 | + |
| 21 | + await page.waitForURL("/config-redirect?missing=true"); |
| 22 | + |
| 23 | + const el = page.getByText("I was redirected from next.config.js", { |
| 24 | + exact: true, |
| 25 | + }); |
| 26 | + await expect(el).toBeVisible(); |
| 27 | + }); |
| 28 | + test("Not missing cookies", async ({ page }) => { |
| 29 | + await page.goto("/"); |
| 30 | + await page.goto("/next-config-redirect-not-missing"); |
| 31 | + |
| 32 | + // the cookie was not missing, so no redirects |
| 33 | + await page.waitForURL("/next-config-redirect-not-missing"); |
| 34 | + |
| 35 | + const el = page.getByText("This page could not be found.", { |
| 36 | + exact: true, |
| 37 | + }); |
| 38 | + await expect(el).toBeVisible(); |
| 39 | + }); |
| 40 | + test("Has cookies", async ({ page }) => { |
| 41 | + await page.goto("/"); |
| 42 | + await page.goto("/next-config-redirect-has"); |
| 43 | + |
| 44 | + await page.waitForURL("/config-redirect?has=true"); |
| 45 | + |
| 46 | + const el = page.getByText("I was redirected from next.config.js", { |
| 47 | + exact: true, |
| 48 | + }); |
| 49 | + await expect(el).toBeVisible(); |
| 50 | + }); |
| 51 | + test("Has cookies with value", async ({ page }) => { |
| 52 | + await page.goto("/"); |
| 53 | + await page.goto("/next-config-redirect-has-with-value"); |
| 54 | + |
| 55 | + await page.waitForURL("/config-redirect?hasWithValue=true"); |
| 56 | + |
| 57 | + const el = page.getByText("I was redirected from next.config.js", { |
| 58 | + exact: true, |
| 59 | + }); |
| 60 | + await expect(el).toBeVisible(); |
| 61 | + }); |
| 62 | + test("Has cookies with bad value", async ({ page }) => { |
| 63 | + await page.goto("/"); |
| 64 | + await page.goto("/next-config-redirect-has-with-bad-value"); |
| 65 | + |
| 66 | + // did not redirect |
| 67 | + await page.waitForURL("/next-config-redirect-has-with-bad-value"); |
| 68 | + |
| 69 | + // 404 not found |
| 70 | + const el = page.getByText("This page could not be found.", { |
| 71 | + exact: true, |
| 72 | + }); |
| 73 | + await expect(el).toBeVisible(); |
| 74 | + }); |
| 75 | +}); |
0 commit comments