|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Browser smoke tests. Structural and behavioral checks against a real |
| 5 | + * browser engine — catches regressions the HTTP-only verify script can't |
| 6 | + * see (hydration, client-mounted WebGL canvas, mobile layout overflow, |
| 7 | + * client-side syntax-highlighting). |
| 8 | + * |
| 9 | + * Not pixel-diff. The 3D hero won't produce a stable WebGL output across |
| 10 | + * Linux/macOS GPU stacks, so screenshots are out of scope. Promote to |
| 11 | + * snapshot diffs only if a regression slips through. |
| 12 | + * |
| 13 | + * The post-dependent specs discover a published slug at runtime by parsing |
| 14 | + * `/blog`'s anchor list. Skips when no published posts are found, so the |
| 15 | + * suite stays useful on a hypothetical empty-content branch. |
| 16 | + */ |
| 17 | + |
| 18 | +let seedPostSlug: string | null = null; |
| 19 | + |
| 20 | +test.beforeAll(async () => { |
| 21 | + const baseURL = process.env.BASE_URL ?? "http://localhost:3000"; |
| 22 | + try { |
| 23 | + const res = await fetch(`${baseURL}/blog`); |
| 24 | + if (!res.ok) return; |
| 25 | + const html = await res.text(); |
| 26 | + const match = html.match(/href="\/blog\/([a-z0-9-]+)"/); |
| 27 | + seedPostSlug = match?.[1] ?? null; |
| 28 | + } catch { |
| 29 | + // leave seedPostSlug as null |
| 30 | + } |
| 31 | +}); |
| 32 | + |
| 33 | +test.describe("home", () => { |
| 34 | + test("hero copy is visible", async ({ page }) => { |
| 35 | + await page.goto("/"); |
| 36 | + await expect( |
| 37 | + page.getByText(/highly performant.*columnar data format/i) |
| 38 | + ).toBeVisible(); |
| 39 | + await expect(page.getByText(/100x faster random access/i)).toBeVisible(); |
| 40 | + }); |
| 41 | + |
| 42 | + test("title is correct", async ({ page }) => { |
| 43 | + await page.goto("/"); |
| 44 | + await expect(page).toHaveTitle(/Vortex/); |
| 45 | + }); |
| 46 | + |
| 47 | + test("WebGL hero canvas mounts after hydration", async ({ page }) => { |
| 48 | + await page.goto("/"); |
| 49 | + // OGL's Renderer constructor throws when WebGL context creation fails, |
| 50 | + // so the canvas only gets appended if WebGL is actually available. |
| 51 | + // Headless WebKit doesn't always have WebGL — skip there and rely on |
| 52 | + // the hero-copy / title tests above to catch a generic page-load |
| 53 | + // regression. Chromium has SwiftShader fallback so this runs there. |
| 54 | + const hasWebGL = await page.evaluate(() => { |
| 55 | + try { |
| 56 | + return !!document.createElement("canvas").getContext("webgl"); |
| 57 | + } catch { |
| 58 | + return false; |
| 59 | + } |
| 60 | + }); |
| 61 | + test.skip(!hasWebGL, "browser doesn't support WebGL"); |
| 62 | + await expect(page.locator("canvas").first()).toBeAttached({ |
| 63 | + timeout: 5000 |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
| 67 | + |
| 68 | +test.describe("blog index", () => { |
| 69 | + test("links to a published post", async ({ page }) => { |
| 70 | + test.skip(!seedPostSlug, "no published posts"); |
| 71 | + await page.goto("/blog"); |
| 72 | + await expect( |
| 73 | + page.locator(`a[href="/blog/${seedPostSlug}"]`).first() |
| 74 | + ).toBeVisible(); |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
| 78 | +test.describe("blog post", () => { |
| 79 | + test("post heading renders", async ({ page }) => { |
| 80 | + test.skip(!seedPostSlug, "no published posts"); |
| 81 | + await page.goto(`/blog/${seedPostSlug}`); |
| 82 | + await expect(page.locator("h1").first()).toBeVisible(); |
| 83 | + }); |
| 84 | + |
| 85 | + test("rehype-pretty-code syntax highlighting is rendered", async ({ |
| 86 | + page |
| 87 | + }) => { |
| 88 | + test.skip(!seedPostSlug, "no published posts"); |
| 89 | + await page.goto(`/blog/${seedPostSlug}`); |
| 90 | + // `figure[data-rehype-pretty-code-figure]` + `[data-line]` children are |
| 91 | + // emitted only when the rehype plugin successfully tokenized the code |
| 92 | + // block. A fallback `<pre>` path (e.g. plugin disabled or theme load |
| 93 | + // failure) wouldn't have either attribute. |
| 94 | + const figure = page |
| 95 | + .locator("figure[data-rehype-pretty-code-figure]") |
| 96 | + .first(); |
| 97 | + await expect(figure).toBeVisible(); |
| 98 | + expect(await figure.locator("[data-line]").count()).toBeGreaterThan(0); |
| 99 | + }); |
| 100 | +}); |
| 101 | + |
| 102 | +test.describe("mobile layout", () => { |
| 103 | + test.use({ viewport: { width: 375, height: 812 } }); |
| 104 | + |
| 105 | + test("home has no horizontal scroll", async ({ page }) => { |
| 106 | + await page.goto("/"); |
| 107 | + const { scrollWidth, clientWidth } = await page.evaluate(() => ({ |
| 108 | + scrollWidth: document.documentElement.scrollWidth, |
| 109 | + clientWidth: document.documentElement.clientWidth |
| 110 | + })); |
| 111 | + expect(scrollWidth).toBeLessThanOrEqual(clientWidth); |
| 112 | + }); |
| 113 | + |
| 114 | + test("blog post page has no horizontal scroll", async ({ page }) => { |
| 115 | + test.skip(!seedPostSlug, "no published posts"); |
| 116 | + await page.goto(`/blog/${seedPostSlug}`); |
| 117 | + const { scrollWidth, clientWidth } = await page.evaluate(() => ({ |
| 118 | + scrollWidth: document.documentElement.scrollWidth, |
| 119 | + clientWidth: document.documentElement.clientWidth |
| 120 | + })); |
| 121 | + expect(scrollWidth).toBeLessThanOrEqual(clientWidth); |
| 122 | + }); |
| 123 | +}); |
0 commit comments