How arghajit47/playwright-lighthouse-performance-testing works
Project Type and Purpose
• This is an automated performance-testing framework built on Node.js, combining Playwright (browser automation) with Lighthouse (performance auditing).
• It supports two user flows—Authorized and Unauthorized—and runs tests in both desktop and mobile modes.
• In addition to test suites, the repo contains:
• A static “performance-report” viewer (HTML/JS/CSS) to render raw Lighthouse output.
• A “dashboard” mini-application (Node backend + HTML/JS/CSS frontend) to display consolidated results.
• A downloadImages.mjs helper to fetch Lighthouse report screenshots for the dashboard.
File Structure
• tests/Auth & tests/UnAuth
• Playwright test specs (TypeScript) driving login flows (Auth) or public pages (UnAuth).
• utils/
• Common helpers for running audits and parsing results.
• test-data/enum.ts
• Canonical URLs and constants for tests.
• lighthouse/base.ts
• Shared Lighthouse configuration.
• playwright.config.ts
• Playwright settings (browsers, timeouts).
• CI Workflow (.github/workflows/playwright.yml)
• Installs dependencies, runs tests, uploads artifacts.
• performance-report/
• Static viewer showing raw Lighthouse HTML reports.
• dashboard/
• backend/server.mjs: Node HTTP server or Express app serving an API to fetch test results/images.
• downloadImages.mjs
• Script that pulls screenshots from generated Lighthouse reports for inclusion in dashboard.
Main Components & Relationships
A. Test Runner Pipeline
1. CLI / npm Scripts
• npm run test:Auth | test:UnAuth | test triggers the test runner.
2. Playwright Test Suite (Auth & UnAuth specs)
• Uses @playwright/test + dotenv for credentials.
• Invokes playwright-lighthouse to run Lighthouse audits under different device emulations.
3. Lighthouse Audit Engine
• Runs performance audits; outputs JSON/HTML reports.
4. Results Storage
• Reports written to disk under workspace (e.g., performance-report/ or temp folders).
B. Report Generation & Viewing
1. performance-report/
• Static site loads raw Lighthouse HTML/JSON, presents charts and metrics.
2. downloadImages.mjs
• Parses Lighthouse JSON to extract screenshot assets.
3. dashboard Backend
• Serves an API that aggregates JSON metrics and images.
4. dashboard Frontend
• Fetches from backend, displays trend graphs and comparison across runs.
C. CI/CD Integration
• GitHub Actions uses playwright.yml to run tests on push/PR.
• Artifacts (reports) are uploaded for 30 days.
• Secrets (EMAIL/PASSWORD) are provided via GitHub secrets.
Architectural Patterns & Design Principles
• Modular Test Pipeline: Separation of Playwright specs, shared helpers, and configuration enables reuse.
• Data-Pipeline Style: Test → Audit → Report → Visualization.
• MVC-Like Dashboard: Node.js backend (Model/API), frontend UI (View), routing logic (Controller).
• CI as Orchestrator: External service triggering automated runs and storing artifacts.
• Components: CLI scripts, Playwright test suite, Lighthouse engine, JSON/HTML report files, downloadImages script, dashboard backend, dashboard frontend, performance-report viewer, GitHub Actions, target web application.
• Legends or annotations for environment variables, secrets, and configuration files.