|
| 1 | +# Running Tests in Roo-Code |
| 2 | + |
| 3 | +This document explains how to run tests in the Roo-Code codebase. |
| 4 | + |
| 5 | +## Test Framework |
| 6 | + |
| 7 | +The project uses Jest for testing, with both extension (backend) and webview (frontend) tests. The test configuration is defined in `jest.config.js` at the root of the project. |
| 8 | + |
| 9 | +## Main Test Commands |
| 10 | + |
| 11 | +- **Run all tests**: |
| 12 | + |
| 13 | + ``` |
| 14 | + npm test |
| 15 | + ``` |
| 16 | +
|
| 17 | + This runs both extension and webview tests in parallel. |
| 18 | +
|
| 19 | +- **Run only extension tests**: |
| 20 | +
|
| 21 | + ``` |
| 22 | + npm run test:extension |
| 23 | + ``` |
| 24 | +
|
| 25 | +- **Run only webview UI tests**: |
| 26 | + ``` |
| 27 | + npm run test:webview |
| 28 | + ``` |
| 29 | +
|
| 30 | +## Additional Options |
| 31 | +
|
| 32 | +- **Run specific test file**: |
| 33 | +
|
| 34 | + ``` |
| 35 | + npm run test:extension -- src/path/to/file.test.ts |
| 36 | + ``` |
| 37 | +
|
| 38 | +- **Run tests with verbose output**: |
| 39 | +
|
| 40 | + ``` |
| 41 | + npm run test:extension -- --verbose |
| 42 | + ``` |
| 43 | +
|
| 44 | +- **Update snapshots** (useful when system prompt changes): |
| 45 | + ``` |
| 46 | + npm run test:extension -- -u |
| 47 | + ``` |
| 48 | +- **List all test files**: |
| 49 | +
|
| 50 | + ``` |
| 51 | + npm run test:extension -- --listTests |
| 52 | + ``` |
| 53 | +
|
| 54 | +- **Troubleshoot hanging tests**: |
| 55 | + ``` |
| 56 | + npm run test:extension -- --detectOpenHandles |
| 57 | + ``` |
| 58 | +
|
| 59 | +## Test Structure |
| 60 | +
|
| 61 | +- Tests are located in `__tests__` directories throughout the codebase |
| 62 | +- Test files use the `.test.ts` naming convention |
| 63 | +- The project follows Jest conventions for test organization |
| 64 | +- Snapshot tests are used for testing prompts and other text-based outputs |
| 65 | +- Various mocks are implemented in `src/__mocks__/` directory |
| 66 | +
|
| 67 | +## Common Test Failures |
| 68 | +
|
| 69 | +### Snapshot Test Failures |
| 70 | +
|
| 71 | +Snapshot tests may fail when changes are made to the system prompt or other text-based outputs. For example, adding a new tool to the system prompt will cause snapshot tests to fail until they are updated. |
| 72 | +
|
| 73 | +To update snapshots: |
| 74 | +
|
| 75 | +``` |
| 76 | +npm run test:extension -- -u |
| 77 | +``` |
| 78 | +
|
| 79 | +Or update snapshots for a specific file: |
| 80 | +
|
| 81 | +``` |
| 82 | +npm run test:extension -- -u src/core/prompts/__tests__/system.test.ts |
| 83 | +``` |
| 84 | +
|
| 85 | +## Code Quality Rules |
| 86 | +
|
| 87 | +According to the `.clinerules` file, test coverage is important in this project: |
| 88 | +
|
| 89 | +1. Before attempting completion, always make sure that any code changes have test coverage |
| 90 | +2. Ensure all tests pass before submitting changes |
0 commit comments