mo3ta-coverage 1.0.7 โ†’ 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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "shallowTests": false,
3
+ "base": "origin/dev"
4
+ }
package/README.md CHANGED
@@ -36,40 +36,55 @@ mo3ta-coverage --base origin/master --lcov coverage/lcov.info --limit 80 --showC
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
-
41
- ```mermaid
42
- flowchart TD
43
- A[User runs mo3ta-coverage] --> B[Parse CLI options in index.js]
44
- B --> C[Get changed files via git diff in cli.js]
45
- C --> D[Run related Jest tests in cli.js]
46
- D --> E[Parse lcov.info for coverage in cli.js]
47
- E --> F[Report uncovered & covered changed lines in cli.js]
48
- F --> G[Check overall coverage vs limit in cli.js]
39
+
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
- ## Example Output
50
+ ## Usage
52
51
 
52
+ ```sh
53
+ mo3ta-coverage --base origin/main --lcov coverage/lcov.info --limit 80 --showCovered --shallowTests
53
54
  ```
54
- Options:
55
- Base Branch: origin/main
56
- LCOV Path: coverage/lcov.info
57
- Coverage Limit: 80
58
- Show Covered Lines: true
59
- ๐Ÿงช Running tests related to the changed files:
60
- src/foo.js
61
- src/bar.js
62
- ๐Ÿšจ /abs/path/src/foo.js - Uncovered changed lines: [12, 15]
63
- Total changed lines: 5, Covered: 3, Uncovered: 2
64
- Covered lines: [10, 11, 13]
65
- Coverage for changed lines: 60.00%
66
- โœ… /abs/path/src/bar.js - All changed lines are covered
67
- Total changed lines: 4, Covered: 4, Uncovered: 0
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
- ## License
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
- .option('--base <branch>', 'Base branch to compare against (e.g., origin/main)', 'origin/main')
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('--shallowTests', 'Run test files only without deep in tests tree', true);
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
- program.parse(process.argv);
17
- const options = program.opts();
92
+ main(options);
93
+ });
18
94
 
19
- main(options);
95
+ await program.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mo3ta-coverage",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Run tests and report uncovered changed lines in a PR",
5
5
  "main": "index.js",
6
6
  "bin": {
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 RUN_TESTS_ONLY = options.shallowTests === true || options.shallowTests === 'true';
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} \nRun Tests Only: ${RUN_TESTS_ONLY}`);
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, RUN_TESTS_ONLY);
26
+ runRelatedTests(changedFiles, SHALLOW_TESTS);
27
27
  reportUncoveredChangedLines(changedFiles, LCOV_PATH, BASE_BRANCH, COVERAGE_LIMIT, SHOW_COVERED);
28
28
 
29
29
  }