|
| 1 | +import { expect, Page } from "@playwright/test"; |
| 2 | +import getPort from "get-port"; |
| 3 | + |
| 4 | +import { matchLine, testTemplate, urlRegex } from "./utils"; |
| 5 | + |
| 6 | +const test = testTemplate("deno", "deno install"); |
| 7 | + |
| 8 | +test("typecheck", async ({ $ }) => { |
| 9 | + await $(`deno task typecheck`); |
| 10 | +}); |
| 11 | + |
| 12 | +test("dev", async ({ page, $ }) => { |
| 13 | + const port = await getPort(); |
| 14 | + const dev = $(`deno task dev --port ${port}`); |
| 15 | + |
| 16 | + const url = await matchLine(dev.stdout, urlRegex.viteDev); |
| 17 | + |
| 18 | + await workflow({ page, url }); |
| 19 | + const [, ...restLines] = dev.buffer.stderr.split("\n"); |
| 20 | + expect(restLines.join("\n")).toBe(""); |
| 21 | +}); |
| 22 | + |
| 23 | +test("build + start", async ({ page, $ }) => { |
| 24 | + await $(`deno task build`); |
| 25 | + |
| 26 | + const port = await getPort(); |
| 27 | + const start = $(`deno task start`, { env: { PORT: String(port) } }); |
| 28 | + |
| 29 | + const url = await matchLine(start.stderr, urlRegex.deno); |
| 30 | + const localURL = new URL(url); |
| 31 | + localURL.hostname = "localhost"; |
| 32 | + |
| 33 | + await workflow({ page, url: localURL.href }); |
| 34 | + const [, ...restLines] = start.buffer.stderr.split("\n"); |
| 35 | + expect(restLines.join("\n")).toBe( |
| 36 | + `Listening on ${url} (${localURL})\n`, |
| 37 | + ); |
| 38 | +}); |
| 39 | + |
| 40 | +async function workflow({ page, url }: { page: Page; url: string }) { |
| 41 | + await page.goto(url); |
| 42 | + await page.getByRole("link", { name: "React Router Docs" }).waitFor(); |
| 43 | + await page.getByRole("link", { name: "Join Discord" }).waitFor(); |
| 44 | + await expect(page).toHaveTitle(/New React Router App/); |
| 45 | + expect(page.errors).toStrictEqual([]); |
| 46 | +} |
0 commit comments