This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
twd-cli is a CLI tool for running TWD (Test While Developing) browser-based tests using Puppeteer in CI/CD environments. It's an npm package that launches a headless browser, navigates to a dev server, and executes tests registered via the twd-js framework.
npm test— Run tests in watch mode (vitest)npm run test:ci— Run tests once with V8 coveragenpm run execute:cli— Run the CLI locally (node ./bin/twd-cli.js)npx twd-cli run— Run TWD tests (the user-facing command)
The codebase is a small ESM-only Node.js CLI with two core source files:
bin/twd-cli.js — CLI entry point. Parses process.argv for the run command, calls runTests(), and exits with code 0 (pass) or 1 (failure).
src/config.js — loadConfig() reads twd.config.json from process.cwd(), merges it with defaults (url, timeout, coverage, headless, puppeteerArgs), and returns the merged config. Falls back to defaults if the file is missing or unparseable.
src/index.js — runTests() is the main orchestrator:
- Loads config via
loadConfig() - Launches Puppeteer with configured headless mode and args
- Navigates to the configured URL (default:
http://localhost:5173) - Waits for
#twd-sidebar-rootselector (indicates app + TWD are ready) - Calls
window.__testRunnerin the browser context to execute all tests - Reports results via
reportResults()fromtwd-js/runner-ci - Optionally collects
window.__coverage__and writes to.nyc_output/out.json - Returns boolean
hasFailures
test-example-app/ — A React demo app with TWD tests integrated, used for manual testing/demonstration. Not part of the published package or test suite.
Tests are in tests/ and use vitest. The test suite mocks fs to test config loading and mocks Puppeteer to test the run flow. Coverage is configured for src/**/*.js only.
- puppeteer — Browser automation (launches Chrome/Chromium)
- twd-js — The TWD testing framework; provides
reportResultsfromtwd-js/runner-ciand the in-browser__testRunner