1 | var should = require('should');
|
2 | var request = require('request');
|
3 | var sinon = require('sinon-restore');
|
4 | var index = require('../index');
|
5 | logger = require('log-driver')({level : false});
|
6 |
|
7 | describe("sendToCoveralls", function(){
|
8 | var realCoverallsHost;
|
9 | beforeEach(function() {
|
10 | realCoverallsHost = process.env.COVERALLS_ENDPOINT;
|
11 | });
|
12 |
|
13 | afterEach(function() {
|
14 | sinon.restoreAll();
|
15 | if (realCoverallsHost !== undefined) {
|
16 | process.env.COVERALLS_ENDPOINT = realCoverallsHost;
|
17 | } else {
|
18 | delete process.env.COVERALLS_ENDPOINT;
|
19 | }
|
20 | });
|
21 |
|
22 | it ("passes on the correct params to request.post", function(done){
|
23 | sinon.stub(request, 'post', function(obj, cb){
|
24 | obj.url.should.equal('https://coveralls.io/api/v1/jobs');
|
25 | obj.form.should.eql({json : '{"some":"obj"}'});
|
26 | cb('err', 'response', 'body');
|
27 | });
|
28 |
|
29 | var obj = {"some":"obj"};
|
30 |
|
31 | index.sendToCoveralls(obj, function(err, response, body){
|
32 | err.should.equal('err');
|
33 | response.should.equal('response');
|
34 | body.should.equal('body');
|
35 | done();
|
36 | });
|
37 | });
|
38 |
|
39 | it ("allows sending to enterprise url", function(done){
|
40 | process.env.COVERALLS_ENDPOINT = 'https://coveralls-ubuntu.domain.com';
|
41 | sinon.stub(request, 'post', function(obj, cb){
|
42 | obj.url.should.equal('https://coveralls-ubuntu.domain.com/api/v1/jobs');
|
43 | obj.form.should.eql({json : '{"some":"obj"}'});
|
44 | cb('err', 'response', 'body');
|
45 | });
|
46 |
|
47 | var obj = {"some":"obj"};
|
48 | index.sendToCoveralls(obj, function(err, response, body){
|
49 | err.should.equal('err');
|
50 | response.should.equal('response');
|
51 | body.should.equal('body');
|
52 | done();
|
53 | });
|
54 | });
|
55 | it ("writes output to stdout when --stdout is passed", function(done) {
|
56 | var obj = {"some":"obj"};
|
57 |
|
58 |
|
59 | var origStdoutWrite = process.stdout.write;
|
60 | process.stdout.write = function(string) {
|
61 | if (string == JSON.stringify(obj)) {
|
62 | process.stdout.write = origStdoutWrite;
|
63 | return done();
|
64 | }
|
65 |
|
66 | origStdoutWrite.apply(this, arguments);
|
67 | };
|
68 |
|
69 | index.options.stdout = true;
|
70 |
|
71 | index.sendToCoveralls(obj, function(err, response, body) {
|
72 | response.statusCode.should.equal(200);
|
73 | });
|
74 | });
|
75 | });
|