How jardevson/playwrightcleancli works
Project type and purpose
• This is an open‑source CLI tool for API testing, built in TypeScript on top of Playwright.
• It provides a clean command‑line interface that invokes Playwright-based tests (in tests/ and tests‑examples/) against a target API (e.g., ServeRest), parameterized by environment.
File structure
• Top level:
• package.json / package-lock.json – defines dependencies (playwright, ts‑node, cross‑env) and CLI scripts (test.api).
• playwright.config.ts – Playwright configuration (timeouts, reporters, baseURL).
• tests/ – actual test suites (api.spec.ts) plus a runner (runTests.ts).
• tests‑examples/ – sample/demo tests (demo-todo-app.spec.ts).
• .github/workflows/playwright.yml – CI pipeline invoking the CLI.
Insights from the README
• Describes rationale for a CLI-driven API testing approach (speed, automation, customization).
• Shows how the runTests.ts script dynamically builds a Playwright CLI command with cross‑env for environment‑agnostic API_URL injection.
• Demonstrates a suite of CRUD tests against /login, /usuarios endpoints.
Main components
a. CLI Layer
• runTests.ts script (invoked via ts-node)
• Accepts parameters: environment (dev/uat/sit), optional specific suite (e.g., api.spec.ts)
• Uses cross‑env to set API_URL
b. Test Runner Layer
• Playwright Test Runner (playwright test)
• Configuration (playwright.config.ts)
• Test Suites (tests/api.spec.ts, tests-examples/demo‑todo‑app.spec.ts)
c. External System Under Test
• REST API endpoint at ${API_URL} (ServeRest or any target)
d. CI/CD Pipeline
• GitHub Actions workflow (.github/workflows/playwright.yml)
• Triggers the same CLI commands on push/PR
Relationships and data flows
1) Developer or CI invokes “npm run test.api <env> [suite]”
2) runTests.ts constructs: cross-env API_URL=<envUrl> npx playwright test tests/<suite>
3) Playwright runner loads config & test files
4) Each test case issues HTTP requests to ${API_URL}/…
5) Assertions validate status codes & response bodies
6) Results flow back to runner, reporter outputs pass/fail
7) CI reads test outcome and fails/builds accordingly
Architectural patterns & design principles
• Thin CLI orchestrator (separation of concerns: command parsing vs. test logic)
• Modular test suites (can add/remove .spec.ts files without changing runner)
• Environment abstraction via cross‑env (platform‑agnostic)
• CI integration (GitHub Actions uses the same CLI entrypoint)
• Extensibility: developers can drop new tests in tests/ or tests‑examples/
• Labels: “runTests.ts (CLI)”, “cross-env”, “npx playwright test”, “playwright.config.ts”, “tests/api.spec.ts”, “tests-examples/demo-todo-app.spec.ts”, “ServeRest API (API_URL)”, “GitHub Actions”
• CLI → cross-env → Playwright Runner
• Playwright Runner → playwright.config.ts (load)
• Playwright Runner → Test Suites (load & execute)
• Test Suites → External API (HTTP requests)
• External API → Test Suites (responses)
• Runner → Console/Reporter → CI server