[Pkg-javascript-commits] [node-coveralls] 37/332: Fixes 7: be quiet by default

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:53:37 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 6187392ca1c1bfcbb4d8ced51de35ed2a04bc8a3
Author: Arpad Borsos <arpad.borsos at googlemail.com>
Date:   Sun Jun 2 14:20:12 2013 +0200

    Fixes 7: be quiet by default
---
 bin/coveralls.js               | 14 +++++++++++++-
 lib/convertLcovToCoveralls.js  | 12 +++++++-----
 lib/handleInput.js             | 22 ++++++++++------------
 test/convertLcovToCoveralls.js |  4 ++--
 4 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/bin/coveralls.js b/bin/coveralls.js
index 698f177..6f3eb57 100755
--- a/bin/coveralls.js
+++ b/bin/coveralls.js
@@ -1,6 +1,18 @@
 #!/usr/bin/env node
 var handleInput = require('../lib/handleInput');
 
+var options = {};
+if (process.argv[2]) {
+  if (~['-v', '--verbose'].indexOf(process.argv[2])) {
+    options.verbose = true;
+    if (process.argv[3]) {
+      options.filepath = process.argv[3];
+    }
+  } else {
+    options.filepath = process.argv[2];
+  }
+}
+
 process.stdin.resume();
 process.stdin.setEncoding('utf8');
 
@@ -11,6 +23,6 @@ process.stdin.on('data', function(chunk) {
 });
 
 process.stdin.on('end', function() {
-    handleInput(input);
+    handleInput(input, options);
 });
 
diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js
index 4657f10..6290d0c 100644
--- a/lib/convertLcovToCoveralls.js
+++ b/lib/convertLcovToCoveralls.js
@@ -25,15 +25,17 @@ var convertLcovFileObject = function(file, filepath){
            coverage : coverage	};
 };
 
-var convertLcovToCoveralls = function(input, filepath, repo_token, cb){
-  console.log("in: ", filepath);
+var convertLcovToCoveralls = function(input, options, cb){
+  var repo_token = options.repo_token,
+      filepath = options.filepath || '';
+  options.verbose && console.log("in: ", filepath);
   if (filepath[0] !== '/'){
     filepath = path.join(process.cwd(), filepath);
   }
   lcovParse(input, function(err, parsed){
-    if (err){  
-      console.log("error from lcovParse: ", err);
-      console.log("input: ", input);
+    if (err){
+      console.error("error from lcovParse: ", err);
+      console.error("input: ", input);
       return cb(err); 
     }
     var postJson = {
diff --git a/lib/handleInput.js b/lib/handleInput.js
index d081e94..be85c4a 100644
--- a/lib/handleInput.js
+++ b/lib/handleInput.js
@@ -3,31 +3,29 @@ var path = require('path');
 var YAML = require('libyaml');
 var sendToCoveralls = require('../index').sendToCoveralls;
 var convertLcovToCoveralls = require('../index').convertLcovToCoveralls;
-var repo_token;
 
-var handleInput = function(input){
-  console.log(input);
-  var libDir = process.argv[2] || '';
+var handleInput = function(input, options){
+  options.verbose && console.log(input);
 
   if (process.env.COVERALLS_REPO_TOKEN) {
-    repo_token = process.env.COVERALLS_REPO_TOKEN;
+    options.repo_token = process.env.COVERALLS_REPO_TOKEN;
   } else {
     var yml = path.join(process.cwd(), '.coveralls.yml');
     try {
       if (fs.statSync(yml).isFile()) {
-        repo_token = YAML.readFileSync(yml)[0].repo_token;
+        options.repo_token = YAML.readFileSync(yml)[0].repo_token;
       }
     } catch(ex){
-      console.log("Repo token could not be determined.  Continuing without it.");
+      console.warn("Repo token could not be determined.  Continuing without it.");
     }
   }
 
-  convertLcovToCoveralls(input, libDir, repo_token, function(err, postData){
+  convertLcovToCoveralls(input, options, function(err, postData){
     if (err){
-      console.log("error from convertLcovToCoveralls");
+      console.error("error from convertLcovToCoveralls");
       throw err;
     }
-    console.log("sending this to coveralls.io: ", postData);
+    options.verbose && console.info("sending this to coveralls.io: ", postData);
     sendToCoveralls(postData, function(err, response, body){
       if (err){
         throw err;
@@ -35,8 +33,8 @@ var handleInput = function(input){
       if (response.statusCode >= 400){
         throw "Bad response: " + response.statusCode + " " + body;
       }
-      console.log(response.statusCode);
-      console.log(body);
+      options.verbose && console.log(response.statusCode);
+      options.verbose && console.log(body);
     });
   });
 
diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js
index 9094631..5483dc7 100644
--- a/test/convertLcovToCoveralls.js
+++ b/test/convertLcovToCoveralls.js
@@ -8,7 +8,7 @@ describe("convertLcovToCoveralls", function(){
     var path = __dirname + "/../fixtures/onefile.lcov";
     var input = fs.readFileSync(path, "utf8");
     var libpath = __dirname + "/../fixtures/lib";
-    convertLcovToCoveralls(input, libpath, null, function(err, output){
+    convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
       should.not.exist(err);
       output.source_files[0].name.should.equal("index.js");
       output.source_files[0].source.split("\n").length.should.equal(225);
@@ -22,7 +22,7 @@ describe("convertLcovToCoveralls", function(){
     var path = __dirname + "/../fixtures/onefile.lcov";
     var input = fs.readFileSync(path, "utf8");
     var libpath = "fixtures/lib";
-    convertLcovToCoveralls(input, libpath, null, function(err, output){
+    convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
       should.not.exist(err);
       output.source_files[0].name.should.equal("index.js");
       output.source_files[0].source.split("\n").length.should.equal(225);

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