[Pkg-javascript-commits] [node-coveralls] 129/332: Add callback to handleInput() for easier use in other projects

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:53:50 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 e0b5ccc5de04f1c8d2e06ff62ece865cfd597e75
Author: Patrick Gansterer <paroga at paroga.com>
Date:   Sun Jan 26 19:02:34 2014 +0100

    Add callback to handleInput() for easier use in other projects
    
    Since handleInput works completely asynchronous it is necessary to
    provide a callback function for signaling finished operation.
    This allows other project to call the handleInput function.
---
 bin/coveralls.js    |  6 ++++-
 lib/handleInput.js  | 15 +++++++----
 test/handleInput.js | 71 +++++++++++++++++++++++++++++++++++------------------
 3 files changed, 62 insertions(+), 30 deletions(-)

diff --git a/bin/coveralls.js b/bin/coveralls.js
index b003b15..324ec6d 100755
--- a/bin/coveralls.js
+++ b/bin/coveralls.js
@@ -13,6 +13,10 @@ process.stdin.on('data', function(chunk) {
 });
 
 process.stdin.on('end', function() {
-    handleInput(input);
+    handleInput(input, function(err) {
+      if (err) {
+        throw err;
+      }
+    });
 });
 
diff --git a/lib/handleInput.js b/lib/handleInput.js
index 807e31d..5f88394 100644
--- a/lib/handleInput.js
+++ b/lib/handleInput.js
@@ -1,31 +1,36 @@
 var index = require('../index');
 var logger = require('./logger')();
 
-function handleInput(input) {
+function handleInput(input, cb) {
   logger.debug(input);
 	var options = index.getOptions(function(err, options){
 
     if (err){
       logger.error("error from getOptions");
-      throw err;
+      cb(err);
+      return;
     }
     logger.debug(options);
 
     index.convertLcovToCoveralls(input, options, function(err, postData){
       if (err){
         logger.error("error from convertLcovToCoveralls");
-        throw err;
+        cb(err);
+        return;
       }
       logger.info("sending this to coveralls.io: ", JSON.stringify(postData));
       index.sendToCoveralls(postData, function(err, response, body){
         if (err){
-          throw err;
+          cb(err);
+          return;
         }
         if (response.statusCode >= 400){
-          throw "Bad response: " + response.statusCode + " " + body;
+          cb("Bad response: " + response.statusCode + " " + body);
+          return;
         }
         logger.debug(response.statusCode);
         logger.debug(body);
+        cb(null);
       });
     });
   });
diff --git a/test/handleInput.js b/test/handleInput.js
index f06e8a4..dc88902 100644
--- a/test/handleInput.js
+++ b/test/handleInput.js
@@ -8,48 +8,71 @@ describe("handleInput", function(){
    afterEach(function() {
         sinon.restoreAll();
       });
-  it ("throws an error when there's an error sending", function(done){
+  it ("returns an error when there's an error getting options", function(done){
+    sinon.stub(index, 'getOptions', function(cb){
+      return cb("some error", {}); 
+    });
+    var path = __dirname + "/../fixtures/onefile.lcov";
+    var input = fs.readFileSync(path, "utf8");
+    index.handleInput(input, function(err){
+      err.should.equal("some error");
+      done();
+    });
+  });
+  it ("returns an error when there's an error converting", function(done){
+    sinon.stub(index, 'getOptions', function(cb){
+      return cb(null, {}); 
+    });
+    sinon.stub(index, 'convertLcovToCoveralls', function(input, options, cb){
+      cb("some error");
+    });
+    var path = __dirname + "/../fixtures/onefile.lcov";
+    var input = fs.readFileSync(path, "utf8");
+    index.handleInput(input, function(err){
+      err.should.equal("some error");
+      done();
+    });
+  });
+  it ("returns an error when there's an error sending", function(done){
     sinon.stub(index, 'getOptions', function(cb){
       return cb(null, {}); 
     });
     sinon.stub(index, 'sendToCoveralls', function(postData, cb){
-      try {
-        cb("some error");
-        should.fail("expected exception was not raised");
-      } catch (ex) {
-        done();
-      }
-    });
-		var path = __dirname + "/../fixtures/onefile.lcov";
+      cb("some error");
+    });
+    var path = __dirname + "/../fixtures/onefile.lcov";
     var input = fs.readFileSync(path, "utf8");
-		index.handleInput(input);
+    index.handleInput(input, function(err){
+      err.should.equal("some error");
+      done();
+    });
   });
-  it ("throws an error when there's a bad status code", function(done){
+  it ("returns an error when there's a bad status code", function(done){
     sinon.stub(index, 'getOptions', function(cb){
       return cb(null, {}); 
     });
     sinon.stub(index, 'sendToCoveralls', function(postData, cb){
-      try {
-        cb(null, {statusCode : 500}, "body");
-        should.fail("expected exception was not raised");
-      } catch (ex) {
-        done();
-      }
-    });
-		var path = __dirname + "/../fixtures/onefile.lcov";
+      cb(null, {statusCode : 500}, "body");
+    });
+    var path = __dirname + "/../fixtures/onefile.lcov";
     var input = fs.readFileSync(path, "utf8");
-		index.handleInput(input);
+    index.handleInput(input, function(err){
+      err.should.equal("Bad response: 500 body");
+      done();
+    });
   });
-  it ("completes successfully when there are now errors", function(done){
+  it ("completes successfully when there are no errors", function(done){
     sinon.stub(index, 'getOptions', function(cb){
       return cb(null, {}); 
     });
     sinon.stub(index, 'sendToCoveralls', function(postData, cb){
       cb(null, {statusCode : 200}, "body");
-      done();
     });
-		var path = __dirname + "/../fixtures/onefile.lcov";
+    var path = __dirname + "/../fixtures/onefile.lcov";
     var input = fs.readFileSync(path, "utf8");
-		index.handleInput(input);
+    index.handleInput(input, function(err){
+      (err === null).should.equal(true);
+      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