From 6c30cda7ccf9a889386f0f9e315a7f7a5718e43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dias?= Date: Fri, 18 Sep 2026 13:12:11 +0100 Subject: [PATCH 1/7] test: set up Playwright accessibility tests --- .gitignore | 7 ++- package-lock.json | 76 ++++++++++++++++++++++++++++++-- package.json | 4 ++ playwright.config.ts | 17 +++++++ src/components/assets/Logo.astro | 1 + tests/e2e/home.spec.ts | 29 ++++++++++++ tests/utils/accessibility.ts | 40 +++++++++++++++++ tests/utils/index.ts | 5 +++ 8 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 playwright.config.ts create mode 100644 tests/e2e/home.spec.ts create mode 100644 tests/utils/accessibility.ts create mode 100644 tests/utils/index.ts diff --git a/.gitignore b/.gitignore index 77637394..83ca958e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ dist/ # generated types .astro/ +# Playwright output +test-results/ +playwright-report/ +blob-report/ + # dependencies node_modules/ @@ -24,4 +29,4 @@ pnpm-debug.log* .idea/ # Local planning / scratch (not for commit) -.local/ \ No newline at end of file +.local/ diff --git a/package-lock.json b/package-lock.json index 21965bac..20034ac9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,8 @@ }, "devDependencies": { "@astrojs/check": "^0.9.10", + "@axe-core/playwright": "^4.13.0", + "@playwright/test": "^1.52.0", "@tailwindcss/vite": "^4.3.3", "@types/fs-extra": "^11.0.4", "@types/node": "^26.1.2", @@ -447,6 +449,19 @@ "yaml": "^2.8.3" } }, + "node_modules/@axe-core/playwright": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@axe-core/playwright/-/playwright-4.13.0.tgz", + "integrity": "sha512-6YLx+kxXu5GJceG4ozFg+33a2EMTdjYwWGloJ3sb9Kta5pp+ZNS53uxGVog5JetIY8s++P5UrtX+cri+u0VAVg==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "axe-core": "~4.13.0" + }, + "peerDependencies": { + "playwright-core": ">= 1.0.0" + } + }, "node_modules/@babel/helper-string-parser": { "version": "7.27.1", "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz", @@ -1834,6 +1849,22 @@ "url": "https://github.com/sponsors/Boshen" } }, + "node_modules/@playwright/test": { + "version": "1.63.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.63.0.tgz", + "integrity": "sha512-oxMK4vllB9RK5NQ2l1pq1IfOf2AvnEuj/vYGDj0H2nMtmtZpKtCwt/l00GEO6xjGfpBNAvjovvYdCm50dRQkpQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.63.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/@rolldown/binding-android-arm64": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.1.5.tgz", @@ -3406,6 +3437,16 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/axe-core": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.13.0.tgz", + "integrity": "sha512-UzGt8zg7Ny8djbYMhxl2zuEevVa7r2gJjYY5Lwr1xM7+XU2nd6CkIWFTVcCIbAP63vSz71NaVyyuSk9lHKcy0A==", + "dev": true, + "license": "MPL-2.0", + "engines": { + "node": ">=4" + } + }, "node_modules/axobject-query": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz", @@ -7429,6 +7470,35 @@ "pathe": "^2.0.1" } }, + "node_modules/playwright": { + "version": "1.63.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.63.0.tgz", + "integrity": "sha512-+7ziBLidS4NaNCdt57SUDT+wYmmd5fmiQejUic/kb+YsYSCPyOOE9sebzMjNmQrsnNpDJqd4WHvV/8lfKfUDUg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.63.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.63.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.63.0.tgz", + "integrity": "sha512-rYCsBF/M5HjUch52bbtVONEFjv6Xu8sm8h72dNlR5bzIE1fvC/bxgspzkjSfU+MweEMmPM8KJebG6nnyxo5mCg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/postcss": { "version": "8.5.22", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.22.tgz", @@ -10462,7 +10532,7 @@ }, "packages/cli": { "name": "bearnie", - "version": "0.2.0", + "version": "0.3.2", "license": "MIT", "dependencies": { "chalk": "^6.0.0", @@ -10535,7 +10605,7 @@ "license": "MIT" }, "packages/create-bearnie": { - "version": "0.5.0", + "version": "0.6.2", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", @@ -10575,7 +10645,7 @@ }, "packages/mcp": { "name": "@bearnie/mcp", - "version": "0.2.0", + "version": "0.3.2", "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "^1.0.0", diff --git a/package.json b/package.json index c962723c..de7da804 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "build:all": "npm run build:packages && npm run build", "release": "npx tsx scripts/release.ts", "test:smoke": "npm run build:packages && npx tsx scripts/smoke-test.ts", + "test:e2e": "playwright test", + "test:e2e:ui": "playwright test --ui", "cli:dev": "npm run dev -w bearnie", "cli:build": "npm run build -w bearnie", "cli:link": "npm link -w bearnie", @@ -44,6 +46,8 @@ }, "devDependencies": { "@astrojs/check": "^0.9.10", + "@axe-core/playwright": "^4.13.0", + "@playwright/test": "^1.52.0", "@tailwindcss/vite": "^4.3.3", "@types/fs-extra": "^11.0.4", "@types/node": "^26.1.2", diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 00000000..6b578073 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,17 @@ +import { defineConfig } from "@playwright/test"; + +export default defineConfig({ + testDir: "./tests/e2e", + fullyParallel: true, + forbidOnly: !!process.env.CI, + reporter: "list", + use: { + baseURL: "http://127.0.0.1:4321", + trace: "on-first-retry", + }, + webServer: { + command: "npm run dev -- --host 127.0.0.1 --port 4321", + url: "http://127.0.0.1:4321", + reuseExistingServer: !process.env.CI, + }, +}); diff --git a/src/components/assets/Logo.astro b/src/components/assets/Logo.astro index 63bcae59..f7a79999 100644 --- a/src/components/assets/Logo.astro +++ b/src/components/assets/Logo.astro @@ -8,6 +8,7 @@ const { class: className = "", ...rest } = Astro.props; viewBox="0 0 649 649" fill="none" xmlns="http://www.w3.org/2000/svg" + data-testid="logo" > { + test.beforeEach(async ({ page }) => { + await page.goto("/"); + await expect(page).toHaveTitle(/Bearnie/i); + }); + + test("content loads successfully", async ({ page }) => { + await expect(page.getByTestId("logo")).toBeVisible(); + await expect(page.getByRole("heading", { name: "Astro components, installed as source", level: 1 })).toBeVisible(); + await expect(page.getByRole("link", { name: "Get Started" })).toBeVisible(); + await expect(page.getByRole("link", { name: "Browse Components" })).toBeVisible(); + await expect(page.getByRole("button", { name: new RegExp("Copy npx bearnie init to clipboard", "i") })).toBeVisible(); + await expect(page.locator("body")).toBeVisible(); + }); + + for (const colorScheme of ["light", "dark"] as const) { + test.describe(`${colorScheme} theme`, () => { + test.use({ colorScheme }); + + test("has no automatically detectable accessibility violations", async ({ accessibility }) => { + const accessibilityReport = await accessibility.analyze(); + + expect(accessibilityReport.violations).toHaveLength(0); + }); + }); + } +}); diff --git a/tests/utils/accessibility.ts b/tests/utils/accessibility.ts new file mode 100644 index 00000000..77ae541a --- /dev/null +++ b/tests/utils/accessibility.ts @@ -0,0 +1,40 @@ +import AxeBuilder from "@axe-core/playwright"; +import type { SerialFrameSelector } from "axe-core"; +import { test as base, expect } from "@playwright/test"; +import type { Page } from "@playwright/test"; + +type AxeRule = string; + +export class Accessibility { + constructor(private readonly page: Page) {} + + private get axe() { + return new AxeBuilder({ page: this.page }); + } + + analyze() { + return this.axe.analyze(); + } + + analyzeSelector(selector: SerialFrameSelector) { + return this.axe.include(selector).analyze(); + } + + analyzeWithout(selector: SerialFrameSelector) { + return this.axe.exclude(selector).analyze(); + } + + analyzeRules(rules: AxeRule | AxeRule[]) { + return this.axe.withRules(rules).analyze(); + } +} + +type AccessibilityFixtures = { accessibility: Accessibility }; + +export const test = base.extend({ + accessibility: async ({ page }, use) => { + await use(new Accessibility(page)); + }, +}); + +export { expect }; diff --git a/tests/utils/index.ts b/tests/utils/index.ts new file mode 100644 index 00000000..58521ab1 --- /dev/null +++ b/tests/utils/index.ts @@ -0,0 +1,5 @@ +import { mergeTests } from "@playwright/test"; +import { test as accessibilityTest } from "./accessibility"; + +export const test = mergeTests(accessibilityTest); +export { expect } from "@playwright/test"; From 327fb301e0e0b056e950a29b764366a99b91bdf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dias?= Date: Mon, 21 Sep 2026 10:04:02 +0100 Subject: [PATCH 2/7] fix: add unique IDs to ComponentPreview instances in accordion documentation --- src/components/docs/ComponentPreview.astro | 250 ++++++++++----------- src/content/components/accordion.mdx | 14 +- 2 files changed, 125 insertions(+), 139 deletions(-) diff --git a/src/components/docs/ComponentPreview.astro b/src/components/docs/ComponentPreview.astro index 76283e17..f63c2a9e 100644 --- a/src/components/docs/ComponentPreview.astro +++ b/src/components/docs/ComponentPreview.astro @@ -17,16 +17,13 @@ export interface Props { component?: string; // Full width preview without padding/max-width (for sidebars, etc.) fullWidth?: boolean; + // Additional custom classes for the component preview container class?: string; + // Unique ID for the component preview container + id?: string; } -const { - code, - displayCode, - component, - fullWidth = false, - class: className, -} = Astro.props; +const { code, displayCode, component, fullWidth = false, class: className, id } = Astro.props; // Determine mode based on props const isInstallMode = !!component; @@ -53,7 +50,7 @@ if (Astro.slots.has("code")) { } // Generate a unique ID for this preview -const id = `preview-${Math.random().toString(36).substring(2, 9)}`; +const uniqueId = `preview-${id ?? Math.random().toString(36).substring(2, 9)}`; // Package manager commands const packageManagers = component @@ -82,9 +79,7 @@ function normalizeCode(value: string) { .filter((line) => line.trim().length > 0) .map((line) => line.match(/^\s+/)?.[0].length ?? 0); const minIndent = indents.length ? Math.min(...indents) : 0; - return lines - .map((line) => line.slice(minIndent).replace(/\s+$/g, "")) - .join("\n"); + return lines.map((line) => line.slice(minIndent).replace(/\s+$/g, "")).join("\n"); } // Priority: displayCode > codeFromSlot > code prop @@ -99,7 +94,7 @@ const normalizedCode = displayCode
{ @@ -196,14 +191,14 @@ const normalizedCode = displayCode
@@ -232,144 +227,135 @@ const normalizedCode = displayCode