Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit 41a5e42

Browse files
authored
Merge pull request #45 from codacy/FixJSCoverageReporting
Fix js coverage reporting
2 parents 0ee0002 + ab4d849 commit 41a5e42

File tree

13 files changed

+4916
-31
lines changed

13 files changed

+4916
-31
lines changed

.buddyrc

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/impl/lcov.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050

5151
//TODO: Convert to reduce function
5252
stats.lines.details.forEach(function (detail) {
53-
// If a line is not sent to the service then it is considered to be 0, so no need to be redundant in the payload.
53+
// Codacy needs the 0s to know failed coverage data
5454
// We also can't have a negative number of hits on a line, so exclude those.
55-
if (detail.hit >= 1) {
55+
if (detail.hit >= 0) {
5656
fileStats.coverage[detail.line] = detail.hit;
5757
}
5858
});

lib/reporter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
fileReports: Joi.array().required().items(Joi.object({
1212
filename: Joi.string().required().min(1),
1313
total: Joi.number().integer().required().min(0).max(100),
14-
coverage: Joi.object().pattern(/\d/, Joi.number().integer().min(1))
14+
coverage: Joi.object().pattern(/\d/, Joi.number().integer().min(0))
1515
}).required())
1616
}).example({total: 50, fileReports: [{filename: 'filename', total: 10, coverage: {1: 1, 2: 3}}]});
1717

@@ -21,14 +21,15 @@
2121
ts: 'typescript',
2222
tsx: 'typescript',
2323
coffee: 'coffeescript'
24-
}
24+
};
2525

2626
function sendByLanguage(endpoint, commitId, token, data) {
2727
var reportsByLanguage = lodash.groupBy(data.fileReports, function(elem) {
2828
return languageMap[lodash.head(lodash.takeRight(elem.filename.split('.'), 1))] || 'javascript';
2929
});
3030

3131
var languageResponses = lodash.map(reportsByLanguage, function(fileReports, language) {
32+
3233
var weighedCoverage = lodash.reduce(fileReports, function(accom, elem) {
3334
return accom + (elem.total * Object.keys(elem.coverage).length);
3435
}, 0);

0 commit comments

Comments
 (0)