Skip to content

test(e2e): Playwright suite for chat, mobile, and embed bundle#35

Open
PAMulligan wants to merge 1 commit into
mainfrom
15-e2e-tests-playwright
Open

test(e2e): Playwright suite for chat, mobile, and embed bundle#35
PAMulligan wants to merge 1 commit into
mainfrom
15-e2e-tests-playwright

Conversation

@PAMulligan
Copy link
Copy Markdown
Contributor

Closes #15

Summary

  • Add Playwright with widget/playwright.config.ts: Vite dev server via webServer, two projects (chromium-desktop, chromium-mobile), and a globalSetup that builds the IIFE embed bundle once before tests run.
  • e2e/chat.spec.ts — desktop: toggle open/close, send + receive (mocked), Escape closes + restores focus, focus trap, Retry-on-failure recovery.
  • e2e/mobile.spec.ts — mobile (iPhone 13 viewport): bottom-sheet layout + scrim + drag handle, scrim tap closes, send/receive.
  • e2e/embed.spec.ts — production IIFE coverage: auto-init from window.ClaudiusConfig and the <claudius-chat> web component. Bundle injected via page.addScriptTag({ path: dist/claudius-embed.iife.js }).
  • e2e/helpers.tsmockChatApi(page) routes **/api/chat with CORS headers + OPTIONS preflight so the cross-origin fetch from :5173:8787 works without spinning up the worker.

Bug fix surfaced by the embed test

vite.config.embed.ts was shipping process.env.NODE_ENV references to the browser, which throws ReferenceError: process is not defined when the IIFE is loaded via <script src>. Fixed via define so the IIFE is now actually usable in production embed scenarios — not just tests.

Scripts

pnpm e2e            # run the suite headless
pnpm e2e:ui         # Playwright UI mode
pnpm e2e:install    # one-time: download Chromium

Test plan

  • pnpm e2e — 10/10 pass (chat: 5, mobile: 3, embed: 2)
  • pnpm test — 184/184 unit + integration still green
  • pnpm exec tsc --noEmit clean
  • Manual: confirm pnpm e2e:ui opens the Playwright UI

🤖 Generated with Claude Code

- 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
  <claudius-chat> 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) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying chat-widget with  Cloudflare Pages  Cloudflare Pages

Latest commit: 55dca6d
Status: ✅  Deploy successful!
Preview URL: https://56ddd341.chat-widget-ejc.pages.dev
Branch Preview URL: https://15-e2e-tests-playwright.chat-widget-ejc.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E2E tests with Playwright for full chat flow

1 participant