Vitest Debugging Methods
Sonamu uses Vitest as its test framework. It provides various debugging methods.Using VSCode Debugger
1. launch.json Configuration
.vscode/launch.json:
2. Running the Debugger
-
Open test file
- Open the
.test.tsfile you want to debug
- Open the
-
Set breakpoints
- Click to the left of the line number to show a red dot
-
Start debugger
- Press F5 or select “Debug Current Test File” from the “Run and Debug” panel
-
Debug
- When paused at a breakpoint, inspect variables
- Use F10 (Step Over), F11 (Step Into), etc.
Console Logging
Using console.log
The simplest debugging method:Structured Logging
Running Specific Tests
test.only
describe.only
Running Specific Tests via CLI
Watch Mode
Auto Re-run
Watch Mode Shortcuts
During test execution:a: Re-run all testsf: Re-run failed tests onlyt: Filter specific testsq: Quit
UI Mode (vitest —ui)
Running
http://localhost:51204/__vitest__/ in the browser
Features:
- Visualize test hierarchy
- Filter failed tests
- Re-run individual tests
- Check code coverage
- View console output
Error Debugging
Detailed Error Messages
Checking Errors with try-catch
Debugging Async Code
Checking async/await
Increasing Timeout
Debugging Mocks
Checking Mock Calls
Checking Mock Reset
Checking Database State
Query Logging
Checking Data After Test
Coverage Debugging
Checking Coverage
Finding Uncovered Code
Vitest Configuration Debugging
Checking Configuration
vitest.config.ts: