UNPKG

2.61 kBJavaScriptView Raw
1var should = require('should');
2var sinon = require('sinon-restore');
3var index = require('../index');
4var fs = require('fs');
5logger = require('log-driver')({level : false});
6
7describe("handleInput", function(){
8 afterEach(function() {
9 sinon.restoreAll();
10 });
11 it ("returns an error when there's an error getting options", function(done){
12 sinon.stub(index, 'getOptions', function(cb){
13 return cb("some error", {});
14 });
15 var path = __dirname + "/../fixtures/onefile.lcov";
16 var input = fs.readFileSync(path, "utf8");
17 index.handleInput(input, function(err){
18 err.should.equal("some error");
19 done();
20 });
21 });
22 it ("returns an error when there's an error converting", function(done){
23 sinon.stub(index, 'getOptions', function(cb){
24 return cb(null, {});
25 });
26 sinon.stub(index, 'convertLcovToCoveralls', function(input, options, cb){
27 cb("some error");
28 });
29 var path = __dirname + "/../fixtures/onefile.lcov";
30 var input = fs.readFileSync(path, "utf8");
31 index.handleInput(input, function(err){
32 err.should.equal("some error");
33 done();
34 });
35 });
36 it ("returns an error when there's an error sending", function(done){
37 sinon.stub(index, 'getOptions', function(cb){
38 return cb(null, {});
39 });
40 sinon.stub(index, 'sendToCoveralls', function(postData, cb){
41 cb("some error");
42 });
43 var path = __dirname + "/../fixtures/onefile.lcov";
44 var input = fs.readFileSync(path, "utf8");
45 index.handleInput(input, function(err){
46 err.should.equal("some error");
47 done();
48 });
49 });
50 it ("returns an error when there's a bad status code", function(done){
51 sinon.stub(index, 'getOptions', function(cb){
52 return cb(null, {});
53 });
54 sinon.stub(index, 'sendToCoveralls', function(postData, cb){
55 cb(null, {statusCode : 500}, "body");
56 });
57 var path = __dirname + "/../fixtures/onefile.lcov";
58 var input = fs.readFileSync(path, "utf8");
59 index.handleInput(input, function(err){
60 err.should.equal("Bad response: 500 body");
61 done();
62 });
63 });
64 it ("completes successfully when there are no errors", function(done){
65 sinon.stub(index, 'getOptions', function(cb){
66 return cb(null, {});
67 });
68 sinon.stub(index, 'sendToCoveralls', function(postData, cb){
69 cb(null, {statusCode : 200}, "body");
70 });
71 var path = __dirname + "/../fixtures/onefile.lcov";
72 var input = fs.readFileSync(path, "utf8");
73 index.handleInput(input, function(err){
74 (err === null).should.equal(true);
75 done();
76 });
77 });
78});