From 55dca6d91e7ac963628d571a36df59de9de87263 Mon Sep 17 00:00:00 2001 From: PAMulligan Date: Fri, 8 May 2026 01:05:09 -0400 Subject: [PATCH] test(e2e): Playwright suite for chat flow, mobile, and embed bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add @playwright/test with widget/playwright.config.ts (Vite dev server via webServer, chromium-desktop + chromium-mobile projects, build the IIFE bundle once in globalSetup). - e2e/chat.spec.ts: toggle open/close, send message + receive reply, Escape closes + restores focus, focus trap, Retry-after-failure flow. - e2e/mobile.spec.ts: bottom-sheet layout + scrim + drag handle, scrim tap closes, send/receive on mobile viewport. - e2e/embed.spec.ts: IIFE auto-init from window.ClaudiusConfig and the web-component path. Bundle is loaded via page.addScriptTag + addStyleTag from dist/. - e2e/helpers.ts: mockChatApi() routes **/api/chat with CORS headers and preflight handling so cross-origin fetch from :5173 → :8787 works. - Vitest exclude updated to skip e2e/. Bug fix surfaced by the embed test: vite.config.embed.ts was leaving `process.env.NODE_ENV` in the IIFE bundle, which throws in browsers ("process is not defined"). Replace it at build time via `define`. Closes #15 Co-Authored-By: Claude Opus 4.7 (1M context) --- README.md | 13 +++++ widget/e2e/chat.spec.ts | 91 +++++++++++++++++++++++++++++++++++ widget/e2e/embed.spec.ts | 94 +++++++++++++++++++++++++++++++++++++ widget/e2e/global-setup.ts | 32 +++++++++++++ widget/e2e/helpers.ts | 68 +++++++++++++++++++++++++++ widget/e2e/mobile.spec.ts | 48 +++++++++++++++++++ widget/package.json | 4 ++ widget/playwright.config.ts | 45 ++++++++++++++++++ widget/pnpm-lock.yaml | 38 +++++++++++++++ widget/vite.config.embed.ts | 6 +++ widget/vite.config.ts | 1 + 11 files changed, 440 insertions(+) create mode 100644 widget/e2e/chat.spec.ts create mode 100644 widget/e2e/embed.spec.ts create mode 100644 widget/e2e/global-setup.ts create mode 100644 widget/e2e/helpers.ts create mode 100644 widget/e2e/mobile.spec.ts create mode 100644 widget/playwright.config.ts diff --git a/README.md b/README.md index 9471520..73fa0f4 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,19 @@ Output: `dist/claudius.iife.js` and `dist/claudius.css` Host these files on your site or a CDN, then add the embed snippet to your HTML. +## Testing + +```bash +cd widget +pnpm test # Unit + integration (Vitest) +pnpm test:coverage # Coverage report (target: 80%+) +pnpm e2e:install # One-time: download Chromium for Playwright +pnpm e2e # End-to-end (Playwright, against `pnpm dev`) +pnpm e2e:ui # Playwright UI mode +``` + +The E2E suite mocks `**/api/chat` via `page.route()` so the worker doesn't need to be running, and builds the embed bundle once in `globalSetup` to exercise it via `