Test Suite Overview
GitHub Desktop uses Node.js’s built-in test runner for unit tests. Tests are organized underapp/test/ with the following structure:
unit/- Unit tests for individual modules and functionsintegration/- End-to-end tests using UI automationfixtures/- Git repositories and test datahelpers/- Shared test utilities and setup code
Running Tests
Run All Tests
yarn test:unit).
Unit Tests
Run all unit tests:Specific Test Files
Run tests in a specific file:Specific Test Directory
Run all tests in a directory:Filter by Test Name
Run tests matching a specific pattern:For more test runner options, see the Node.js test runner documentation.
ESLint Tests
Run tests for custom ESLint rules:Script Tests
Run tests for build scripts:Writing Unit Tests
Creating a New Test Module
Create Test File
Create a file named
[module-name]-test.ts in the appropriate directory under app/test/unit/:Test Structure
Follow the Arrange-Act-Assert pattern:Best Practices
Keep tests focused: Each test should verify one specific behavior or scenario.
- Test module organization: Match the directory structure of
app/src/ - Descriptive test names: Use clear, readable descriptions
- Test edge cases: Cover error conditions and boundary cases
- Avoid complexity: If tests are complex, consider refactoring the code
- No code comments needed: Tests should be self-documenting
Example: Testing Pure Functions
Testing State Updates
When testing complex state logic inAppStore:
- Extract logic to pure functions outside of
AppStore - Take current state as a parameter instead of reading implicit state
- Return new state rather than mutating existing state
- Test the extracted function in isolation
Example Pattern
app/src/lib/stores/updates/changes-state.ts for a complete example.
Test Setup
Run test setup scripts:Continuous Integration
All tests run automatically on pull requests. Ensure your tests pass locally before pushing:Test Fixtures
Test fixtures are located inapp/test/fixtures/ and include:
- Sample Git repositories
- Test data files
- Mock configurations
Debugging Tests
To debug a failing test:- Run the specific test with the file path
- Add console.log statements to inspect values
- Use Node.js debugger with
--inspectflag - Check test isolation - ensure tests don’t depend on each other
Next Steps
- Learn about Linting
- Set up Development Tools
- Review Building instructions