aboutsummaryrefslogtreecommitdiff
path: root/test/getOptions.js
diff options
context:
space:
mode:
authorMatthew J. Morrison <[email protected]>2013-09-06 22:31:08 -0500
committerMatthew J. Morrison <[email protected]>2013-09-06 22:31:08 -0500
commit8078aa060a0361d358b069f92fa07af7f9e27bd4 (patch)
treec6084e24b34c8c944958c56447b21e7f9a7e951b /test/getOptions.js
parent3ab2c57bdde97787c313623b4f7638e909c5aafd (diff)
downloadnode-coveralls-8078aa060a0361d358b069f92fa07af7f9e27bd4.tar.xz
node-coveralls-8078aa060a0361d358b069f92fa07af7f9e27bd4.zip
export both getOptions and getBaseOptions from getOptions.js
Also updated index.js to prevent any breaking API changes and added tests around both getOptions and getBaseOptions.
Diffstat (limited to 'test/getOptions.js')
-rw-r--r--test/getOptions.js202
1 files changed, 133 insertions, 69 deletions
diff --git a/test/getOptions.js b/test/getOptions.js
index 67276af..87e5b80 100644
--- a/test/getOptions.js
+++ b/test/getOptions.js
@@ -1,5 +1,37 @@
var should = require('should');
var getOptions = require('../index').getOptions;
+var getBaseOptions = require('../lib/getOptions').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(){
@@ -22,88 +54,120 @@ describe("getOptions", function(){
});
});
it ("should set service_job_id if it exists", function(done){
- process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID";
- getOptions(function(err, options){
- options.service_job_id.should.equal("SERVICE_JOB_ID");
- done();
- });
+ testServiceJobId(getOptions, done);
});
it ("should set git hash if it exists", function(done){
- process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e";
- getOptions(function(err, options){
- options.git.head.id.should.equal("e3e3e3e3e3e3e3e3e");
- done();
- });
+ testGitHash(getOptions, done);
});
- it ("should set git hash if it exists", function(done){
- process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e";
- process.env.COVERALLS_GIT_BRANCH = "master";
- getOptions(function(err, options){
- options.git.branch.should.equal("master");
- done();
- });
+ it ("should set git branch if it exists", function(done){
+ testGitBranch(getOptions, done);
});
it ("should set repo_token if it exists", function(done){
- process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN";
- getOptions(function(err, options){
- options.repo_token.should.equal("REPO_TOKEN");
- done();
- });
+ testRepoToken(getOptions, done);
});
it ("should set service_name if it exists", function(done){
- process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
- getOptions(function(err, options){
- options.service_name.should.equal("SERVICE_NAME");
- done();
- });
+ testServiceName(getOptions, done);
});
it ("should set service_name and service_job_id if it's running on travis-ci", function(done){
- process.env.TRAVIS = "TRUE";
- process.env.TRAVIS_JOB_ID = "1234";
- getOptions(function(err, options){
- options.service_name.should.equal("travis-ci");
- options.service_job_id.should.equal("1234");
- done();
- });
+ testTravisCi(getOptions, done);
});
it ("should set service_name and service_job_id if it's running on jenkins", function(done){
- process.env.JENKINS_URL = "something";
- process.env.BUILD_ID = "1234";
- process.env.GIT_COMMIT = "a12s2d3df4f435g45g45g67h5g6";
- process.env.GIT_BRANCH = "master";
- getOptions(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();
- });
+ testJenkins(getOptions, done);
});
it ("should set service_name and service_job_id if it's running on circleci", function(done){
- process.env.CIRCLECI = true;
- process.env.CIRCLE_BRANCH = "master";
- process.env.CIRCLE_BUILD_NUM = "1234";
- process.env.CIRCLE_SHA1 = "e3e3e3e3e3e3e3e3e";
- getOptions(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: [] });
+ 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();
+ });
+};