# Stock Bot Coverage CLI A custom coverage tool for the Stock Bot monorepo that provides advanced coverage reporting with support for excluding directories (like `dist/`) and beautiful reporting options. ## Features - 🚫 **Exclusion Support**: Exclude directories like `dist/`, `node_modules/`, and test files from coverage - πŸ“Š **Multiple Reporters**: Terminal, HTML, JSON, and Markdown reports - 🎯 **Threshold Enforcement**: Set and enforce coverage thresholds - πŸ“¦ **Monorepo Support**: Works seamlessly with workspace packages - 🎨 **Beautiful Reports**: Interactive HTML reports and colored terminal output - πŸ”§ **Configurable**: Use `.coveragerc.json` or CLI flags ## Installation The tool is already part of the Stock Bot monorepo. Just run: ```bash bun install ``` ## Usage ### Basic Usage Run coverage for all packages: ```bash bun run coverage ``` ### Generate HTML Report ```bash bun run coverage:html ``` ### CI Mode Generate markdown and JSON reports, fail if below threshold: ```bash bun run coverage:ci ``` ### Run for Specific Packages ```bash bun run coverage --packages core utils ``` ### Custom Exclusions ```bash bun run coverage --exclude "**/dist/**" "**/generated/**" "**/vendor/**" ``` ### Set Thresholds ```bash bun run coverage --threshold 85 --threshold-functions 80 ``` ## Configuration Create a `.coveragerc.json` file in your project root: ```json { "exclude": [ "**/node_modules/**", "**/dist/**", "**/build/**", "**/coverage/**", "**/*.test.ts", "**/*.test.js", "**/test/**", "**/tests/**" ], "reporters": ["terminal", "html"], "thresholds": { "lines": 80, "functions": 80, "branches": 80, "statements": 80 }, "outputDir": "coverage" } ``` Or create one with: ```bash bun run coverage init ``` ## Reporters ### Terminal Reporter Beautiful colored output in your terminal: ``` ═══════════════════════════════════════════════════════════ Stock Bot Coverage Report ═══════════════════════════════════════════════════════════ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Package β”‚ Lines β”‚ Functionsβ”‚ Branches β”‚ Statements β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ @stock-bot/coreβ”‚ 85.3% βœ“ β”‚ 82.1% βœ“ β”‚ 79.2% ⚠ β”‚ 84.7% βœ“ β”‚ β”‚ @stock-bot/utilsβ”‚ 92.1% βœ“ β”‚ 90.5% βœ“ β”‚ 88.3% βœ“ β”‚ 91.8% βœ“ β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Overall β”‚ 88.7% βœ“ β”‚ 86.3% βœ“ β”‚ 83.8% βœ“ β”‚ 88.3% βœ“ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ βœ“ 15 packages meet coverage thresholds ⚠ 2 packages below threshold ``` ### HTML Reporter Interactive HTML report with: - Package breakdown - File-level coverage - Beautiful charts and visualizations - Responsive design ### Markdown Reporter Perfect for CI/CD comments on pull requests: - Summary tables - Package details - Threshold status - File breakdowns ### JSON Reporter Machine-readable format for: - Custom tooling integration - Historical tracking - CI/CD pipelines ## CLI Options | Option | Description | |--------|-------------| | `-p, --packages ` | Run coverage for specific packages | | `-e, --exclude ` | Glob patterns to exclude from coverage | | `-i, --include ` | Glob patterns to include in coverage | | `-r, --reporters ` | Coverage reporters to use | | `-t, --threshold ` | Set coverage threshold for all metrics | | `--threshold-lines ` | Set line coverage threshold | | `--threshold-functions ` | Set function coverage threshold | | `--threshold-branches ` | Set branch coverage threshold | | `--threshold-statements ` | Set statement coverage threshold | | `-o, --output-dir ` | Output directory for reports | | `-c, --config ` | Path to coverage config file | | `--fail-under` | Exit with non-zero code if below threshold | ## How It Works 1. **Test Execution**: Runs `bun test` for each package 2. **Data Collection**: Currently simulates coverage data based on test results (Bun's coverage feature is not yet fully implemented) 3. **Filtering**: Applies exclusion patterns to remove unwanted files 4. **Processing**: Merges coverage data across packages 5. **Reporting**: Generates reports in requested formats > **Note**: This tool currently generates simulated coverage data based on test results because Bun's `--coverage` flag doesn't yet produce LCOV output. Once Bun's coverage feature is fully implemented, the tool will be updated to use actual coverage data. ## Why This Tool? Bun's built-in coverage tool lacks several features needed for large monorepos: - No way to exclude directories like `dist/` - Limited reporting options - No per-package thresholds - Basic terminal output This tool addresses these limitations while maintaining compatibility with Bun's test runner. ## Contributing The coverage tool is located in `tools/coverage-cli/`. To work on it: 1. Make changes in `tools/coverage-cli/src/` 2. Test with `bun run coverage` 3. Build with `bun build tools/coverage-cli/src/index.ts` ## License Part of the Stock Bot Trading Platform - MIT License