Comparing version 2.6.1 to 2.7.0
@@ -16,4 +16,8 @@ #!/usr/bin/env node | ||
process.stdin.on('end', function() { | ||
handleInput(input); | ||
handleInput(input, function(err) { | ||
if (err) { | ||
throw err; | ||
} | ||
}); | ||
}); | ||
var index = require('../index'); | ||
var logger = require('./logger')(); | ||
function handleInput(input) { | ||
function handleInput(input, cb) { | ||
logger.debug(input); | ||
@@ -10,3 +10,4 @@ var options = index.getOptions(function(err, options){ | ||
logger.error("error from getOptions"); | ||
throw err; | ||
cb(err); | ||
return; | ||
} | ||
@@ -18,3 +19,4 @@ logger.debug(options); | ||
logger.error("error from convertLcovToCoveralls"); | ||
throw err; | ||
cb(err); | ||
return; | ||
} | ||
@@ -24,9 +26,12 @@ logger.info("sending this to coveralls.io: ", JSON.stringify(postData)); | ||
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); | ||
}); | ||
@@ -33,0 +38,0 @@ }); |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "2.6.1", | ||
"version": "2.7.0", | ||
"bugs": { | ||
@@ -11,0 +11,0 @@ "url": "https://github.com/cainus/node-coveralls/issues" |
@@ -11,19 +11,42 @@ var should = require('should'); | ||
}); | ||
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(); | ||
} | ||
cb("some error"); | ||
}); | ||
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.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){ | ||
@@ -33,14 +56,12 @@ 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(); | ||
} | ||
cb(null, {statusCode : 500}, "body"); | ||
}); | ||
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.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){ | ||
@@ -51,8 +72,10 @@ return cb(null, {}); | ||
cb(null, {statusCode : 200}, "body"); | ||
}); | ||
var path = __dirname + "/../fixtures/onefile.lcov"; | ||
var input = fs.readFileSync(path, "utf8"); | ||
index.handleInput(input, function(err){ | ||
(err === null).should.equal(true); | ||
done(); | ||
}); | ||
var path = __dirname + "/../fixtures/onefile.lcov"; | ||
var input = fs.readFileSync(path, "utf8"); | ||
index.handleInput(input); | ||
}); | ||
}); |
204941
6828