aboutsummaryrefslogtreecommitdiff
path: root/test/sendToCoveralls.js
blob: 6121bbb11de089577a1097b5be91672699b56b02 (plain)
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
var should = require('should');
var request = require('request');
var sinon = require('sinon-restore');
var index = require('../index');
logger = require('log-driver')({level : false});

describe("sendToCoveralls", function(){
  var realCoverallsHost;
  beforeEach(function() {
    realCoverallsHost = process.env.COVERALLS_ENDPOINT;
  });

  afterEach(function() {
    sinon.restoreAll();
    if (realCoverallsHost !== undefined) {
      process.env.COVERALLS_ENDPOINT = realCoverallsHost;
    } else {
      delete process.env.COVERALLS_ENDPOINT;
    }
  });

  it ("passes on the correct params to request.post", function(done){
    sinon.stub(request, 'post', function(obj, cb){
      obj.url.should.equal('https://coveralls.io/api/v1/jobs');
      obj.form.should.eql({json : '{"some":"obj"}'});
      cb('err', 'response', 'body');
    });

    var obj = {"some":"obj"};
    
    index.sendToCoveralls(obj, function(err, response, body){
      err.should.equal('err');
      response.should.equal('response');
      body.should.equal('body');
      done();
    });
  });

  it ("allows sending to enterprise url", function(done){
    process.env.COVERALLS_ENDPOINT = 'https://coveralls-ubuntu.domain.com';
    sinon.stub(request, 'post', function(obj, cb){
      obj.url.should.equal('https://coveralls-ubuntu.domain.com/api/v1/jobs');
      obj.form.should.eql({json : '{"some":"obj"}'});
      cb('err', 'response', 'body');
    });

    var obj = {"some":"obj"};
    index.sendToCoveralls(obj, function(err, response, body){
      err.should.equal('err');
      response.should.equal('response');
      body.should.equal('body');
      done();
    });
  });
  it ("writes output to stdout when --stdout is passed", function(done) {
    var obj = {"some":"obj"};
    
    // set up mock process.stdout.write temporarily
    var origStdoutWrite = process.stdout.write;
    process.stdout.write = function(string) {
      if (string == JSON.stringify(obj)) {
        process.stdout.write = origStdoutWrite;
        return done();
      }
      
      origStdoutWrite.apply(this, arguments);
    };
    
    index.options.stdout = true;
    
    index.sendToCoveralls(obj, function(err, response, body) {
      response.statusCode.should.equal(200);
    });
  });
});