codacy-coverage
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -10,3 +10,3 @@ (function (parser, reporter, getGitData, logger, Promise, util) { | ||
var pathPrefix = opts.prefix || ''; | ||
var language = opts.language || 'javascript'; | ||
var language = opts.language; | ||
var loggerImpl; | ||
@@ -13,0 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
(function (request, Joi, Promise, util, logger) { | ||
(function(request, Joi, Promise, util, lodash, logger) { | ||
'use strict'; | ||
@@ -18,3 +18,92 @@ | ||
module.exports = function (options) { | ||
var languageMap = { | ||
js: 'javascript', | ||
jsx: 'javascript', | ||
ts: 'typescript', | ||
tsx: 'typescript', | ||
coffee: 'coffeescript' | ||
} | ||
function sendByLanguage(endpoint, commitId, token, data) { | ||
var reportsByLanguage = lodash.groupBy(data.fileReports, function(elem) { | ||
return languageMap[lodash.head(lodash.takeRight(elem.filename.split('.'), 1))] || 'javascript'; | ||
}); | ||
var languageResponses = lodash.map(reportsByLanguage, function(fileReports, language) { | ||
var weighedCoverage = lodash.reduce(fileReports, function(accom, elem) { | ||
return accom + (elem.total * Object.keys(elem.coverage).length); | ||
}, 0); | ||
var coveredLines = lodash.reduce(fileReports, function(accom, elem) { | ||
return accom + Object.keys(elem.coverage).length; | ||
}, 0); | ||
var finalCoverage = weighedCoverage / coveredLines; | ||
var dataPerLanguage = lodash.clone(data); | ||
dataPerLanguage.fileReports = fileReports; | ||
dataPerLanguage.total = Math.floor(finalCoverage); | ||
return sendLanguage(endpoint, commitId, language, token, dataPerLanguage); | ||
}); | ||
return Promise.all(languageResponses) | ||
.then(function(errs) { | ||
errs = lodash.filter(errs, function(e) { | ||
return !lodash.isUndefined(e) | ||
}); | ||
if (errs.length) { | ||
return Promise.reject(errs[0]); | ||
} | ||
logger.trace('All languages sent successfully'); | ||
return Promise.resolve(); | ||
}, function(err) { | ||
logger.trace('Failed to send some languages'); | ||
return Promise.reject(err); | ||
}); | ||
} | ||
function sendForLanguage(endpoint, commitId, language, token, data) { | ||
return sendLanguage(endpoint, commitId, language, token, data) | ||
.then(function(err) { | ||
if (err) { | ||
return Promise.reject(err); | ||
} | ||
return Promise.resolve(); | ||
}, function(err) { | ||
return Promise.reject(err); | ||
}); | ||
} | ||
function sendLanguage(endpoint, commitId, language, token, data) { | ||
var url = endpoint.replace(':commitId', commitId).replace(':language', language); | ||
logger.trace(util.format('Sending POST to %s', url)); | ||
return request({ | ||
url: url, | ||
method: 'POST', | ||
json: data, | ||
headers: { | ||
// jscs:disable | ||
project_token: token | ||
// jscs:enable | ||
}, | ||
resolveWithFullResponse: true | ||
}).then(function(res) { | ||
if (res.statusCode !== 200) { | ||
var err = new Error(util.format('Expected Status Code of 200, but got [%s]', res.statusCode)); | ||
logger.error(util.format('Status Code [%s] - Error [%j]', res.statusCode, res.error)); | ||
return Promise.reject(err); | ||
} | ||
logger.debug('Successfully sent coverage data'); | ||
return Promise.resolve(); | ||
}, function(res) { | ||
var err = new Error(util.format('Expected Successful Status Code, but got [%s]', res.statusCode)); | ||
logger.error(util.format('Status Code [%s] - Error [%j]', res.statusCode, res.error)); | ||
return Promise.reject(err); | ||
}); | ||
} | ||
module.exports = function(options) { | ||
logger.trace(util.format('Creating reporter for %j', options)); | ||
@@ -35,46 +124,23 @@ var optionsValid = Joi.validate(options, optionsValidation, { | ||
sendCoverage: function sendCoverage(token, commitId, language, data) { | ||
return new Promise(function (resolve, reject) { | ||
logger.trace(util.format('Sending Coverage for token [%s] and commitId [%s]', token, commitId)); | ||
var tokenValid = Joi.validate(token, tokenValidation); | ||
var commitIdValid = Joi.validate(commitId, commitIdValidation); | ||
var dataValid = Joi.validate(data, coverageDataValidation, { | ||
stripUnknown: true | ||
}); | ||
var validationErr = tokenValid.error || commitIdValid.error || dataValid.error; | ||
logger.trace(util.format('Sending Coverage for token [%s] and commitId [%s]', token, commitId)); | ||
var tokenValid = Joi.validate(token, tokenValidation); | ||
var commitIdValid = Joi.validate(commitId, commitIdValidation); | ||
var dataValid = Joi.validate(data, coverageDataValidation, { | ||
stripUnknown: true | ||
}); | ||
var validationErr = tokenValid.error || commitIdValid.error || dataValid.error; | ||
if (validationErr) { | ||
logger.error(validationErr); | ||
return reject(validationErr); | ||
} | ||
if (validationErr) { | ||
logger.error(validationErr); | ||
return Promise.reject(validationErr); | ||
} | ||
var url = endpoint.replace(':commitId', commitId).replace(':language', language); | ||
logger.trace(util.format('Sending POST to %s', url)); | ||
if (language) { | ||
return sendForLanguage(endpoint, commitId, language, token, data); | ||
} | ||
return request({ | ||
url: url, | ||
method: 'POST', | ||
json: data, | ||
headers: { | ||
// jscs:disable | ||
project_token: token | ||
// jscs:enable | ||
}, | ||
resolveWithFullResponse: true | ||
}).then(function (res) { | ||
if (res.statusCode !== 200) { | ||
var err = new Error(util.format('Expected Status Code of 200, but got [%s]', res.statusCode)); | ||
logger.error(util.format('Status Code [%s] - Error [%j]', res.statusCode, res.error)); | ||
return reject(err); | ||
} | ||
logger.debug('Successfully sent coverage data'); | ||
resolve(); | ||
}, function (res) { | ||
var err = new Error(util.format('Expected Successful Status Code, but got [%s]', res.statusCode)); | ||
logger.error(util.format('Status Code [%s] - Error [%j]', res.statusCode, res.error)); | ||
reject(err); | ||
}); | ||
}); | ||
return sendByLanguage(endpoint, commitId, token, data); | ||
} | ||
}; | ||
}; | ||
}(require('request-promise'), require('joi'), require('bluebird'), require('util'), require('./logger')())); | ||
}(require('request-promise'), require('joi'), require('bluebird'), require('util'), require('lodash'), require('./logger')())); |
{ | ||
"name": "codacy-coverage", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Code Coverage reporter for Codacy.com", | ||
@@ -35,2 +35,3 @@ "keywords": [ | ||
"lcov-parse": "0.x", | ||
"lodash": "^4.17.4", | ||
"log-driver": "^1.x", | ||
@@ -37,0 +38,0 @@ "request-promise": "^0.x" |
@@ -15,3 +15,3 @@ # Node Codacy Coverage | ||
##Installation: | ||
## Installation: | ||
Add the latest version of `codacy-coverage` to your package.json: | ||
@@ -27,3 +27,3 @@ ``` | ||
##Usage: | ||
## Usage: | ||
@@ -94,2 +94,7 @@ This script ( `bin/codacy-coverage.js` ) can take standard input from any tool that emits the lcov data format (including [mocha](http://mochajs.org)'s [LCov reporter](https://npmjs.org/package/mocha-lcov-reporter)) and send it to Codacy to report your code coverage there. | ||
### Custom Language (Typescript, Coffeescript) | ||
- Pass an extra parameter to the codacy-coverage reporter `--language typescript` or `--language coffeescript`. | ||
- If you have multiple language you need to invoke the reporter once for each of them. | ||
### Troubleshooting | ||
@@ -96,0 +101,0 @@ |
@@ -65,3 +65,3 @@ (function (exec, Joi, parser, helper) { | ||
expect(res).to.match(/Started with: token \["1234"], commitId \["4321"], language \[undefined], endpoint \["something"], format \["lcov"], path prefix \["asdf\/"], verbose \[true], debug \[true]/); | ||
expect(res).to.match(/Handling input for: token \["1234"], commitId \["4321"], language \["javascript"], endpoint \["something"], format \["lcov"], path prefix \["asdf\/"], verbose \[true], debug \[true]/); | ||
expect(res).to.match(/Handling input for: token \["1234"], commitId \["4321"], language \[undefined], endpoint \["something"], format \["lcov"], path prefix \["asdf\/"], verbose \[true], debug \[true]/); | ||
done(); | ||
@@ -68,0 +68,0 @@ }); |
@@ -17,3 +17,3 @@ (function (handleInput, helper, Joi, request, fs, path) { | ||
fileReports: Joi.array().items(Joi.object({ | ||
filename: Joi.string().valid('filename'), | ||
filename: Joi.string().valid('filename.js'), | ||
total: Joi.number().valid(10), | ||
@@ -31,3 +31,3 @@ coverage: Joi.object({ | ||
{ | ||
filename: 'filename', | ||
filename: 'filename.js', | ||
total: 10, | ||
@@ -34,0 +34,0 @@ coverage: { |
@@ -7,3 +7,2 @@ (function (fs, parser, helper, path) { | ||
var noStatsLcovData = fs.readFileSync(__dirname + '/mock/no-lines.info').toString(); | ||
var nadaLcovData = fs.readFileSync(__dirname + '/mock/nada.info').toString(); | ||
@@ -109,19 +108,3 @@ describe('Lcov Parser', function () { | ||
}); | ||
it('should be able to parse lcov data without anything', function () { | ||
return expect(parser.getParser('lcov').parse('', nadaLcovData)) | ||
.to.eventually.satisfy(function (data) { | ||
expect(JSON.stringify(data)).to.equal(JSON.stringify({ | ||
total: 0, | ||
fileReports: [ | ||
{ | ||
filename: '', | ||
coverage: {}, | ||
total: 0 | ||
} | ||
] | ||
})); | ||
return true; | ||
}); | ||
}); | ||
}); | ||
}(require('fs'), require('../lib/coverageParser'), require('./helper'), require('path'))); |
@@ -14,3 +14,3 @@ (function (Joi, request, reporter, helper) { | ||
fileReports: Joi.array().items(Joi.object({ | ||
filename: Joi.string().valid('filename'), | ||
filename: Joi.string().valid('filename.js'), | ||
total: Joi.number().valid(10), | ||
@@ -28,3 +28,3 @@ coverage: Joi.object({ | ||
{ | ||
filename: 'filename', | ||
filename: 'filename.js', | ||
total: 10, | ||
@@ -31,0 +31,0 @@ coverage: { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111855
1037
131
7
+ Addedlodash@^4.17.4
+ Addedlodash@4.17.21(transitive)