Test Framework
Glyph uses Vitest for frontend testing:- Fast execution (powered by Vite)
- Jest-compatible API
- Native TypeScript support
- Watch mode with HMR
Rust backend tests use Rust’s built-in
cargo test framework.Running Tests
All Tests
Watch Mode
Single Test File
Single Test Case
Coverage Report
Frontend Test Structure
Test File Naming
- Place tests next to source:
utils.ts→utils.test.ts - Use
.test.tsor.test.tsxextension - Integration tests:
.integration.test.ts
Example Test
src/lib/diff.test.ts
Testing Patterns
Utility Functions
React Hooks
src/hooks/useFileTree.test.ts
TipTap Extensions
src/components/editor/extensions/wikiLink.integration.test.ts
Mocking Tauri Commands
src/lib/tauri.mock.ts
Usage in test
Rust Testing
Unit Tests
src-tauri/src/paths.rs
Integration Tests
src-tauri/tests/space_lifecycle.rs
Test Coverage
Current Coverage
Run coverage report:Coverage Goals
- Utilities: 90%+ coverage (pure functions)
- Hooks: 70%+ coverage (harder to test)
- Components: 50%+ coverage (UI-heavy)
- Integration: Key workflows covered
Test Organization
Tested Modules
- Utilities
- Editor
- Database
- File Tree
src/lib/diff.test.ts- Text diffingsrc/lib/shortcuts.test.ts- Keyboard shortcutssrc/lib/notePreview.test.ts- Preview generationsrc/lib/errorUtils.test.ts- Error handlingsrc/utils/path.test.ts- Path utilities
Writing New Tests
Step 1: Create Test File
Step 2: Import Vitest
Step 3: Group Tests
Step 4: Write Assertions
Continuous Integration
Tests run on every PR via GitHub Actions:.github/workflows/test.yml
Best Practices
1
Test behavior, not implementation
Focus on what the function does, not how it does it.
Good
Bad
2
One assertion per test (generally)
Each test should verify one thing.
Good
3
Use descriptive test names
Test name should explain what’s being tested.
Good
Bad
4
Test edge cases
Always test boundary conditions.
Next Steps
Architecture
Understand the codebase structure
Components
Learn about React components