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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
var should = require('should');
var index = require('../index');
var getOptions = index.getOptions;
var getBaseOptions = index.getBaseOptions;
describe("getBaseOptions", function(){
beforeEach(function(){
process.env = {};
});
it ("should set service_job_id if it exists", function(done){
testServiceJobId(getBaseOptions, done);
});
it ("should set git hash if it exists", function(done){
testGitHash(getBaseOptions, done);
});
it ("should set git branch if it exists", function(done){
testGitBranch(getBaseOptions, done);
});
it ("should set repo_token if it exists", function(done){
testRepoToken(getBaseOptions, done);
});
it ("should set service_name if it exists", function(done){
testServiceName(getBaseOptions, done);
});
it ("should set service_name and service_job_id if it's running on travis-ci", function(done){
testTravisCi(getBaseOptions, done);
});
it ("should set service_name and service_job_id if it's running on jenkins", function(done){
testJenkins(getBaseOptions, done);
});
it ("should set service_name and service_job_id if it's running on circleci", function(done){
testCircleCi(getBaseOptions, done);
});
});
describe("getOptions", function(){
beforeEach(function(){
process.env = {};
});
it ("should get a filepath if there is one", function(done){
process.argv[2] = "somepath";
getOptions(function(err, options){
options.filepath.should.equal("somepath");
done();
});
});
it ("should get a filepath if there is one, even in verbose mode", function(done){
process.argv[2] = "--verbose";
process.argv[3] = "somepath";
getOptions(function(err, options){
options.filepath.should.equal("somepath");
done();
});
});
it ("should set service_job_id if it exists", function(done){
testServiceJobId(getOptions, done);
});
it ("should set git hash if it exists", function(done){
testGitHash(getOptions, done);
});
it ("should set git branch if it exists", function(done){
testGitBranch(getOptions, done);
});
it ("should set repo_token if it exists", function(done){
testRepoToken(getOptions, done);
});
it ("should set service_name if it exists", function(done){
testServiceName(getOptions, done);
});
it ("should set service_name and service_job_id if it's running on travis-ci", function(done){
testTravisCi(getOptions, done);
});
it ("should set service_name and service_job_id if it's running on jenkins", function(done){
testJenkins(getOptions, done);
});
it ("should set service_name and service_job_id if it's running on circleci", function(done){
testCircleCi(getOptions, done);
});
});
var testServiceJobId = function(sut, done){
process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID";
sut(function(err, options){
options.service_job_id.should.equal("SERVICE_JOB_ID");
done();
});
};
var testGitHash = function(sut, done){
process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e";
sut(function(err, options){
options.git.head.id.should.equal("e3e3e3e3e3e3e3e3e");
done();
});
};
var testGitBranch = function(sut, done){
process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e";
process.env.COVERALLS_GIT_BRANCH = "master";
sut(function(err, options){
options.git.branch.should.equal("master");
done();
});
};
var testRepoToken = function(sut, done){
process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN";
sut(function(err, options){
options.repo_token.should.equal("REPO_TOKEN");
done();
});
};
var testServiceName = function(sut, done){
process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
sut(function(err, options){
options.service_name.should.equal("SERVICE_NAME");
done();
});
};
var testTravisCi = function(sut, done){
process.env.TRAVIS = "TRUE";
process.env.TRAVIS_JOB_ID = "1234";
sut(function(err, options){
options.service_name.should.equal("travis-ci");
options.service_job_id.should.equal("1234");
done();
});
};
var testJenkins = function(sut, done){
process.env.JENKINS_URL = "something";
process.env.BUILD_ID = "1234";
process.env.GIT_COMMIT = "a12s2d3df4f435g45g45g67h5g6";
process.env.GIT_BRANCH = "master";
sut(function(err, options){
options.service_name.should.equal("jenkins");
options.service_job_id.should.equal("1234");
options.git.should.eql({ head:
{ id: 'a12s2d3df4f435g45g45g67h5g6',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message' },
branch: 'master',
remotes: [] });
done();
});
};
var testCircleCi = function(sut, done){
process.env.CIRCLECI = true;
process.env.CIRCLE_BRANCH = "master";
process.env.CIRCLE_BUILD_NUM = "1234";
process.env.CIRCLE_SHA1 = "e3e3e3e3e3e3e3e3e";
sut(function(err, options){
options.service_name.should.equal("circleci");
options.service_job_id.should.equal("1234");
options.git.should.eql({ head:
{ id: 'e3e3e3e3e3e3e3e3e',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message' },
branch: 'master',
remotes: [] });
done();
});
};
|