mo3ta-coverage 1.0.6 โ 1.0.8
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/.mo3ta-coverage.json +4 -0
- package/README.md +45 -30
- package/index.js +83 -7
- package/package.json +1 -1
- package/src/cli.js +6 -4
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
16
|
```sh
|
|
17
|
-
mo3ta-coverage --base origin/
|
|
17
|
+
mo3ta-coverage --base origin/master --lcov coverage/lcov.info --limit 80 --showCovered --shallowTests=false
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## CLI Options
|
|
@@ -25,7 +25,7 @@ mo3ta-coverage --base origin/main --lcov coverage/lcov.info --limit 80 --showCov
|
|
|
25
25
|
| `--lcov` | Path to lcov.info file generated by test coverage tools | `coverage/lcov.info` |
|
|
26
26
|
| `--limit` | Minimum required coverage percentage for all changed lines | `80` |
|
|
27
27
|
| `--showCovered` | Show covered changed lines in the output | `false` |
|
|
28
|
-
| `--
|
|
28
|
+
| `--shallowTests` | Run test files only, skipping other files | `true` |
|
|
29
29
|
|
|
30
30
|
## How It Works
|
|
31
31
|
|
|
@@ -36,40 +36,55 @@ mo3ta-coverage --base origin/main --lcov coverage/lcov.info --limit 80 --showCov
|
|
|
36
36
|
5. **Report**: Prints uncovered changed lines, optionally covered lines, and overall coverage ([`src/cli.js`](src/cli.js)).
|
|
37
37
|
6. **Enforce limit**: Exits with error if coverage is below the specified threshold.
|
|
38
38
|
|
|
39
|
-
## Architecture Diagram
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
# mo3ta-coverage
|
|
41
|
+
|
|
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.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
npm install -g mo3ta-coverage
|
|
49
48
|
```
|
|
50
49
|
|
|
51
|
-
##
|
|
50
|
+
## Usage
|
|
52
51
|
|
|
52
|
+
```sh
|
|
53
|
+
mo3ta-coverage --base origin/main --lcov coverage/lcov.info --limit 80 --showCovered --shallowTests
|
|
53
54
|
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Covered lines: [20, 21, 22, 23]
|
|
69
|
-
Coverage for changed lines: 100.00%
|
|
70
|
-
๐ข Overall coverage for all changed lines: 80.00% limit is 80%
|
|
55
|
+
|
|
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
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
You can persist default options using the config command:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
mo3ta-coverage config --base origin/dev --shallowTests false
|
|
71
69
|
```
|
|
72
70
|
|
|
73
|
-
|
|
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.
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
74
|
|
|
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
|
+
```
|
|
88
|
+
|
|
89
|
+
## License
|
|
75
90
|
MIT
|
package/index.js
CHANGED
|
@@ -1,19 +1,95 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
import { Command } from 'commander';
|
|
4
5
|
import { main } from './src/cli.js';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
const CONFIG_PATH = path.resolve(process.cwd(), '.mo3ta-coverage.json');
|
|
10
|
+
|
|
11
|
+
function readConfig() {
|
|
12
|
+
console.log(`Reading config from: ${CONFIG_PATH}`);
|
|
13
|
+
|
|
14
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
|
15
|
+
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
|
|
16
|
+
}
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function writeConfig(config) {
|
|
21
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
22
|
+
console.log(`Updated config: ${JSON.stringify(config, null, 2)}`);
|
|
23
|
+
}
|
|
5
24
|
|
|
6
25
|
const program = new Command();
|
|
26
|
+
|
|
7
27
|
program
|
|
8
28
|
.name('mo3ta-coverage')
|
|
9
|
-
.description('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.')
|
|
10
|
-
|
|
29
|
+
.description('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.');
|
|
30
|
+
|
|
31
|
+
program
|
|
32
|
+
.option('--base <branch>', 'Base branch to compare against (e.g., origin/main)')
|
|
11
33
|
.option('--lcov <path>', 'Path to lcov.info file generated by test coverage tools', 'coverage/lcov.info')
|
|
12
34
|
.option('--limit <percent>', 'Minimum required coverage percentage for all changed lines (e.g., 80)', '80')
|
|
13
|
-
.option('--showCovered', 'Show covered changed lines in the output', false)
|
|
14
|
-
.option('--
|
|
35
|
+
.option('--showCovered <bool>', 'Show covered changed lines in the output', false)
|
|
36
|
+
.option('--shallowTests <bool>', 'Run test files only without deep in tests tree', true)
|
|
37
|
+
.passThroughOptions()
|
|
38
|
+
.enablePositionalOptions();
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
program
|
|
42
|
+
.command('config')
|
|
43
|
+
.description('Set or get configuration options')
|
|
44
|
+
.option('--base <branch>', 'Set default base branch')
|
|
45
|
+
.option('--shallowTests <bool>', 'Set default shallowTests value (true/false)')
|
|
46
|
+
.action((opts) => {
|
|
47
|
+
let config = readConfig();
|
|
48
|
+
|
|
49
|
+
let updated = false;
|
|
50
|
+
|
|
51
|
+
if (opts.base) {
|
|
52
|
+
config.base = opts.base;
|
|
53
|
+
updated = true;
|
|
54
|
+
console.log(`Default base branch set to: ${opts.base}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof opts.shallowTests !== 'undefined') {
|
|
58
|
+
config.shallowTests = opts.shallowTests === 'true' || opts.shallowTests === true;
|
|
59
|
+
updated = true;
|
|
60
|
+
console.log(`Default shallowTests set to: ${config.shallowTests}`);
|
|
61
|
+
}
|
|
62
|
+
if (updated) {
|
|
63
|
+
writeConfig(config);
|
|
64
|
+
} else {
|
|
65
|
+
console.log('Current config:', config);
|
|
66
|
+
}
|
|
67
|
+
process.exit(0);
|
|
68
|
+
})
|
|
69
|
+
.enablePositionalOptions()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
program.action((opts) => {
|
|
73
|
+
const config = readConfig();
|
|
74
|
+
const options = program.opts();
|
|
75
|
+
console.log(`Current config: ${JSON.stringify(config, null, 2)}`);
|
|
76
|
+
console.log(`Current options: ${JSON.stringify(options, null, 2)}`);
|
|
77
|
+
console.log(`Current wqwqw: ${JSON.stringify(opts, null, 2)}`);
|
|
78
|
+
|
|
79
|
+
// Use config base if not provided in CLI
|
|
80
|
+
if (!options.base && config.base) {
|
|
81
|
+
options.base = config.base;
|
|
82
|
+
} else if (!options.base) {
|
|
83
|
+
options.base = 'origin/main';
|
|
84
|
+
}
|
|
85
|
+
// Use config shallowTests if not provided in CLI
|
|
86
|
+
console.log(`Using shallowTests: ${options.shallowTests} ${config.shallowTests}`);
|
|
87
|
+
|
|
88
|
+
options.shallowTests = config.shallowTests ?? options.shallowTests;
|
|
89
|
+
|
|
90
|
+
console.log(`Final options: ${JSON.stringify(options, null, 2)}`);
|
|
15
91
|
|
|
16
|
-
|
|
17
|
-
|
|
92
|
+
main(options);
|
|
93
|
+
});
|
|
18
94
|
|
|
19
|
-
|
|
95
|
+
await program.parseAsync(process.argv);
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -18,12 +18,12 @@ export function main(options) {
|
|
|
18
18
|
const LCOV_PATH = options.lcov;
|
|
19
19
|
const COVERAGE_LIMIT = parseFloat(options.limit);
|
|
20
20
|
const SHOW_COVERED = options.showCovered === true || options.showCovered === 'true';
|
|
21
|
-
const
|
|
21
|
+
const SHALLOW_TESTS = options.shallowTests === true || options.shallowTests === 'true';
|
|
22
22
|
|
|
23
|
-
console.log(`Options:\nBase Branch: ${BASE_BRANCH} \nLCOV Path: ${LCOV_PATH} \nCoverage Limit: ${COVERAGE_LIMIT} \nShow Covered Lines: ${SHOW_COVERED} \
|
|
23
|
+
console.log(`Options:\nBase Branch: ${BASE_BRANCH} \nLCOV Path: ${LCOV_PATH} \nCoverage Limit: ${COVERAGE_LIMIT} \nShow Covered Lines: ${SHOW_COVERED} \nShallow Tests: ${SHALLOW_TESTS}`);
|
|
24
24
|
|
|
25
25
|
const changedFiles = getChangedFiles(BASE_BRANCH);
|
|
26
|
-
runRelatedTests(changedFiles,
|
|
26
|
+
runRelatedTests(changedFiles, SHALLOW_TESTS);
|
|
27
27
|
reportUncoveredChangedLines(changedFiles, LCOV_PATH, BASE_BRANCH, COVERAGE_LIMIT, SHOW_COVERED);
|
|
28
28
|
|
|
29
29
|
}
|
|
@@ -81,7 +81,9 @@ function getJsOnlyFiles(files, runTestsOnly) {
|
|
|
81
81
|
// Only include source code files, exclude test, config, and json files
|
|
82
82
|
return files.filter(f => {
|
|
83
83
|
// Exclude test files
|
|
84
|
-
if (f.match(/(\.test|\.spec)\.(js|ts|jsx|tsx)$/)) return false
|
|
84
|
+
if (f.match(/(\.test|\.spec)\.(js|ts|jsx|tsx)$/)) return false;
|
|
85
|
+
// skip non test files when running only test files
|
|
86
|
+
if (runTestsOnly) return false;
|
|
85
87
|
// Exclude config files
|
|
86
88
|
if (f.match(/(jest|babel|webpack|tsconfig|eslint|prettier|rollup|vite|package)\.(js|ts|json)$/)) return false;
|
|
87
89
|
// Exclude json files
|