[Pkg-javascript-commits] [node-coveralls] 293/332: branching WIP

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:54:13 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 15750503b69c3143b3020fa5d4fe4fc1d455356e
Author: Nick Merwin <n at mer.io>
Date:   Sun Feb 5 12:35:46 2017 -0800

    branching WIP
---
 lib/convertLcovToCoveralls.js  | 16 ++++++++++++++--
 package.json                   |  2 +-
 test/convertLcovToCoveralls.js | 29 +++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js
index 68687bd..521e749 100644
--- a/lib/convertLcovToCoveralls.js
+++ b/lib/convertLcovToCoveralls.js
@@ -12,22 +12,34 @@ var detailsToCoverage = function(length, details){
   return coverage;
 };
 
+var detailsToBranches = function(details){
+  var branches = [];
+  details.forEach(function(obj){
+    ['line','block','branch','taken'].forEach(function(key){
+      branches.push(obj[key] || 0);
+    });
+  });
+  return branches;
+};
+
 var convertLcovFileObject = function(file, filepath){
   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);
+  var branches = detailsToBranches(file.branches.details);
 	return { name     : path.relative(rootpath, path.resolve(rootpath, file.file)).split( path.sep ).join( "/" ),
            source   : source,
-           coverage : coverage	};
+           coverage : coverage,
+           branches : branches };
 };
 
 var cleanFilePath = function(file) {
   if (file.indexOf('!') > -1) {
     var regex = /^(.*!)(.*)$/g;
     var matches = regex.exec(file);
-    return matches[matches.length-1];  
+    return matches[matches.length-1];
   }
 
   return file;
diff --git a/package.json b/package.json
index 9777196..a8fa62d 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
     "coverage",
     "coveralls"
   ],
-  "version": "2.11.15",
+  "version": "2.12.0",
   "bugs": {
     "url": "https://github.com/nickmerwin/node-coveralls/issues"
   },
diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js
index 25a0e97..9a7789c 100644
--- a/test/convertLcovToCoveralls.js
+++ b/test/convertLcovToCoveralls.js
@@ -88,6 +88,35 @@ describe("convertLcovToCoveralls", function(){
     });
   });
 
+  it ("should handle branch coverage data", 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);
+    };
+
+    var originalExistsSync = fs.existsSync;
+    fs.existsSync = function () { return true; };
+
+    convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
+      fs.readFileSync = originalReadFileSync;
+      fs.existsSync = originalExistsSync;
+      
+      should.not.exist(err);
+      output.source_files[0].branches.slice(0,8).should.eql([18,1,0,85,18,1,1,2]);
+      done();
+    });
+  });
+
   it ("should ignore files that do not exists", function(done){
     process.env.TRAVIS_JOB_ID = -1;
     var lcovpath = __dirname + "/../fixtures/istanbul.lcov";

-- 
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