@@ -26,7 +26,16 @@ npm run dev:psychic
2626# Development with live reload (psychic2 engine)
2727npm run dev:psychic2
2828
29- # Run comprehensive tests (requires PlatformIO)
29+ # Run TypeScript unit tests
30+ npm run test
31+
32+ # Run tests in watch mode
33+ npm run test:watch
34+
35+ # Generate test coverage report
36+ npm run test:coverage
37+
38+ # Run comprehensive ESP32 tests (requires PlatformIO)
3039npm run test:all
3140```
3241
@@ -119,6 +128,53 @@ npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./output.h --etag=true
119128- ** Prettier** : 120 character line width, single quotes, no trailing commas
120129- ** Import Sorting** : Automatic import organization with ` simple-import-sort `
121130
131+ ### Testing
132+
133+ The project uses ** Vitest** for unit testing with comprehensive coverage:
134+
135+ ** Test Structure:**
136+
137+ ```
138+ test/
139+ ├── unit/
140+ │ ├── commandLine.test.ts # CLI argument parsing tests
141+ │ ├── file.test.ts # File operations tests
142+ │ ├── cppCode.test.ts # C++ code generation tests
143+ │ └── consoleColor.test.ts # Console utilities tests
144+ └── fixtures/
145+ └── sample-files/ # Test fixture files
146+ ```
147+
148+ ** Test Coverage (68.25% overall):**
149+
150+ - ` commandLine.ts ` : 84.56% - CLI argument parsing, validation, engine/tri-state validation
151+ - ` file.ts ` : 100% - File collection, duplicate detection (SHA256), pre-compressed file skipping
152+ - ` cppCode.ts ` : 96.62% - Template rendering for all 4 engines, etag/gzip combinations, Handlebars helpers
153+ - ` cppCodeEspIdf.ts ` : 100% - ESP-IDF template (tested via ` cppCode.ts ` )
154+ - ` consoleColor.ts ` : 100% - ANSI color code wrapping
155+ - ` index.ts ` : 0% - Main entry point (has side effects, tested via integration)
156+
157+ ** Key Testing Features:**
158+
159+ - ** Vitest Configuration** : ` vitest.config.ts ` with TypeScript support, 60% coverage thresholds
160+ - ** Mocking Strategy** : Uses ` vi.mock() ` for file system (` node:fs ` ), glob (` tinyglobby ` ), and module dependencies
161+ - ** Dynamic Imports** : Tests use dynamic imports for ` commandLine.ts ` to test different CLI arguments without side effects
162+ - ** Test Fixtures** : Small sample files (HTML/CSS/JS) for testing file processing pipeline
163+ - ** Coverage Reports** : Generated in ` coverage/ ` directory (ignored by git), viewable HTML reports at ` coverage/index.html `
164+
165+ ** Testing Approach:**
166+
167+ - ** commandLine.test.ts** : Tests argument parsing (` --flag=value ` , ` -f value ` , ` --flag value ` ), validation errors, required arguments, directory validation. Uses dynamic imports to avoid module side effects.
168+ - ** file.test.ts** : Mocks file system with ` memfs ` , tests duplicate detection, compressed file skipping, path handling
169+ - ** cppCode.test.ts** : Tests template selection by engine, code generation for all etag/gzip combinations, byte array conversion, ETag/cache headers, default route detection
170+ - ** consoleColor.test.ts** : Simple tests for ANSI escape code wrapping (quick coverage wins)
171+
172+ ** Running Tests:**
173+
174+ - ` npm run test ` - Run all tests once (CI/CD)
175+ - ` npm run test:watch ` - Watch mode for development
176+ - ` npm run test:coverage ` - Generate coverage reports
177+
122178### Demo Projects
123179
124180- ** ` demo/svelte/ ` ** : Example Svelte application with Vite, TailwindCSS, gallery images
0 commit comments