diff options
| author | Gregg Caines <[email protected]> | 2014-03-17 18:37:31 -0700 |
|---|---|---|
| committer | Gregg Caines <[email protected]> | 2014-03-17 18:37:31 -0700 |
| commit | 15747afc13f515caaf818b6243672bd11dbeb126 (patch) | |
| tree | 6724611a8c7361f601693c488c88eb9f33ba4c22 | |
| parent | 26581f2eeec2635c713ae6a438cce81bff458e4b (diff) | |
| parent | 91771c4ff7703fcc79a5066333678137a351f6d0 (diff) | |
| download | node-coveralls-15747afc13f515caaf818b6243672bd11dbeb126.tar.xz node-coveralls-15747afc13f515caaf818b6243672bd11dbeb126.zip | |
Merge branch 'master' of github.com:cainus/node-coveralls
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | lib/convertLcovToCoveralls.js | 5 | ||||
| -rw-r--r-- | test/convertLcovToCoveralls.js | 38 |
3 files changed, 36 insertions, 9 deletions
@@ -7,7 +7,7 @@ Status](https://drone.io/github.com/cainus/node-coveralls/status.png)](https://d [Coveralls.io](https://coveralls.io/) support for node.js. Get the great coverage reporting of coveralls.io and add a cool coverage button ( like the one above ) to your README. -Supported CI services: [travis-ci](https://travis-ci.org/), [codeship](https://www.codeship.io/), [circle-ci](https://circleci.com/), [jenkins](http://jenkins-ci.org/), [drone](https://drone.io/) +Supported CI services: [travis-ci](https://travis-ci.org/), [codeship](https://www.codeship.io/), [circle-ci](https://circleci.com/), [jenkins](http://jenkins-ci.org/) ##Installation: Add the latest version of `coveralls` to your package.json: diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js index b73863a..11c87b6 100644 --- a/lib/convertLcovToCoveralls.js +++ b/lib/convertLcovToCoveralls.js @@ -13,11 +13,12 @@ var detailsToCoverage = function(length, details){ }; var convertLcovFileObject = function(file, filepath){ - filepath = path.resolve(filepath, file.file); + var rootpath = filepath; + filepath = path.resolve(rootpath, file.file); var source = fs.readFileSync(filepath, 'utf8'); var lines = source.split("\n"); var coverage = detailsToCoverage(lines.length, file.lines.details); - return { name : file.file, + return { name : path.relative(rootpath, path.resolve(rootpath, file.file)), source : source, coverage : coverage }; }; diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js index 2e07a87..0e3b9da 100644 --- a/test/convertLcovToCoveralls.js +++ b/test/convertLcovToCoveralls.js @@ -3,13 +3,14 @@ var getOptions = require('../index').getOptions; var should = require('should'); var fs = require('fs'); var logger = require('../lib/logger'); +var path = require('path'); logger = require('log-driver')({level : false}); describe("convertLcovToCoveralls", function(){ it ("should convert a simple lcov file", function(done){ process.env.TRAVIS_JOB_ID = -1; - var path = __dirname + "/../fixtures/onefile.lcov"; - var input = fs.readFileSync(path, "utf8"); + var lcovpath = __dirname + "/../fixtures/onefile.lcov"; + var input = fs.readFileSync(lcovpath, "utf8"); var libpath = __dirname + "/../fixtures/lib"; convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){ should.not.exist(err); @@ -30,8 +31,8 @@ describe("convertLcovToCoveralls", function(){ process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN"; getOptions(function(err, options){ - var path = __dirname + "/../fixtures/onefile.lcov"; - var input = fs.readFileSync(path, "utf8"); + var lcovpath = __dirname + "/../fixtures/onefile.lcov"; + var input = fs.readFileSync(lcovpath, "utf8"); var libpath = "fixtures/lib"; options.filepath = libpath; convertLcovToCoveralls(input, options, function(err, output){ @@ -43,8 +44,8 @@ describe("convertLcovToCoveralls", function(){ }); it ("should work with a relative path as well", function(done){ process.env.TRAVIS_JOB_ID = -1; - var path = __dirname + "/../fixtures/onefile.lcov"; - var input = fs.readFileSync(path, "utf8"); + var lcovpath = __dirname + "/../fixtures/onefile.lcov"; + var input = fs.readFileSync(lcovpath, "utf8"); var libpath = "fixtures/lib"; convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){ should.not.exist(err); @@ -53,4 +54,29 @@ describe("convertLcovToCoveralls", function(){ done(); }); }); + + it ("should convert absolute input paths to relative", function(done){ + process.env.TRAVIS_JOB_ID = -1; + var lcovpath = __dirname + "/../fixtures/istanbul.lcov"; + var input = fs.readFileSync(lcovpath, "utf8"); + var libpath = "/Users/deepsweet/Dropbox/projects/svgo/lib"; + var sourcepath = path.resolve(libpath, "svgo/config.js"); + + var originalReadFileSync = fs.readFileSync; + fs.readFileSync = function(filepath) { + if (filepath === sourcepath) { + return ''; + } + + return originalReadFileSync.apply(fs, arguments); + } + + convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){ + fs.readFileSync = originalReadFileSync; + + should.not.exist(err); + output.source_files[0].name.should.equal(path.join("svgo", "config.js")); + done(); + }); + }); }); |
