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 +46 -58
- package/RECOMMENDED_USAGE.md +67 -0
- package/coverage/clover.xml +427 -0
- package/coverage/coverage-final.json +5 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/cli.js.html +1252 -0
- package/coverage/lcov-report/coverage/index.html +116 -0
- package/coverage/lcov-report/coverage/index.js.html +364 -0
- package/coverage/lcov-report/coverage/src/cli.js.html +652 -0
- package/coverage/lcov-report/coverage/src/fileUtils.js.html +130 -0
- package/coverage/lcov-report/coverage/src/gitUtils.js.html +145 -0
- package/coverage/lcov-report/coverage/src/index.html +146 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/fileUtils.js.html +775 -0
- package/coverage/lcov-report/gitUtils.js.html +145 -0
- package/coverage/lcov-report/importer.js.html +1051 -0
- package/coverage/lcov-report/index.html +161 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +799 -0
- package/index.js +43 -8
- package/package.json +3 -2
- package/src/cli.js +252 -52
- package/src/cli.test.js +113 -0
- package/src/fileUtils.js +215 -0
- package/src/fileUtils.test.js +182 -1
- package/src/importer.js +323 -0
- package/.github/workflows/publish.yml +0 -29
- package/.mo3ta-coverage.json +0 -4
package/README.md
CHANGED
|
@@ -1,90 +1,78 @@
|
|
|
1
|
-
# mo3ta-coverage
|
|
1
|
+
# mo3ta-coverage 
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
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
|
-
##
|
|
13
|
+
## Installation
|
|
15
14
|
|
|
16
15
|
```sh
|
|
17
|
-
|
|
16
|
+
npm install -g mo3ta-coverage
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
##
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
+
## Modes
|
|
43
36
|
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
npm install -g mo3ta-coverage
|
|
48
|
-
```
|
|
41
|
+
## Recommended Mode
|
|
49
42
|
|
|
50
|
-
|
|
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 --
|
|
46
|
+
mo3ta-coverage --mode smart --base origin/main --limit 80
|
|
54
47
|
```
|
|
55
48
|
|
|
56
|
-
|
|
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
|
|
53
|
+
You can persist defaults with the `config` subcommand:
|
|
66
54
|
|
|
67
55
|
```sh
|
|
68
|
-
mo3ta-coverage config --base origin/
|
|
56
|
+
mo3ta-coverage config --base origin/main --mode smart
|
|
69
57
|
```
|
|
70
58
|
|
|
71
|
-
This
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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.
|