|
1 | 1 | # Development Documentation |
2 | 2 |
|
| 3 | +## Testing and Code Coverage |
| 4 | + |
| 5 | +### Running Tests |
| 6 | + |
| 7 | +The project uses Jest for testing. To run the test suite you can use: |
| 8 | + |
| 9 | +```bash |
| 10 | +npm test |
| 11 | +``` |
| 12 | + |
| 13 | +This runs all tests with code coverage analysis enabled. |
| 14 | + |
| 15 | +### Test Configuration |
| 16 | + |
| 17 | +Test configuration is in `jest.config.js`, which extends `kcd-scripts/jest` with |
| 18 | +project-specific settings: |
| 19 | + |
| 20 | +```javascript |
| 21 | +const jestConfig = require('kcd-scripts/jest') |
| 22 | + |
| 23 | +module.exports = Object.assign(jestConfig, { |
| 24 | + coverageThreshold: { |
| 25 | + global: { |
| 26 | + branches: 50, |
| 27 | + functions: 40, |
| 28 | + lines: 50, |
| 29 | + statements: 50, |
| 30 | + }, |
| 31 | + }, |
| 32 | + forceExit: true, |
| 33 | +}) |
| 34 | +``` |
| 35 | + |
| 36 | +### Coverage Thresholds |
| 37 | + |
| 38 | +The project enforces minimum code coverage thresholds through the jest |
| 39 | +configuration above: |
| 40 | + |
| 41 | +| Coverage Type | Percentage | |
| 42 | +| ------------- | ---------- | |
| 43 | +| Branches | 50% | |
| 44 | +| Functions | 40% | |
| 45 | +| Lines | 50% | |
| 46 | +| Statements | 50% | |
| 47 | + |
| 48 | +Tests will fail if coverage drops below these thresholds. |
| 49 | + |
| 50 | +### Coverage Reports |
| 51 | + |
| 52 | +When you run tests, coverage reports are automatically generated in the |
| 53 | +`coverage/` directory: |
| 54 | + |
| 55 | +- **`coverage/lcov-report/index.html`** — Interactive HTML report (open in |
| 56 | + browser) |
| 57 | +- **`coverage/lcov.info`** — LCOV format (used by Codecov) |
| 58 | +- **`coverage/clover.xml`** — Clover XML format |
| 59 | +- **`coverage/coverage-final.json`** — JSON format |
| 60 | + |
| 61 | +The HTML report provides a visual breakdown of which files are covered by tests. |
| 62 | + |
| 63 | +### Codecov Integration |
| 64 | + |
| 65 | +The project uses Codecov to track code coverage over time and on pull requests. |
| 66 | + |
| 67 | +#### CI Integration |
| 68 | + |
| 69 | +- The GitHub Actions workflow (`.github/workflows/test-deploy.yml`) |
| 70 | + automatically uploads coverage to Codecov after running tests |
| 71 | +- Coverage reports appear as comments on pull requests (if enabled) |
| 72 | +- The workflow uses `codecov/codecov-action@vxxx` (whatever version is most |
| 73 | + recent) to upload the `lcov.info` file |
| 74 | + |
| 75 | +#### Configuration |
| 76 | + |
| 77 | +Codecov behavior is configured in `.codecov.yml`: |
| 78 | + |
| 79 | +- Patch coverage is tracked (checks coverage of changed code in PRs) |
| 80 | +- Project-level status checks are disabled |
| 81 | +- PR comments are disabled |
| 82 | +- Codecov now requires a token for all uploads so we have one generated in the |
| 83 | + repo as a secret `secrets.CODECOV_TOKEN`. |
| 84 | + |
| 85 | +#### Local Usage |
| 86 | + |
| 87 | +You don't need a Codecov account to view coverage locally—just run `pnpm test` |
| 88 | +and open the HTML report. Codecov integration is primarily for tracking coverage |
| 89 | +trends and to simplify PR reviews in the CI/CD pipeline. |
| 90 | + |
3 | 91 | ## Linting |
4 | 92 |
|
5 | 93 | 2026 update: The project is now using ESLint 9 and the flat config format. As we |
|
0 commit comments