|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +test("should not fail on an api route", async ({ page }) => { |
| 4 | + const result = await page.goto("/api/hello"); |
| 5 | + expect(result?.status()).toBe(200); |
| 6 | + const body = await result?.json(); |
| 7 | + expect(body).toEqual({ hello: "OpenNext rocks!" }); |
| 8 | +}); |
| 9 | + |
| 10 | +test("should work with dynamic api route", async ({ page }) => { |
| 11 | + const result = await page.goto("/api/dynamic/opennext"); |
| 12 | + expect(result?.status()).toBe(200); |
| 13 | + const body = await result?.json(); |
| 14 | + expect(body).toEqual({ slug: "opennext" }); |
| 15 | +}); |
| 16 | + |
| 17 | +test("should work with catch all api route", async ({ page }) => { |
| 18 | + const result = await page.goto("/api/dynamic/catch-all/first/second/third"); |
| 19 | + expect(result?.status()).toBe(200); |
| 20 | + const body = await result?.json(); |
| 21 | + expect(body).toEqual({ slug: ["first", "second", "third"] }); |
| 22 | +}); |
| 23 | + |
| 24 | +test("dynamic route should take precedence over catch all", async ({ |
| 25 | + page, |
| 26 | +}) => { |
| 27 | + const result = await page.goto("/api/dynamic/catch-all"); |
| 28 | + expect(result?.status()).toBe(200); |
| 29 | + const body = await result?.json(); |
| 30 | + expect(body).toEqual({ slug: "catch-all" }); |
| 31 | +}); |
| 32 | + |
| 33 | +test("should work with optional catch all api route", async ({ page }) => { |
| 34 | + const result = await page.goto("/api/dynamic/catch-all-optional"); |
| 35 | + expect(result?.status()).toBe(200); |
| 36 | + const body = await result?.json(); |
| 37 | + expect(body).toEqual({ optional: "true" }); |
| 38 | +}); |
| 39 | + |
| 40 | +// This should work but it doesn't. It seems that the predefined api route is not taking precedence. |
| 41 | +// Its broken in `next start` aswell. |
| 42 | +// Issue currently open in Next: https://github.com/vercel/next.js/issues/76765 |
| 43 | +test.skip("predefined api route should take presedence", async ({ page }) => { |
| 44 | + const result = await page.goto("/api/dynamic/precedence"); |
| 45 | + expect(result?.status()).toBe(200); |
| 46 | + const body = await result?.json(); |
| 47 | + expect(body).toEqual({ precedence: "true" }); |
| 48 | +}); |
0 commit comments