[Pkg-javascript-commits] [node-coveralls] 149/332: convertLcovToCoveralls should convert absolute source paths to relative paths in output.

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:53:53 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-coveralls.

commit 913039d9323c94467c853cac985455d5941c454f
Author: Marc Knaup <marc.knaup at koeln.de>
Date:   Fri Mar 14 12:02:02 2014 +0100

    convertLcovToCoveralls should convert absolute source paths to relative paths in output.
---
 lib/convertLcovToCoveralls.js  |  5 +++--
 test/convertLcovToCoveralls.js | 38 ++++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 8 deletions(-)

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();
+    });
+  });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-coveralls.git



More information about the Pkg-javascript-commits mailing list