Skip to content

Commit c50a398

Browse files
authored
fix: avoid reporting NaN coverage (#237)
1 parent c09fc48 commit c50a398

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

fixtures/lcov.0.info

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; This is a manually generated lcov file that has no reported line founds.
2+
SF:/very_good_coverage/fake_lcov__no_lines_found.dart
3+
end_of_record

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function run() {
4141
}
4242
}
4343
});
44-
const coverage = (totalHits / totalFinds) * 100;
44+
const coverage = totalFinds === 0 ? 0 : (totalHits / totalFinds) * 100;
4545
const isValidBuild = coverage >= minCoverage;
4646
const linesMissingCoverageByFile = Object.entries(linesMissingCoverage).map(
4747
([file, lines]) => {

index.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,19 @@ test('shows lines that are missing coverage when coverage is less than 100%', ()
188188
'/Users/felix/Development/github.com/felangel/bloc/packages/bloc/lib/src/bloc_observer.dart: 20, 27, 36, 43, 51'
189189
);
190190
});
191+
192+
test('reports 0 coverage when no lines are found ', () => {
193+
const lcovPath = './fixtures/lcov.0.info';
194+
const minCoverage = 100;
195+
process.env['INPUT_PATH'] = lcovPath;
196+
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
197+
const ip = path.join(__dirname, 'index.js');
198+
try {
199+
cp.execSync(`node ${ip}`, { env: process.env }).toString();
200+
fail('this code should fail');
201+
} catch (err) {
202+
expect(err).toBeDefined();
203+
const errorMessage = err.stdout.toString();
204+
expect(errorMessage).toContain('0 is less than min_coverage 100');
205+
}
206+
});

0 commit comments

Comments
 (0)