1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
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 ("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){
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 a bad status code", function(done){
sinon.stub(index, 'getOptions', function(cb){
return cb(null, {});
});
sinon.stub(index, 'sendToCoveralls', function(postData, cb){
cb(null, {statusCode : 500}, "body");
});
var path = __dirname + "/../fixtures/onefile.lcov";
var input = fs.readFileSync(path, "utf8");
index.handleInput(input, function(err){
err.should.equal("Bad response: 500 body");
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");
});
var path = __dirname + "/../fixtures/onefile.lcov";
var input = fs.readFileSync(path, "utf8");
index.handleInput(input, function(err){
(err === null).should.equal(true);
done();
});
});
});
|