mo3ta-coverage 1.0.15 ā 1.0.18
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 +1 -1
- package/RECOMMENDED_USAGE.md +2 -2
- package/package.json +1 -1
- package/src/cli.js +34 -8
- package/src/cli.test.js +16 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ mo3ta-coverage --mode smart --base origin/main --limit 80
|
|
|
35
35
|
## Modes
|
|
36
36
|
|
|
37
37
|
- `fast`: Direct execution of mapped test files only. No Jest dependency traversal.
|
|
38
|
-
- `smart`: Direct execution of
|
|
38
|
+
- `smart`: Direct execution of changed test files only. It does not expand to mapped or imported test files, and performs no Jest dependency traversal.
|
|
39
39
|
- `full`: Runs mapped test files through `jest --findRelatedTests`.
|
|
40
40
|
|
|
41
41
|
## Recommended Mode
|
package/RECOMMENDED_USAGE.md
CHANGED
|
@@ -10,14 +10,14 @@ mo3ta-coverage --mode smart --base origin/main --limit 80
|
|
|
10
10
|
|
|
11
11
|
## Why `smart`
|
|
12
12
|
|
|
13
|
-
`smart` avoids Jest dependency traversal by running only
|
|
13
|
+
`smart` avoids Jest dependency traversal by running only test files that are themselves changed in the diff. It never expands to every test file related to a changed source file, which keeps the run predictable for large projects.
|
|
14
14
|
|
|
15
15
|
## Mode Comparison
|
|
16
16
|
|
|
17
17
|
| Mode | What Jest Receives | Traversal | Typical Outcome |
|
|
18
18
|
|------|--------------------|-----------|-----------------|
|
|
19
19
|
| `fast` | mapped test files | none | fastest run |
|
|
20
|
-
| `smart` |
|
|
20
|
+
| `smart` | changed test files only | none | predictable changed-file check |
|
|
21
21
|
| `full` | mapped test files via `--findRelatedTests` | yes | can expand widely |
|
|
22
22
|
|
|
23
23
|
## Project Setup
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -40,16 +40,27 @@ function getChangedFiles(BASE_BRANCH) {
|
|
|
40
40
|
|
|
41
41
|
try {
|
|
42
42
|
const output = execSync(command).toString();
|
|
43
|
-
|
|
44
|
-
return output
|
|
43
|
+
const changedFiles = output
|
|
45
44
|
.split('\n')
|
|
46
|
-
.filter(f => f.trim().length > 0 && f.match(/\.(js|ts|jsx|tsx)$/))
|
|
45
|
+
.filter(f => f.trim().length > 0 && f.match(/\.(js|ts|jsx|tsx)$/))
|
|
46
|
+
// Defensive: ignore dependency/build/coverage artifacts even if git tracked them
|
|
47
|
+
.filter(f => !f.match(/(^|\/)(node_modules|coverage|dist|build)\/|(^|\/)\.git\//));
|
|
48
|
+
console.log(`Changed files:\n${changedFiles.join('\n')}`);
|
|
49
|
+
return changedFiles;
|
|
47
50
|
} catch (error) {
|
|
48
51
|
console.error('Error getting changed files:', error.message || error);
|
|
49
52
|
return [];
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
export function selectTestFilesForMode(mode, changedTestFiles, mappedTestFiles) {
|
|
57
|
+
if (mode === 'smart') {
|
|
58
|
+
return changedTestFiles;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return mappedTestFiles;
|
|
62
|
+
}
|
|
63
|
+
|
|
53
64
|
function runRelatedTests(files, mode) {
|
|
54
65
|
if (files.length === 0) {
|
|
55
66
|
console.log('ā
No changed source files found.');
|
|
@@ -130,12 +141,23 @@ function runRelatedTests(files, mode) {
|
|
|
130
141
|
exit(1);
|
|
131
142
|
}
|
|
132
143
|
} else if (mode === 'smart') {
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
// Smart mode is intentionally scoped to the changed files in the diff.
|
|
145
|
+
// Mapped tests can include unchanged files (especially when a source file
|
|
146
|
+
// is imported by a broad test suite), which makes smart mode unexpectedly
|
|
147
|
+
// run the whole suite. Only changed test files belong in this mode.
|
|
148
|
+
const changedTestFiles = selectTestFilesForMode(mode, testFiles, finalTestFiles);
|
|
149
|
+
if (changedTestFiles.length === 0) {
|
|
150
|
+
console.log('\nā ļø No changed test files found to run in smart mode.');
|
|
151
|
+
console.log('Change a test file or use --mode full to run related tests for changed source files.');
|
|
152
|
+
exit(0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
console.log(`\nš Test strategy: smart (Run only changed test files, no Jest dependency traversal)`);
|
|
156
|
+
console.log(` Test files: ${changedTestFiles.length}`);
|
|
135
157
|
console.log(` Source files for coverage: ${sourceFiles.length}`);
|
|
136
158
|
console.log(' Files passed to Jest:');
|
|
137
|
-
|
|
138
|
-
const command = `npx jest --passWithNoTests --coverage ${
|
|
159
|
+
changedTestFiles.forEach(file => console.log(` - ${file}`));
|
|
160
|
+
const command = `npx jest --passWithNoTests --coverage ${changedTestFiles.join(' ')}`;
|
|
139
161
|
console.log(` Jest command: ${command}`);
|
|
140
162
|
|
|
141
163
|
try {
|
|
@@ -340,9 +362,13 @@ function reportUncoveredChangedLines(changedFiles, LCOV_PATH, BASE_BRANCH, COVER
|
|
|
340
362
|
|
|
341
363
|
// Cumulative coverage check
|
|
342
364
|
if (totalChanged > 0) {
|
|
343
|
-
const { overallCoverage, icon } = summarizeCoverageResult(totalChanged, totalNotCovered, COVERAGE_LIMIT);
|
|
365
|
+
const { overallCoverage, passed, icon } = summarizeCoverageResult(totalChanged, totalNotCovered, COVERAGE_LIMIT);
|
|
344
366
|
console.log(`\n${icon} Overall coverage for all changed lines: ${overallCoverage.toFixed(2)}% (limit: ${COVERAGE_LIMIT}%)`);
|
|
345
367
|
console.log(`Not covered lines: ${totalNotCovered} out of ${totalChanged} changed lines`);
|
|
346
368
|
formatMissedLinesSummary(uncoveredByFile).forEach(line => console.log(line));
|
|
369
|
+
|
|
370
|
+
if (!passed) {
|
|
371
|
+
process.exit(1);
|
|
372
|
+
}
|
|
347
373
|
}
|
|
348
374
|
}
|
package/src/cli.test.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
classifyChangedLineCoverage,
|
|
6
6
|
formatMissedLinesSummary,
|
|
7
7
|
parseLcov,
|
|
8
|
+
selectTestFilesForMode,
|
|
8
9
|
summarizeCoverageResult
|
|
9
10
|
} from './cli.js';
|
|
10
11
|
|
|
@@ -91,6 +92,20 @@ describe('summarizeCoverageResult', () => {
|
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
94
|
|
|
95
|
+
describe('selectTestFilesForMode', () => {
|
|
96
|
+
const changedTests = ['src/changed.test.js'];
|
|
97
|
+
const mappedTests = ['src/changed.test.js', 'src/unchanged.test.js'];
|
|
98
|
+
|
|
99
|
+
it('limits smart mode to test files changed in the diff', () => {
|
|
100
|
+
expect(selectTestFilesForMode('smart', changedTests, mappedTests)).toEqual(changedTests);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('keeps mapped tests for non-smart modes', () => {
|
|
104
|
+
expect(selectTestFilesForMode('fast', changedTests, mappedTests)).toEqual(mappedTests);
|
|
105
|
+
expect(selectTestFilesForMode('full', changedTests, mappedTests)).toEqual(mappedTests);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
94
109
|
describe('formatMissedLinesSummary', () => {
|
|
95
110
|
it('formats uncovered files and lines for the final summary', () => {
|
|
96
111
|
const result = formatMissedLinesSummary([
|
|
@@ -110,4 +125,4 @@ describe('formatMissedLinesSummary', () => {
|
|
|
110
125
|
it('returns no summary lines when no files have missed lines', () => {
|
|
111
126
|
expect(formatMissedLinesSummary([])).toEqual([]);
|
|
112
127
|
});
|
|
113
|
-
});
|
|
128
|
+
});
|