diff options
| author | cainus <[email protected]> | 2013-06-08 11:38:13 -0700 |
|---|---|---|
| committer | cainus <[email protected]> | 2013-06-08 11:38:13 -0700 |
| commit | 45738a0b1851bdf161c6508f52e9c51cf776172d (patch) | |
| tree | 3ac1c9f34d6ab6ea6098c5cb76a0a22c0fa48c99 | |
| parent | 85a98465ec1f777bd55f99ab276ce526a487b9cd (diff) | |
| download | node-coveralls-45738a0b1851bdf161c6508f52e9c51cf776172d.tar.xz node-coveralls-45738a0b1851bdf161c6508f52e9c51cf776172d.zip | |
add some tests. version bump to 2.0.13.
| -rw-r--r-- | lib/handleInput.js | 10 | ||||
| -rw-r--r-- | lib/sendToCoveralls.js | 2 | ||||
| -rw-r--r-- | package.json | 5 | ||||
| -rw-r--r-- | test/getOptions.js | 17 | ||||
| -rw-r--r-- | test/handleInput.js | 55 | ||||
| -rw-r--r-- | test/sendToCoveralls.js | 27 |
6 files changed, 107 insertions, 9 deletions
diff --git a/lib/handleInput.js b/lib/handleInput.js index a354efa..0ea17a9 100644 --- a/lib/handleInput.js +++ b/lib/handleInput.js @@ -1,20 +1,18 @@ -var sendToCoveralls = require('../index').sendToCoveralls; -var convertLcovToCoveralls = require('../index').convertLcovToCoveralls; +var index = require('../index'); var logger = require('./logger'); -var getOptions = require('../index').getOptions; var handleInput = function(input){ logger.debug(input); - var options = getOptions(); + var options = index.getOptions(); logger.debug(options); - convertLcovToCoveralls(input, options, function(err, postData){ + index.convertLcovToCoveralls(input, options, function(err, postData){ if (err){ logger.error("error from convertLcovToCoveralls"); throw err; } logger.info("sending this to coveralls.io: ", JSON.stringify(postData)); - sendToCoveralls(postData, function(err, response, body){ + index.sendToCoveralls(postData, function(err, response, body){ if (err){ throw err; } diff --git a/lib/sendToCoveralls.js b/lib/sendToCoveralls.js index b3514c6..10e614d 100644 --- a/lib/sendToCoveralls.js +++ b/lib/sendToCoveralls.js @@ -3,7 +3,7 @@ var request = require('request'); var sendToCoveralls = function(obj, cb){ var str = JSON.stringify(obj); var url = 'https://coveralls.io/api/v1/jobs'; - request({url : url, method : 'POST', form : { json : str}}, function(err, response, body){ + request.post({url : url, form : { json : str}}, function(err, response, body){ cb(err, response, body); }); }; diff --git a/package.json b/package.json index f17edbb..bd917cf 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "coverage", "coveralls" ], - "version": "2.0.12", + "version": "2.0.13", "bugs": { "url": "https://github.com/cainus/node-coveralls/issues" }, @@ -22,7 +22,7 @@ "Alan Gutierrez <[email protected]> (http://www.prettyrobots.com/)", "Kir Belevich (https://github.com/svg)", "elliotcable <[email protected]> (http://elliottcable.name/)", - "Arpad Borsos <[email protected]> (http://swatinem.de/)" + "Arpad Borsos <[email protected]> (http://swatinem.de/)" ], "dependencies": { "yaml": "0.2.3", @@ -31,6 +31,7 @@ "log-driver": "1.2.1" }, "devDependencies": { + "sinon-restore": "1.0.0", "mocha-lcov-reporter": "0.0.1", "mocha": "1.8.1", "should": "1.1.0", diff --git a/test/getOptions.js b/test/getOptions.js new file mode 100644 index 0000000..e8e3c7a --- /dev/null +++ b/test/getOptions.js @@ -0,0 +1,17 @@ +var should = require('should'); +var getOptions = require('../index').getOptions; + +describe("getOptions", function(){ + it ("should get a filepath if there is one", function(){ + process.argv[2] = "somepath"; + getOptions().filepath.should.equal("somepath"); + + }); + it ("should get a filepath if there is one, even in verbose mode", function(){ + process.argv[2] = "--verbose"; + process.argv[3] = "somepath"; + getOptions().filepath.should.equal("somepath"); + + }); + +}); diff --git a/test/handleInput.js b/test/handleInput.js new file mode 100644 index 0000000..45f0482 --- /dev/null +++ b/test/handleInput.js @@ -0,0 +1,55 @@ +var should = require('should'); +var sinon = require('sinon-restore'); +var index = require('../index'); +var fs = require('fs'); +logger = require('log-driver')({level : false}); + +describe("handleInput", function(){ + afterEach(function() { + sinon.restoreAll(); + }); + it ("throws an error when there's an error sending", function(done){ + sinon.stub(index, 'getOptions', function(){ + return {}; + }); + 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"; + var input = fs.readFileSync(path, "utf8"); + index.handleInput(input); + }); + it ("throws an error when there's a bad status code", function(done){ + sinon.stub(index, 'getOptions', function(){ + return {}; + }); + 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"; + var input = fs.readFileSync(path, "utf8"); + index.handleInput(input); + }); + it ("completes successfully when there are now errors", function(done){ + sinon.stub(index, 'getOptions', function(){ + return {}; + }); + sinon.stub(index, 'sendToCoveralls', function(postData, cb){ + cb(null, {statusCode : 200}, "body"); + done(); + }); + var path = __dirname + "/../fixtures/onefile.lcov"; + var input = fs.readFileSync(path, "utf8"); + index.handleInput(input); + }); +}); diff --git a/test/sendToCoveralls.js b/test/sendToCoveralls.js new file mode 100644 index 0000000..937df95 --- /dev/null +++ b/test/sendToCoveralls.js @@ -0,0 +1,27 @@ +var should = require('should'); +var request = require('request'); +var sinon = require('sinon-restore'); +var index = require('../index'); +logger = require('log-driver')({level : false}); + +describe("sendToCoveralls", function(){ + afterEach(function() { + sinon.restoreAll(); + }); + it ("passes on the correct params to request.post", function(done){ + sinon.stub(request, 'post', function(obj, cb){ + obj.url.should.equal('https://coveralls.io/api/v1/jobs'); + obj.form.should.eql({json : '{"some":"obj"}'}); + cb('err', 'response', 'body'); + }); + + var obj = {"some":"obj"}; + index.sendToCoveralls(obj, function(err, response, body){ + err.should.equal('err'); + response.should.equal('response'); + body.should.equal('body'); + done(); + + }); + }); +}); |
