This document provides comprehensive testing instructions for Tick Tack Timer.
To run all tests once and see the results:
yarn test:runTo run tests in watch mode (automatically re-runs when files change):
yarn testTo run tests with a visual interface:
yarn test:uiThen open your browser to the URL shown (usually http://localhost:51204/__vitest__/)
To generate a test coverage report:
yarn coveragetests/
├── unit/
│ └── audio/
│ ├── tick-detector.spec.ts # Unit tests for WASM tick detector (8 tests)
│ ├── tick-processor.worklet.spec.ts # Unit tests for AudioWorklet processor (20 tests)
│ └── AudioManager.spec.ts # Unit tests for AudioManager (46 tests)
└── property/
├── tick-detection.property.spec.ts # Property tests for tick detection (2 tests)
└── audio-manager.property.spec.ts # Property tests for audio forwarding (4 tests)
- ✅ 8 unit tests for RMS calculation, high-pass filtering, and tick detection
- ✅ 2 property-based tests (Properties 10 & 11) - 100 iterations each
- ✅ 20 unit tests covering:
- Initialization and configuration
- Message handling (setCalibration, setWasm)
- Audio processing pipeline
- Duplicate detection window (50ms)
- Error handling
- ✅ 46 unit tests covering:
- AudioContext initialization
- Microphone access and permissions
- AudioWorklet loading
- WASM module loading and compilation
- Calibration settings
- Audio graph connection (start/stop)
- Tick detection callbacks
- Worklet message handling
- Resource cleanup
- ✅ 4 property-based tests (Property 9) covering:
- Audio sample forwarding to WASM module (100 iterations)
- WASM module initialization before processing (50 iterations)
- Audio graph connection stability (50 iterations)
- Calibration propagation to worklet (50 iterations)
Total: 80 tests, all passing
- Syntax Error - Removed malformed comment
*** End Patch】}***/from test file - fast-check Constraints - Fixed float constraints to use
Math.fround()for 32-bit floats - Test Signal Issues - Updated tests to use high-frequency signals instead of DC signals:
- DC signals (constant values) are correctly filtered out by the high-pass filter
- Tests now use alternating signals (e.g.,
[0.5, -0.5, 0.5, -0.5, ...]) which pass through the filter
✅ All 10 tests passing:
- 8 unit tests for tick detector functions
- 2 property-based tests validating Requirements 4.1 and 4.2
- Test specific scenarios with known inputs and expected outputs
- Validate RMS calculation, high-pass filtering, and tick detection logic
- Test edge cases like zero samples, sensitivity bounds, etc.
- Run 100 iterations with randomly generated inputs
- Property 10: Validates that samples exceeding threshold are identified as ticks
- Property 11: Validates that samples below threshold are filtered out
- The high-pass filter (~500Hz cutoff) correctly removes DC (constant) signals
- Tests use alternating high-frequency signals to simulate actual tick sounds
- The WASM implementation in
assembly/tick-detector.tsmirrors the TypeScript reference insrc/audio/tick-detector-math.ts