diff options
| author | cainus <[email protected]> | 2013-03-27 23:48:04 -0700 |
|---|---|---|
| committer | cainus <[email protected]> | 2013-03-27 23:48:04 -0700 |
| commit | 112119e43cb048cfa0dbd98d6e03833b8ca4b619 (patch) | |
| tree | 1bdb90068b87229dfa04a7a217e907d856ed0981 /lib/convertLcovToCoveralls.js | |
| parent | 86f733351d4e920a44e9682f105034628f6b0b4d (diff) | |
| download | node-coveralls-112119e43cb048cfa0dbd98d6e03833b8ca4b619.tar.xz node-coveralls-112119e43cb048cfa0dbd98d6e03833b8ca4b619.zip | |
changed to use lcov input format only.
Diffstat (limited to 'lib/convertLcovToCoveralls.js')
| -rw-r--r-- | lib/convertLcovToCoveralls.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js new file mode 100644 index 0000000..cd3ee6d --- /dev/null +++ b/lib/convertLcovToCoveralls.js @@ -0,0 +1,90 @@ +var TRAVIS_JOB_ID = process.env.TRAVIS_JOB_ID || 'unknown'; +var fs = require('fs'); +var lcovParse = require('./parser'); + +var detailsToCoverage = function(length, details){ + var coverage = new Array(length); + details.forEach(function(obj){ + coverage[obj.line] = obj.hit; + }); + return coverage; +}; + +var convertLcovFileObject = function(file, filepath){ + var path = filepath + "/" + file.file; + var source = fs.readFileSync(path, 'utf8'); + var lines = source.split("\n"); + var coverage = detailsToCoverage(lines.length, file.lines.details); + return { name : file.file, + source : source, + coverage : coverage }; +}; + +var convertLcovToCoveralls = function(input, filepath){ + filepath = filepath || 'lib'; + if (filepath[0] !== '/'){ + filepath = process.cwd() + '/' + filepath; + } + var parsed = lcovParse(input); + var postJson = { + service_job_id : TRAVIS_JOB_ID, + service_name : "travis-ci", + source_files : [] + }; + parsed.forEach(function(file){ + postJson.source_files.push(convertLcovFileObject(file, filepath)); + }); + return postJson; +}; + +module.exports = convertLcovToCoveralls; + +/* example coveralls json file + + +{ + "service_job_id": "1234567890", + "service_name": "travis-ci", + "source_files": [ + { + "name": "example.rb", + "source": "def four\n 4\nend", + "coverage": [null, 1, null] + }, + { + "name": "two.rb", + "source": "def seven\n eight\n nine\nend", + "coverage": [null, 1, 0, null] + } + ] +} + + +example output from lcov parser: + + [ + { + "file": "index.js", + "lines": { + "found": 0, + "hit": 0, + "details": [ + { + "line": 1, + "hit": 1 + }, + { + "line": 2, + "hit": 1 + }, + { + "line": 3, + "hit": 1 + }, + { + "line": 5, + "hit": 1 + }, + +*/ + |
