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

Commit

Permalink
Merge pull request #73 from MediaMarktSaturn/feature/jacocoReports
Browse files Browse the repository at this point in the history
Feature/jacoco reports
  • Loading branch information
rtfpessoa committed Nov 21, 2018
2 parents 3b41638 + daf582f commit bf8435a
Show file tree
Hide file tree
Showing 12 changed files with 726 additions and 266 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
@@ -1,5 +1,6 @@
{
"env": {
"es6": true,
"mocha": true,
"node": true
},
Expand Down
2 changes: 1 addition & 1 deletion lib/coverageParser.js
@@ -1,7 +1,7 @@
(function (Joi, util, logger) {
'use strict';

var validFormats = ['lcov'];
var validFormats = ['lcov','jacoco'];
var formatValidation = Joi.string().valid(validFormats).required();

module.exports = {
Expand Down
74 changes: 74 additions & 0 deletions lib/impl/jacoco.js
@@ -0,0 +1,74 @@
(function (jacocoParse, Promise, Joi, logger, util, path) {
'use strict';

var jacocoStringValidation = Joi.string().required();
var optionsValidation = Joi.object().keys().optional();

module.exports = {
parse: function parseJacoco(pathPrefix, jacocoString, options) {
return new Promise(function (resolve, reject) {
logger.debug('Parsing Jacoco Data');
var nonEmptyReport = Joi.validate(jacocoString, jacocoStringValidation);
var validOptions = Joi.validate(options, optionsValidation, {
stripUnknown: true
});
var validationError = nonEmptyReport.error || validOptions.error;

if (validationError) {
logger.error(validationError);
return reject(validationError);
}

jacocoParse.parseContent(jacocoString, function (err, data) {
if (err) {
err = new Error('Failed to parse jacoco report: ' + err);

logger.error(err);
return reject(err);
}

var result = {
total: 0,
fileReports: []
};
var totalLines = 0;
var totalHits = 0;

//TODO: Convert to reduce function
data.forEach(function (stats) {
var fileStats = {
// The API expects the filenames to be relative to the project, ex. lib/reporter.js
filename: stats.file ? pathPrefix + path.relative(process.cwd(), stats.file) : '',
coverage: {}
};

totalLines += stats.lines.found;
totalHits += stats.lines.hit;

// The API uses integers only, so convert accordingly.
fileStats.total = Math.floor(util.safeDivision(stats.lines.hit, stats.lines.found) * 100);

//TODO: Convert to reduce function
stats.lines.details.forEach(function (detail) {
// Codacy needs the 0s to know failed coverage data
// We also can't have a negative number of hits on a line, so exclude those.
if (detail.hit >= 0) {
fileStats.coverage[detail.line] = detail.hit;
}
});

logger.trace('Successfully parsed ' + stats.file);
result.fileReports.push(fileStats);
});

// The API uses integers only, so convert accordingly.
result.total = Math.floor(util.safeDivision(totalHits, totalLines) * 100);

logger.debug('Successfully Parsed Jacoco Data');

resolve(result);
});
});
}
};
}(require('jacoco-parse'), require('bluebird'), require('joi'), require('../logger')(), require('../util'), require('path')));
3 changes: 2 additions & 1 deletion lib/reporter.js
Expand Up @@ -23,7 +23,8 @@
jsx: 'javascript',
ts: 'typescript',
tsx: 'typescript',
coffee: 'coffeescript'
coffee: 'coffeescript',
java: 'java'
};

function sendByLanguage(endpoint, commitId, token, data, accountToken, username, projectName) {
Expand Down

0 comments on commit bf8435a

Please sign in to comment.