Prompt
## COMPREHENSIVE TEST AUTOMATION & GAP ANALYSIS
Analyze this project to create a complete, risk-prioritized test suite using Vitest. Identify all testing gaps, create a phased implementation plan, then generate the actual test files.
## PHASE 1: DISCOVERY & MAPPING
### 1.1 Feature Inventory
Catalog every feature, function, and behavior:
- Build scripts (npm run build:dev, npm run build, etc.)
- Internal utilities and helper functions
- API endpoints or data fetching
- User-facing interactions (forms, buttons, navigation)
- State management and data flows
- Third-party integrations and plugins
- Configuration and environment handling
### 1.2 Current Test Inventory
- Find all existing test files
- Map which features have coverage vs gaps
- Identify obsolete tests (testing removed features)
- Note test quality issues (brittle, slow, incomplete assertions)
## PHASE 2: RISK-BASED PRIORITIZATION
| Priority | Name | What to Test | Examples |
|----------|------|--------------|----------|
| **P1** | CRITICAL | Data integrity, security, core business logic, build pipeline | Payment processing, auth, build scripts |
| **P2** | HIGH | User-facing forms, API integrations, error handling | Form validation, API calls, navigation |
| **P3** | MEDIUM | UI components, edge cases, utilities | Rendering, performance code, helpers |
| **P4** | LOW | Presentational, simple getters, logging | Pure display components, analytics |
## PHASE 3: TEST ARCHITECTURE DESIGN
### 3.1 Test Categories
**Unit Tests** (fast, isolated, mocked dependencies)
- Individual functions
- Utility modules
- Data transformations
- Validation logic
**Integration Tests** (real interactions, minimal mocking)
- Module interactions
- Build pipeline stages
- File system operations
**E2E Tests** (real browser via Playwright, no mocking)
- Critical user journeys
- Form submissions
- Navigation flows
### 3.2 Mocking Strategy
**MOCK THESE** (for speed):
- Network requests (use msw or vi.mock)
- File system operations (where possible)
- Timers and dates (vi.useFakeTimers)
- External APIs and services
- Heavy computational functions
**DO NOT MOCK THESE** (need real behavior):
- Core business logic under test
- Build script actual execution (in integration tests)
- Final E2E user journeys
- Security-critical paths
### 3.3 Vitest Configuration
Create `vitest.config.js` with:
- Coverage thresholds (80 percent+ on P1/P2)
- Test file patterns
- Setup files for common mocks
- Environment configuration (jsdom for browser tests)
- Coverage reporters (text, html, lcov)
## PHASE 4: TEST IMPLEMENTATION PLAN
### Wave 1: Foundation (Do First)
1. Vitest configuration and setup files
2. Common test utilities and helpers
3. Mock factories for repeated mocking patterns
4. Build script tests (ensure build works)
### Wave 2: Critical Path (P1)
5. Core business logic unit tests
6. Authentication/security tests
7. Data integrity tests
8. Error boundary tests
### Wave 3: Integration (P2)
9. API integration tests
10. Module interaction tests
11. Form validation tests
12. State management tests
### Wave 4: User Facing (P2-P3)
13. Component rendering tests
14. User interaction tests
15. Accessibility tests
16. Playwright E2E for localhost:8080
### Wave 5: Polish (P3-P4)
17. Edge case coverage
18. Performance tests
19. Remaining utility function tests
20. Documentation of test patterns
## PHASE 5: EXECUTION
### Test File Header Standard
```javascript
/**
* @fileoverview Tests for [module/feature name]
* @priority P1|P2|P3|P4
* @covers [list of functions/features covered]
* @mocks [list of mocked dependencies]
*/
```
### Test File Structure
```
tests/
setup/
vitest.setup.js # Global setup
mocks/ # Shared mock factories
unit/
utils/ # Utility function tests
lib/ # Library/module tests
components/ # Component unit tests
integration/
build/ # Build pipeline tests
api/ # API integration tests
flows/ # Multi-module flow tests
e2e/
journeys/ # Critical user journeys (Playwright)
```
### Package.json Scripts
```json
{
"scripts": {
"test": "vitest",
"test:unit": "vitest run --dir tests/unit",
"test:integration": "vitest run --dir tests/integration",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest --watch",
"test:ui": "vitest --ui",
"test:e2e": "playwright test",
"test:ci": "vitest run --coverage --reporter=junit"
}
}
```
## OUTPUT REQUIREMENTS
### Deliverable 1: Gap Analysis Report
- Total functions/features identified
- Current coverage percentage
- Gap list with priority assignments
- Risk assessment for untested code
| Area | Functions | Covered | Gap | Priority |
|------|-----------|---------|-----|----------|
| Build Scripts | 5 | 1 | 4 | P1 |
| Utils | 12 | 3 | 9 | P2 |
### Deliverable 2: Implementation Plan
- Ordered list of test files to create
- Time estimates per test file (S/M/L)
- Dependencies between test files
- Suggested sprint/cycle breakdown
### Deliverable 3: Test Files
Actually create all test files following the plan:
- Start with Wave 1 (foundation)
- Progress through each wave
- Include meaningful assertions (not just "it renders")
- Add comments explaining complex test scenarios
- Use descriptive test names that explain the behavior
### Deliverable 4: Configuration Files
- `vitest.config.js` (complete configuration)
- `tests/setup/vitest.setup.js` (global mocks and setup)
- `tests/setup/mocks/*.js` (reusable mock factories)
- `playwright.config.js` (E2E configuration)
- Updated `package.json` with test scripts
## SUCCESS CRITERIA
- [ ] All P1 features have test coverage
- [ ] All P2 features have test coverage
- [ ] Coverage report shows 80 percent+ on critical paths
- [ ] Unit tests run in under 30 seconds
- [ ] Build pipeline has automated test gate
- [ ] No brittle tests dependent on timing or order
- [ ] E2E tests pass against localhost:8080