mo3ta-coverage 1.0.16 ā 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 +23 -4
- 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
|
@@ -53,6 +53,14 @@ function getChangedFiles(BASE_BRANCH) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
export function selectTestFilesForMode(mode, changedTestFiles, mappedTestFiles) {
|
|
57
|
+
if (mode === 'smart') {
|
|
58
|
+
return changedTestFiles;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return mappedTestFiles;
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
function runRelatedTests(files, mode) {
|
|
57
65
|
if (files.length === 0) {
|
|
58
66
|
console.log('ā
No changed source files found.');
|
|
@@ -133,12 +141,23 @@ function runRelatedTests(files, mode) {
|
|
|
133
141
|
exit(1);
|
|
134
142
|
}
|
|
135
143
|
} else if (mode === 'smart') {
|
|
136
|
-
|
|
137
|
-
|
|
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}`);
|
|
138
157
|
console.log(` Source files for coverage: ${sourceFiles.length}`);
|
|
139
158
|
console.log(' Files passed to Jest:');
|
|
140
|
-
|
|
141
|
-
const command = `npx jest --passWithNoTests --coverage ${
|
|
159
|
+
changedTestFiles.forEach(file => console.log(` - ${file}`));
|
|
160
|
+
const command = `npx jest --passWithNoTests --coverage ${changedTestFiles.join(' ')}`;
|
|
142
161
|
console.log(` Jest command: ${command}`);
|
|
143
162
|
|
|
144
163
|
try {
|
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
|
+
});
|