mo3ta-coverage 1.0.9 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,90 +1,78 @@
1
- # mo3ta-coverage
1
+ # mo3ta-coverage ![NPM Version](https://img.shields.io/npm/v/mo3ta-coverage)
2
2
 
3
- **mo3ta-coverage** is a CLI tool for checking test coverage of changed lines in a pull request. It runs related tests, parses coverage reports, and ensures cumulative coverage meets a specified threshold—ideal for CI and code review workflows.
3
+ mo3ta-coverage checks coverage for changed lines in a pull request. It finds changed source files, maps them to likely test files, runs Jest in a selected execution mode, and validates changed-line coverage against a threshold.
4
4
 
5
5
  ## Features
6
6
 
7
- - Detects changed files between branches using `git diff`
8
- - Runs related Jest tests for changed files
9
- - Parses `lcov.info` for coverage data
10
- - Reports uncovered changed lines
11
- - Optionally displays covered changed lines
12
- - Checks overall coverage against a user-defined limit
7
+ - Detects changed JS/TS files from git history and working tree
8
+ - Maps changed source files to nearby test files automatically
9
+ - Supports three execution modes: `fast`, `smart`, and `full`
10
+ - Parses `lcov.info` and reports uncovered changed lines
11
+ - Enforces a minimum coverage threshold for changed lines
13
12
 
14
- ## Usage
13
+ ## Installation
15
14
 
16
15
  ```sh
17
- mo3ta-coverage --base origin/master --lcov coverage/lcov.info --limit 80 --showCovered --shallowTests=false
16
+ npm install -g mo3ta-coverage
18
17
  ```
19
18
 
20
- ## CLI Options
21
-
22
- | Option | Description | Default |
23
- |------------------|------------------------------------------------------------------|----------------------|
24
- | `--base` | Base branch to compare against | `origin/main` |
25
- | `--lcov` | Path to lcov.info file generated by test coverage tools | `coverage/lcov.info` |
26
- | `--limit` | Minimum required coverage percentage for all changed lines | `80` |
27
- | `--showCovered` | Show covered changed lines in the output | `false` |
28
- | `--shallowTests` | Run test files only, skipping other files | `true` |
29
-
30
- ## How It Works
19
+ ## Usage
31
20
 
32
- 1. **Parse CLI options** using [commander](https://www.npmjs.com/package/commander) in [`index.js`](index.js).
33
- 2. **Get changed files**: Uses `git diff --name-only <base>` to find modified JS/TS files ([`src/cli.js`](src/cli.js)).
34
- 3. **Run related tests**: Executes Jest for changed files with `--findRelatedTests` ([`src/cli.js`](src/cli.js)).
35
- 4. **Parse coverage**: Reads `lcov.info` to find uncovered lines ([`src/cli.js`](src/cli.js)).
36
- 5. **Report**: Prints uncovered changed lines, optionally covered lines, and overall coverage ([`src/cli.js`](src/cli.js)).
37
- 6. **Enforce limit**: Exits with error if coverage is below the specified threshold.
21
+ ```sh
22
+ mo3ta-coverage --mode smart --base origin/main --limit 80
23
+ ```
38
24
 
25
+ ## CLI Options
39
26
 
40
- # mo3ta-coverage
27
+ | Option | Description | Default |
28
+ |--------|-------------|---------|
29
+ | `--base <branch>` | Base branch to compare against | `origin/main` |
30
+ | `--lcov <path>` | Path to `lcov.info` | `coverage/lcov.info` |
31
+ | `--limit <percent>` | Minimum changed-line coverage percentage | `80` |
32
+ | `--showCovered <bool>` | Show covered changed lines in output | `false` |
33
+ | `--mode <mode>` | Execution mode: `fast`, `smart`, or `full` | `smart` |
41
34
 
42
- Run tests and report uncovered changed lines in a PR. Checks cumulative coverage for all changed lines against a specified limit. Useful for CI and code review workflows.
35
+ ## Modes
43
36
 
44
- ## Installation
37
+ - `fast`: Direct execution of mapped test files only. No Jest dependency traversal.
38
+ - `smart`: Direct execution of changed source files plus mapped test files. No Jest dependency traversal.
39
+ - `full`: Runs mapped test files through `jest --findRelatedTests`.
45
40
 
46
- ```sh
47
- npm install -g mo3ta-coverage
48
- ```
41
+ ## Recommended Mode
49
42
 
50
- ## Usage
43
+ For most projects, especially large ones with shared helpers or deep import graphs, use:
51
44
 
52
45
  ```sh
53
- mo3ta-coverage --base origin/main --lcov coverage/lcov.info --limit 80 --showCovered --shallowTests
46
+ mo3ta-coverage --mode smart --base origin/main --limit 80
54
47
  ```
55
48
 
56
- ### Options
57
- - `--base <branch>`: Base branch to compare against (default: origin/main or config value)
58
- - `--lcov <path>`: Path to lcov.info file generated by test coverage tools (default: coverage/lcov.info)
59
- - `--limit <percent>`: Minimum required coverage percentage for all changed lines (default: 80)
60
- - `--showCovered`: Show covered changed lines in the output
61
- - `--shallowTests`: Run test files only without deep in tests tree
49
+ Use `full` only when you intentionally want Jest to expand to related tests.
62
50
 
63
51
  ## Configuration
64
52
 
65
- You can persist default options using the config command:
53
+ You can persist defaults with the `config` subcommand:
66
54
 
67
55
  ```sh
68
- mo3ta-coverage config --base origin/dev --shallowTests false
56
+ mo3ta-coverage config --base origin/main --mode smart
69
57
  ```
70
58
 
71
- This will save your preferences in `.mo3ta-coverage.json` in your project root. The CLI will use these values unless overridden by command-line options.
59
+ This writes `.mo3ta-coverage.json` in the project root.
60
+
61
+ ## How It Works
62
+
63
+ 1. Reads CLI options and saved config from [index.js](index.js).
64
+ 2. Finds changed source files from git in [src/cli.js](src/cli.js).
65
+ 3. Maps source files to nearby test files in [src/fileUtils.js](src/fileUtils.js).
66
+ 4. Runs Jest in the selected mode from [src/cli.js](src/cli.js).
67
+ 5. Parses `lcov.info` and reports uncovered changed lines.
72
68
 
73
69
  ## Development
74
70
 
75
- 1. Clone the repository
76
- 2. Install dependencies:
77
- ```sh
78
- npm install
79
- ```
80
- 3. Run tests:
81
- ```sh
82
- npm test
83
- ```
84
- 4. Run tests with coverage:
85
- ```sh
86
- npm run test:coverage
87
- ```
71
+ ```sh
72
+ npm install
73
+ npm test
74
+ ```
88
75
 
89
76
  ## License
90
- MIT
77
+
78
+ MIT
@@ -0,0 +1,67 @@
1
+ # Recommended Usage for Large Projects
2
+
3
+ ## TL;DR
4
+
5
+ For projects with large suites or shared test infrastructure, use:
6
+
7
+ ```bash
8
+ mo3ta-coverage --mode smart --base origin/main --limit 80
9
+ ```
10
+
11
+ ## Why `smart`
12
+
13
+ `smart` avoids Jest dependency traversal while still passing both changed source files and mapped test files into the run. That makes it the most predictable mode for large projects.
14
+
15
+ ## Mode Comparison
16
+
17
+ | Mode | What Jest Receives | Traversal | Typical Outcome |
18
+ |------|--------------------|-----------|-----------------|
19
+ | `fast` | mapped test files | none | fastest run |
20
+ | `smart` | source files + mapped test files | none | best balance |
21
+ | `full` | mapped test files via `--findRelatedTests` | yes | can expand widely |
22
+
23
+ ## Project Setup
24
+
25
+ ### CLI
26
+
27
+ ```bash
28
+ mo3ta-coverage --mode smart --base origin/main --limit 80
29
+ ```
30
+
31
+ ### Config File
32
+
33
+ ```json
34
+ {
35
+ "base": "origin/main",
36
+ "mode": "smart"
37
+ }
38
+ ```
39
+
40
+ ### package.json
41
+
42
+ ```json
43
+ {
44
+ "scripts": {
45
+ "test:coverage": "mo3ta-coverage --mode smart --limit 80"
46
+ }
47
+ }
48
+ ```
49
+
50
+ ### GitHub Actions
51
+
52
+ ```yaml
53
+ - name: Run coverage check
54
+ run: npx mo3ta-coverage --mode smart --base origin/main --limit 80
55
+ ```
56
+
57
+ ## When To Use `full`
58
+
59
+ Use `full` only if you explicitly want Jest to discover more tests through dependency traversal and you accept that this may widen the run substantially.
60
+
61
+ ## When To Use `fast`
62
+
63
+ Use `fast` when you want the quickest direct execution of mapped tests and do not want source files added to the Jest argument list.
64
+
65
+ ## Summary
66
+
67
+ For large codebases, `smart` should be your default operational mode.