Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid reporting NaN coverage #237

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fixtures/lcov.0.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; This is a manually generated lcov file that has no reported line founds.
SF:/very_good_coverage/fake_lcov__no_lines_found.dart
end_of_record
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function run() {
}
}
});
const coverage = (totalHits / totalFinds) * 100;
const coverage = totalFinds === 0 ? 0 : (totalHits / totalFinds) * 100;
const isValidBuild = coverage >= minCoverage;
const linesMissingCoverageByFile = Object.entries(linesMissingCoverage).map(
([file, lines]) => {
Expand Down
16 changes: 16 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,19 @@ test('shows lines that are missing coverage when coverage is less than 100%', ()
'/Users/felix/Development/github.com/felangel/bloc/packages/bloc/lib/src/bloc_observer.dart: 20, 27, 36, 43, 51'
);
});

test('reports 0 coverage when no lines are found ', () => {
const lcovPath = './fixtures/lcov.0.info';
const minCoverage = 100;
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env }).toString();
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();
const errorMessage = err.stdout.toString();
expect(errorMessage).toContain('0 is less than min_coverage 100');
}
});