Prompt-Optimizer Testing Strategy: How to Run Unit and E2E Tests
The prompt-optimizer repository uses a layered testing strategy that combines Vitest for fast unit and integration tests with Playwright for end-to-end browser validation, all orchestrated through pnpm scripts.
The linshenkx/prompt-optimizer project implements a comprehensive testing strategy designed to balance rapid developer feedback with production-grade quality assurance. By leveraging Vitest for TypeScript validation and Playwright for full-stack UI flows, this monorepo ensures reliability across its core library, web interface, and desktop applications. Understanding how to execute these tests is essential for contributors maintaining or extending the codebase.
Understanding the Layered Testing Strategy
The testing architecture in linshenkx/prompt-optimizer follows a three-tier approach that isolates fast feedback loops from comprehensive integration validation.
Unit and Integration Testing with Vitest
The foundation relies on Vitest, a Vite-native test runner, for all TypeScript source validation. Unit tests target isolated functions and utilities, while integration tests verify module interactions. These tests reside in packages/<pkg>/tests/unit/**/*.spec.ts and packages/<pkg>/tests/integration/**/*.spec.ts respectively.
End-to-End Testing with Playwright
For full-stack validation, the repository employs Playwright to automate browser interactions. This layer validates the web application and desktop/Electron wrapper through realistic user flows. E2E specifications are located in packages/<pkg>/tests/e2e/**/*.spec.ts.
Orchestration Layer
The root package.json uses npm-run-all to sequence these layers into a single deterministic command suitable for CI pipelines.
How to Run Tests in Prompt-Optimizer
The repository provides granular pnpm scripts for different testing scenarios, from rapid development feedback to comprehensive CI validation.
Run the Complete Test Suite
To execute the full testing strategy as configured in continuous integration:
pnpm test
This command orchestrates both layers sequentially via the root package.json script definition:
"scripts": {
"test": "npm-run-all -s test:unit test:e2e:smart",
"test:unit": "pnpm -r test --run --passWithNoTests",
"test:e2e:smart": "node scripts/smart-e2e.js"
}
Run Unit Tests Only
For rapid development feedback without browser overhead:
pnpm test:unit
To target a specific package, such as the core library:
pnpm -F @prompt-optimizer/core test
Or run unit tests for a specific package with coverage reporting:
pnpm -F @prompt-optimizer/core test:coverage
Run End-to-End Tests
To validate full user flows through Playwright:
pnpm test:e2e
For faster execution during development, use the "smart" runner that skips tests with existing VCR recordings:
pnpm test:e2e:smart
This optimization is handled by scripts/smart-e2e.js, which analyzes VCR fixtures to determine which specifications require execution.
Watch Mode for Continuous Testing
To run tests continuously while coding:
pnpm test:unit -- --watch
Or for a specific package:
pnpm -F @prompt-optimizer/core test:watch
Test Configuration and Key Files
Understanding the configuration files helps customize the testing strategy for specific development needs.
Root Orchestration
The top-level package.json defines the entry points for all test commands. Located at the repository root, it sequences unit and E2E layers using npm-run-all.
Package-Level Vitest Configuration
Each package maintains its own test scripts. In packages/core/package.json, you will find granular commands:
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"test:gate": "vitest run tests/unit/utils/vcr.spec.ts tests/unit/utils/llm-mock-service.spec.ts",
"test:unit": "vitest run tests/unit",
"test:integration": "vitest run tests/integration"
}
Playwright Integration
The web interface package configures Vitest to include Playwright fixtures in packages/web/vitest.config.ts, enabling browser automation within the same test runner infrastructure.
Smart E2E Runner
The scripts/smart-e2e.js file implements the intelligent test selection logic that powers the test:e2e:smart command, analyzing VCR recordings to skip unnecessary browser executions.
Example Test Files
- Unit test example:
packages/core/tests/unit/utils/vcr.spec.tsdemonstrates Vitest specifications for utility functions. - E2E test example:
packages/ui/tests/e2e/conversation-optimization.spec.tsshows Playwright tests for conversation flows.
Summary
The linshenkx/prompt-optimizer repository implements a robust, layered testing strategy that balances speed and comprehensiveness:
- Vitest handles unit and integration testing for fast feedback during development, with tests located in
packages/<pkg>/tests/unit/andpackages/<pkg>/tests/integration/. - Playwright manages end-to-end browser testing for the web and desktop applications, with specs in
packages/<pkg>/tests/e2e/. - pnpm scripts orchestrate the entire suite through commands like
pnpm test,pnpm test:unit, andpnpm test:e2e:smart. - Smart optimization via
scripts/smart-e2e.jsreduces CI time by skipping E2E tests with existing VCR recordings.
Frequently Asked Questions
What testing frameworks does prompt-optimizer use?
The repository uses Vitest for unit and integration testing and Playwright for end-to-end browser automation. Vitest runs TypeScript tests across the monorepo packages, while Playwright validates full user flows in the web interface and Electron desktop wrapper.
How do I run tests for a single package?
Use the pnpm filter flag -F followed by the package name. For example, to run only the core package tests: pnpm -F @prompt-optimizer/core test. You can also run specific test types per package, such as pnpm -F @prompt-optimizer/core test:unit or pnpm -F @prompt-optimizer/core test:integration.
What is the difference between test:e2e and test:e2e:smart?
The pnpm test:e2e command runs the complete Playwright end-to-end test suite against live browser instances. In contrast, pnpm test:e2e:smart executes scripts/smart-e2e.js, which analyzes VCR recordings to skip tests that have already been recorded and validated, significantly reducing execution time during development and CI.
Where are the test files located in the repository?
Unit and integration tests reside in packages/<package-name>/tests/unit/**/*.spec.ts and packages/<package-name>/tests/integration/**/*.spec.ts respectively. End-to-end tests are located in packages/<package-name>/tests/e2e/**/*.spec.ts. For example, core utilities are tested in packages/core/tests/unit/utils/vcr.spec.ts, while UI flows are tested in packages/ui/tests/e2e/conversation-optimization.spec.ts.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →