Files
karaoke-gen/frontend
Andrew Beveridge ☄️andClaude Opus 5.5 19f3c731fb test(e2e): sanitized page-activity log on tenant E2E failure (#1229)
## Summary
Tenant E2E #155 (singa, 2026-10-28) failed with the portal stuck on the
`/en/app/` loading spinner for 30s. The backend served tenant config in
168ms, 8 live re-runs were fine, and run #156 got past the same step.
The only evidence was a screenshot: CI has no Playwright traces, because
traces hold `X-Admin-Token` and the repo's artifacts are public.

This adds a public-safe stand-in,
`frontend/e2e/helpers/page-activity.ts`. It records:
- main-frame navigations;
- each request's method and origin/path (no query strings), with status
and duration or the failure reason;
- console errors/warnings and uncaught page errors, with URLs and
token-like values in their text redacted.

On failure it writes `page-activity.log` into test-results (the scrubber
still checks it) and prints the requests still in flight to the job log.
It is wired into `tenant-happy-path.spec.ts`. The approach is documented
in docs/TESTING.md, which also records #155 as a one-off flake.

## Testing
- New offline spec `e2e/self-healing/page-activity.spec.ts` (3 tests): a
fixture page with one hung, one failed and one token-bearing request,
plus console and page errors. The self-heal suite runs in CI's
frontend-e2e-smoke job. The whole suite passes locally (36 tests).
- `playwright test --list` on the production config compiles the tenant
spec.
- Local CodeRabbit review: 2 findings (redact console text; race on the
REQFAIL assertion), both fixed.
- Test-only change, so no version bump.

Alert:
https://discord.com/channels/1198691101943541770/1265517528608669707/1564876714532798465

@coderabbitai ignore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_012RYLVTiUPKxn3sQPyp3Teh

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 02:22:52 -04:00
..

Karaoke Generator Frontend

Next.js frontend for the Karaoke Generator application.

Quick Start

# Install dependencies
npm install

# Run development server
npm run dev

The app will be available at http://localhost:3000

Development Setup

Connecting to the Cloud Backend

In development, the frontend proxies API requests to the cloud backend (api.nomadkaraoke.com) via Next.js rewrites. This avoids CORS issues and allows local development without running a local backend.

The proxy is configured in next.config.mjs:

  • All /api/* requests are forwarded to the cloud backend
  • You can override the backend URL with BACKEND_URL environment variable

Authentication

The backend requires authentication. To authenticate:

  1. Create a .env.local file in the frontend directory:

    KARAOKE_ACCESS_TOKEN=your-token-here
    
  2. The token is automatically loaded by Playwright tests

  3. In the browser, the token is stored in localStorage as karaoke_access_token

Testing

Unit Tests (Jest)

# Run tests in watch mode
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in CI mode
npm run test:ci

E2E Tests (Playwright)

E2E tests run against the local dev server connected to the real cloud backend.

# Run all E2E tests
npm run test:e2e

# Run with UI (interactive mode)
npm run test:e2e:ui

# Run in headed mode (see the browser)
npm run test:e2e:headed

# Run in debug mode
npm run test:e2e:debug

Authentication for E2E Tests

E2E tests require a valid access token. Set it in .env.local:

KARAOKE_ACCESS_TOKEN=your-token-here

The Playwright config (playwright.config.ts) automatically loads this file.

Test Structure

Tests are located in e2e/:

  • karaoke-generation.spec.ts - Main test suite covering:
    • Homepage loading and form display
    • Search tab functionality
    • Audio search submission
    • Audio selection dialog flow
    • API health checks

Test Architecture

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────────┐
│   Playwright    │────▶│  Next.js Dev     │────▶│  Cloud Backend      │
│   Browser       │     │  Server (:3000)  │     │  api.nomadkaraoke   │
└─────────────────┘     └──────────────────┘     └─────────────────────┘
                              │
                              ▼
                        API Proxy
                        /api/* → backend

Debugging Test Failures

  1. Screenshots: Failed tests save screenshots to test-results/
  2. Videos: First retry captures video (when retries enabled)
  3. Traces: View detailed traces with npx playwright show-trace <trace.zip>
  4. HTML Report: After running tests, view npx playwright show-report

Common Issues

  • 401 Unauthorized: Token missing or invalid - check .env.local
  • Socket hang up: Backend operation taking too long - some operations (like audio download) can take minutes
  • Element outside viewport: Dialog scrolling issues - tests use JavaScript click to handle this

Project Structure

frontend/
├── app/                    # Next.js app router pages
├── components/             # React components
│   ├── ui/                 # shadcn/ui components
│   └── audio-search/       # Audio search feature components
├── lib/                    # Utilities and API client
│   └── api.ts              # Backend API client
├── e2e/                    # Playwright E2E tests
├── playwright.config.ts    # Playwright configuration
└── next.config.mjs         # Next.js configuration

Scripts

Script Description
npm run dev Start development server
npm run build Build for production
npm run start Start production server
npm run lint Run ESLint
npm test Run unit tests (watch mode)
npm run test:ci Run unit tests (CI mode with coverage)
npm run test:e2e Run E2E tests
npm run test:e2e:ui Run E2E tests with interactive UI