Skip to main content

Test Suite Overview

GitHub Desktop uses Node.js’s built-in test runner for unit tests. Tests are organized under app/test/ with the following structure:
  • unit/ - Unit tests for individual modules and functions
  • integration/ - End-to-end tests using UI automation
  • fixtures/ - Git repositories and test data
  • helpers/ - Shared test utilities and setup code

Running Tests

Run All Tests

This runs all unit tests by default (equivalent to 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

1

Create Test File

Create a file named [module-name]-test.ts in the appropriate directory under app/test/unit/:
2

Run the Test

Verify your test file is recognized:
3

Write Real Tests

Replace the placeholder test with actual test cases for your module.

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 in AppStore:
  1. Extract logic to pure functions outside of AppStore
  2. Take current state as a parameter instead of reading implicit state
  3. Return new state rather than mutating existing state
  4. Test the extracted function in isolation

Example Pattern

See app/src/lib/stores/updates/changes-state.ts for a complete example.

Test Setup

Run test setup scripts:
This initializes test fixtures and prepares the test environment.

Continuous Integration

All tests run automatically on pull requests. Ensure your tests pass locally before pushing:
Pull requests must pass all tests before they can be merged.

Test Fixtures

Test fixtures are located in app/test/fixtures/ and include:
  • Sample Git repositories
  • Test data files
  • Mock configurations
When adding tests that require Git repositories, reuse existing fixtures or create new ones in this directory.

Debugging Tests

To debug a failing test:
  1. Run the specific test with the file path
  2. Add console.log statements to inspect values
  3. Use Node.js debugger with --inspect flag
  4. Check test isolation - ensure tests don’t depend on each other

Next Steps