Skip to main content

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.tsutils.test.ts
  • Use .test.ts or .test.tsx extension
  • 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
Run with:

Integration Tests

src-tauri/tests/space_lifecycle.rs

Test Coverage

Current Coverage

Run coverage report:
Output:

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

  • src/lib/diff.test.ts - Text diffing
  • src/lib/shortcuts.test.ts - Keyboard shortcuts
  • src/lib/notePreview.test.ts - Preview generation
  • src/lib/errorUtils.test.ts - Error handling
  • src/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