Testing philosophy
Our testing strategy prioritizes:- Core editor functionality - Timeline, playback, commands, actions
- Data integrity - Storage migrations, project serialization
- Critical paths - Export, import, save/load
- Regression prevention - Tests for previously fixed bugs
Test framework
OpenCut uses Bun’s built-in test runner, which provides:- Fast execution
- TypeScript support out of the box
- Jest-compatible API
- Built-in mocking and assertions
Running tests
From the project root:Test structure
Tests are located alongside the code they test in__tests__ directories:
Writing tests
Basic test structure
Example: Testing a utility function
Example: Testing data migrations
Storage migrations are critical and should be thoroughly tested:Testing EditorCore and managers
Resetting the singleton between tests
Testing manager functionality
Testing commands (undo/redo)
Commands are critical for the undo/redo system:Testing React components
Component testing is not yet standardized in OpenCut. We focus primarily on testing logic, utilities, and core functionality.
Mocking
Mocking modules
Mocking EditorCore
Test coverage
While we don’t require 100% coverage, aim to test:- All public APIs of core modules
- All commands (execute, undo, redo)
- All data migrations
- Critical utilities (ID generation, validation, parsing)
- Edge cases and error conditions
When to write tests
Write tests when:- Adding new commands - Always test execute/undo/redo
- Adding data migrations - Critical for data integrity
- Fixing bugs - Prevent regressions
- Adding critical utilities - Parsing, validation, calculations
- Changing core functionality - Timeline, playback, export
- Simple UI components
- One-off scripts
- Experimental features
- Prototype code
Continuous integration
Tests run automatically on:- Every pull request
- Every push to main branch
- Before deployment
Best practices
Write descriptive test names
Write descriptive test names
Test names should clearly describe what is being tested:
Test one thing per test
Test one thing per test
Each test should verify a single behavior:
Use arrange-act-assert pattern
Use arrange-act-assert pattern
Structure tests with clear sections:
Clean up after tests
Clean up after tests
Reset state between tests:
Test error conditions
Test error conditions
Don’t just test the happy path:
Debugging tests
Add console logs
Run single test
Use Bun’s debugger
Contributing tests
When contributing:- Add tests for new functionality
- Update tests when changing behavior
- Add regression tests when fixing bugs
- Ensure all tests pass before submitting PR
Contributing Guide
Learn more about the contribution workflow
Next steps
Setup
Set up your development environment
Architecture
Learn about the system architecture