feat: add Playwright for end-to-end testing and create initial test suite

This commit is contained in:
2026-01-20 01:18:26 +00:00
parent 5b01e6bfee
commit 565bc1f2ba
4 changed files with 141 additions and 1 deletions

37
tests/e2e/home.spec.ts Normal file
View File

@@ -0,0 +1,37 @@
import { expect, test } from "@playwright/test"
test.describe("home page", () => {
test("renders key sections without console errors", async ({ page }) => {
const consoleErrors: string[] = []
page.on("console", (message) => {
if (message.type() === "error") {
consoleErrors.push(message.text())
}
})
await page.goto("/")
await expect(page.getByRole("heading", { name: "My Snippets" })).toBeVisible()
await expect(
page.getByText("Save, organize, and share your code snippets", { exact: true })
).toBeVisible()
await expect(page.locator("header")).toBeVisible()
await expect(page.locator("main")).toBeVisible()
await expect(page.locator("footer")).toBeVisible()
expect(consoleErrors).toEqual([])
})
test("stays within viewport on mobile (no horizontal overflow)", async ({ page }, testInfo) => {
test.skip(!testInfo.project.name.includes("mobile"), "mobile-only check")
await page.goto("/")
const overflow = await page.evaluate(() =>
Math.max(document.documentElement.scrollWidth - window.innerWidth, 0)
)
expect(overflow).toBeLessThanOrEqual(1)
await expect(page.getByRole("heading", { name: "My Snippets" })).toBeVisible()
})
})