/
handleInput.js
74 lines (71 loc) · 2.58 KB
/
handleInput.js
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
'use strict';
const fs = require('fs');
const sysPath = require('path');
const should = require('should');
const sinon = require('sinon').sandbox.create();
const logDriver = require('log-driver');
const index = require('..');
logDriver({ level: false });
describe('handleInput', () => {
afterEach(() => {
sinon.restore();
});
it('returns an error when there\'s an error getting options', done => {
sinon.stub(index, 'getOptions').callsFake(cb => cb('some error', {}));
const path = sysPath.join(__dirname, './fixtures/onefile.lcov');
const input = fs.readFileSync(path, 'utf8');
index.handleInput(input, err => {
err.should.equal('some error');
done();
});
});
it('returns an error when there\'s an error converting', done => {
sinon.stub(index, 'getOptions').callsFake(cb => cb(null, {}));
sinon.stub(index, 'convertLcovToCoveralls').callsFake((input, options, cb) => {
cb('some error');
});
const path = sysPath.join(__dirname, './fixtures/onefile.lcov');
const input = fs.readFileSync(path, 'utf8');
index.handleInput(input, err => {
err.should.equal('some error');
done();
});
});
it('returns an error when there\'s an error sending', done => {
sinon.stub(index, 'getOptions').callsFake(cb => cb(null, {}));
sinon.stub(index, 'sendToCoveralls').callsFake((postData, cb) => {
cb('some error');
});
const path = sysPath.join(__dirname, './fixtures/onefile.lcov');
const input = fs.readFileSync(path, 'utf8');
index.handleInput(input, err => {
err.should.equal('some error');
done();
});
});
it('returns an error when there\'s a bad status code', done => {
sinon.stub(index, 'getOptions').callsFake(cb => cb(null, {}));
sinon.stub(index, 'sendToCoveralls').callsFake((postData, cb) => {
cb(null, { statusCode: 500 }, 'body');
});
const path = sysPath.join(__dirname, './fixtures/onefile.lcov');
const input = fs.readFileSync(path, 'utf8');
index.handleInput(input, err => {
err.should.equal('Bad response: 500 body');
done();
});
});
it('completes successfully when there are no errors', done => {
sinon.stub(index, 'getOptions').callsFake(cb => cb(null, {}));
sinon.stub(index, 'sendToCoveralls').callsFake((postData, cb) => {
cb(null, { statusCode: 200 }, 'body');
});
const path = sysPath.join(__dirname, './fixtures/onefile.lcov');
const input = fs.readFileSync(path, 'utf8');
index.handleInput(input, (err, body) => {
should.not.exist(err);
body.should.equal('body');
done();
});
});
});