diff options
| author | Patrick Gansterer <[email protected]> | 2014-01-26 19:02:34 +0100 |
|---|---|---|
| committer | Patrick Gansterer <[email protected]> | 2014-01-26 19:24:59 +0100 |
| commit | e0b5ccc5de04f1c8d2e06ff62ece865cfd597e75 (patch) | |
| tree | a0c6c98f1572121b663d834f4ab335c035402253 /test | |
| parent | cbfe6bcad8db471d712c4e7fac6e293bb9688608 (diff) | |
| download | node-coveralls-e0b5ccc5de04f1c8d2e06ff62ece865cfd597e75.tar.xz node-coveralls-e0b5ccc5de04f1c8d2e06ff62ece865cfd597e75.zip | |
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.
Diffstat (limited to 'test')
| -rw-r--r-- | test/handleInput.js | 71 |
1 files changed, 47 insertions, 24 deletions
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(); + }); }); }); |
