diff options
| author | Gregg Caines <[email protected]> | 2013-08-24 18:00:40 -0700 |
|---|---|---|
| committer | Gregg Caines <[email protected]> | 2013-08-24 18:00:40 -0700 |
| commit | 0c817523ee2a74a7912250056f474156dc755100 (patch) | |
| tree | b3ac61d91440216fddc7537cf1af8090fd4b6cc8 /test | |
| parent | 829e407f57e6a0abb15cafd69a0983165777535b (diff) | |
| download | node-coveralls-0c817523ee2a74a7912250056f474156dc755100.tar.xz node-coveralls-0c817523ee2a74a7912250056f474156dc755100.zip | |
removed exec-sync. version 2.2.0 candidate
Diffstat (limited to 'test')
| -rw-r--r-- | test/convertLcovToCoveralls.js | 27 | ||||
| -rw-r--r-- | test/fetchGitData.js | 212 | ||||
| -rw-r--r-- | test/getOptions.js | 114 | ||||
| -rw-r--r-- | test/handleInput.js | 12 |
4 files changed, 206 insertions, 159 deletions
diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js index eab2dd8..2e07a87 100644 --- a/test/convertLcovToCoveralls.js +++ b/test/convertLcovToCoveralls.js @@ -6,7 +6,7 @@ var logger = require('../lib/logger'); logger = require('log-driver')({level : false}); describe("convertLcovToCoveralls", function(){ - it ("should convert a simple lcov file", function(){ + it ("should convert a simple lcov file", function(done){ process.env.TRAVIS_JOB_ID = -1; var path = __dirname + "/../fixtures/onefile.lcov"; var input = fs.readFileSync(path, "utf8"); @@ -17,10 +17,11 @@ describe("convertLcovToCoveralls", function(){ output.source_files[0].source.split("\n").length.should.equal(173); output.source_files[0].coverage[54].should.equal(0); output.source_files[0].coverage[60].should.equal(0); + done(); }); }); - it ("should pass on all appropriate parameters from the environment", function(){ + it ("should pass on all appropriate parameters from the environment", function(done){ process.env.TRAVIS_JOB_ID = -1; process.env.COVERALLS_GIT_COMMIT = "GIT_HASH"; process.env.COVERALLS_GIT_BRANCH = "master"; @@ -28,18 +29,19 @@ describe("convertLcovToCoveralls", function(){ process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID"; process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN"; - var options = getOptions(); - var path = __dirname + "/../fixtures/onefile.lcov"; - var input = fs.readFileSync(path, "utf8"); - var libpath = "fixtures/lib"; - options.filepath = libpath; - convertLcovToCoveralls(input, options, function(err, output){ - should.not.exist(err); - console.log(output); - //output.git.should.equal("GIT_HASH"); + getOptions(function(err, options){ + var path = __dirname + "/../fixtures/onefile.lcov"; + var input = fs.readFileSync(path, "utf8"); + var libpath = "fixtures/lib"; + options.filepath = libpath; + convertLcovToCoveralls(input, options, function(err, output){ + should.not.exist(err); + //output.git.should.equal("GIT_HASH"); + done(); + }); }); }); - it ("should work with a relative path as well", function(){ + it ("should work with a relative path as well", function(done){ process.env.TRAVIS_JOB_ID = -1; var path = __dirname + "/../fixtures/onefile.lcov"; var input = fs.readFileSync(path, "utf8"); @@ -48,6 +50,7 @@ describe("convertLcovToCoveralls", function(){ should.not.exist(err); output.source_files[0].name.should.equal("index.js"); output.source_files[0].source.split("\n").length.should.equal(173); + done(); }); }); }); diff --git a/test/fetchGitData.js b/test/fetchGitData.js index 94d243f..de5c474 100644 --- a/test/fetchGitData.js +++ b/test/fetchGitData.js @@ -1,5 +1,5 @@ var should = require('should'); -var git = require('../lib/fetchGitData'); +var fetchGitData = require('../lib/fetchGitData'); var getOptions = require('../index').getOptions; describe("fetchGitData", function(){ @@ -7,60 +7,46 @@ describe("fetchGitData", function(){ process.env = {}; }); it("should throw an error when no data is passed", function() { - git.should.throw(/No options passed/); + fetchGitData.should.throw(/fetchGitData requires a callback/); }); - it("should throw an error if no head is provided", function() { - var fn = function() { - git({}); - }; - fn.should.throw(/You must provide the head/); + it("should throw an error if no head is provided", function(done) { + fetchGitData({ + }, function(err){ + err.should.match(/You must provide the head/); + done(); + }); }); - it("should throw an error if no head.id is provided", function() { - var fn = function() { - git({ - head: {} - }); - }; - fn.should.throw(/You must provide the head.id/); + it("should throw an error if no head.id is provided", function(done) { + fetchGitData({ + head: {} + }, function(err){ + err.should.match(/You must provide the head.id/); + done(); + }); }); - it("should return default values", function() { - var options = git({ + it("should return default values", function(done) { + var options = fetchGitData({ head: { id: "COMMIT_HASH" } - }); - options.should.eql({ - "head": { - "id": "COMMIT_HASH", - "author_name": "Unknown Author", - "author_email": "", - "committer_name": "Unknown Committer", - "committer_email": "", - "message": "Unknown Commit Message" - }, - "branch": "", - "remotes": [] + }, function(err, options){ + options.should.eql({ + "head": { + "id": "COMMIT_HASH", + "author_name": "Unknown Author", + "author_email": "", + "committer_name": "Unknown Committer", + "committer_email": "", + "message": "Unknown Commit Message" + }, + "branch": "", + "remotes": [] + }); + done(); }); }); - it("should override default values", function() { - var options = git({ - "head": { - "id": "COMMIT_HASH", - "author_name": "MY AUTHOR", - "author_email": "", - "committer_name": "MY COMMITTER", - "committer_email": "", - "message": "MY COMMIT MESSAGE" - }, - "branch": "TEST", - "remotes": [ - { - "name": "TEST", - "url": "test-url" - } - ] - }); - options.should.eql({ + it("should override default values", function(done) { + var options = fetchGitData({ "head": { "id": "COMMIT_HASH", "author_name": "MY AUTHOR", @@ -76,46 +62,71 @@ describe("fetchGitData", function(){ "url": "test-url" } ] + }, function(err, options){ + options.should.eql({ + "head": { + "id": "COMMIT_HASH", + "author_name": "MY AUTHOR", + "author_email": "", + "committer_name": "MY COMMITTER", + "committer_email": "", + "message": "MY COMMIT MESSAGE" + }, + "branch": "TEST", + "remotes": [ + { + "name": "TEST", + "url": "test-url" + } + ] + }); + done(); }); }); - it("should convert git.branch to a string", function() { - var objectToString = git({ + it("should convert git.branch to a string", function(done) { + fetchGitData({ "head": { "id": "COMMIT_HASH" }, "branch": { "covert": "to a string" } + }, function(err, str){ + str.branch.should.be.a("string"); + fetchGitData({ + "head": { + "id": "COMMIT_HASH" + }, + "branch": ["convert", "to", "a", "string"] + }, function(err, str){ + str.branch.should.be.a("string"); + done(); + }); }); - var arrayToString = git({ - "head": { - "id": "COMMIT_HASH" - }, - "branch": ["convert", "to", "a", "string"] - }); - objectToString.branch.should.be.a("string"); - arrayToString.branch.should.be.a("string"); }); - it("should convert git.remotes to an array", function() { - var stringToArray = git({ + it("should convert git.remotes to an array", function(done) { + fetchGitData({ "head": { "id": "COMMIT_HASH" }, "remotes": "convert from string to an array" + }, function(err, arr){ + arr.remotes.should.be.instanceof(Array); + fetchGitData({ + "head": { + "id": "COMMIT_HASH" + }, + "remotes": { + "convert": "from object to an array" + } + }, function(err, arr){ + arr.remotes.should.be.instanceof(Array); + done(); + }); }); - var objectToArray = git({ - "head": { - "id": "COMMIT_HASH" - }, - "remotes": { - "convert": "from object to an array" - } - }); - stringToArray.remotes.should.be.instanceof(Array); - objectToArray.remotes.should.be.instanceof(Array); }); - it("should save passed remotes", function() { - var options = git({ + it("should save passed remotes", function(done) { + fetchGitData({ "head": { "id": "COMMIT_HASH" }, @@ -125,36 +136,41 @@ describe("fetchGitData", function(){ "url": "https://my.test.url" } ] - }); - options.should.eql({ - "head": { - "id": "COMMIT_HASH", - "author_name": "Unknown Author", - "author_email": "", - "committer_name": "Unknown Committer", - "committer_email": "", - "message": "Unknown Commit Message" - }, - "branch": "", - "remotes": [ - { - "name": "test", - "url": "https://my.test.url" - } - ] + }, function(err, options){ + options.should.eql({ + "head": { + "id": "COMMIT_HASH", + "author_name": "Unknown Author", + "author_email": "", + "committer_name": "Unknown Committer", + "committer_email": "", + "message": "Unknown Commit Message" + }, + "branch": "", + "remotes": [ + { + "name": "test", + "url": "https://my.test.url" + } + ] + }); + done(); }); }); - it("should execute git commands when a valid commit hash is given", function() { + it("should execute git commands when a valid commit hash is given", function(done) { process.env.COVERALLS_GIT_COMMIT = "HEAD"; process.env.COVERALLS_GIT_BRANCH = "master"; - var options = getOptions().git; - options.head.should.be.a("object"); - options.head.author_name.should.not.equal("Unknown Author"); - options.head.committer_name.should.not.equal("Unknown Committer"); - options.head.message.should.not.equal("Unknown Commit Message"); - options.branch.should.be.a("string"); - options.should.have.property("remotes"); - options.remotes.should.be.instanceof(Array); - options.remotes.length.should.be.above(0); + getOptions(function(err, options){ + options = options.git; + options.head.should.be.a("object"); + options.head.author_name.should.not.equal("Unknown Author"); + options.head.committer_name.should.not.equal("Unknown Committer"); + options.head.message.should.not.equal("Unknown Commit Message"); + options.branch.should.be.a("string"); + options.should.have.property("remotes"); + options.remotes.should.be.instanceof(Array); + options.remotes.length.should.be.above(0); + done(); + }); }); }); diff --git a/test/getOptions.js b/test/getOptions.js index ba3b7f0..67276af 100644 --- a/test/getOptions.js +++ b/test/getOptions.js @@ -5,77 +5,105 @@ describe("getOptions", function(){ beforeEach(function(){ process.env = {}; }); - it ("should get a filepath if there is one", function(){ + it ("should get a filepath if there is one", function(done){ process.argv[2] = "somepath"; - getOptions().filepath.should.equal("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(){ + it ("should get a filepath if there is one, even in verbose mode", function(done){ process.argv[2] = "--verbose"; process.argv[3] = "somepath"; - getOptions().filepath.should.equal("somepath"); + getOptions(function(err, options){ + options.filepath.should.equal("somepath"); + done(); + }); }); - it ("should set service_job_id if it exists", function(){ + it ("should set service_job_id if it exists", function(done){ process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID"; - getOptions().service_job_id.should.equal("SERVICE_JOB_ID"); + getOptions(function(err, options){ + options.service_job_id.should.equal("SERVICE_JOB_ID"); + done(); + }); }); - it ("should set git hash if it exists", function(){ + it ("should set git hash if it exists", function(done){ process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e"; - getOptions().git.head.id.should.equal("e3e3e3e3e3e3e3e3e"); + getOptions(function(err, options){ + options.git.head.id.should.equal("e3e3e3e3e3e3e3e3e"); + done(); + }); }); - it ("should set git hash if it exists", function(){ + it ("should set git hash if it exists", function(done){ process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e"; process.env.COVERALLS_GIT_BRANCH = "master"; - getOptions().git.branch.should.equal("master"); + getOptions(function(err, options){ + options.git.branch.should.equal("master"); + done(); + }); }); - it ("should set repo_token if it exists", function(){ + it ("should set repo_token if it exists", function(done){ process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN"; - getOptions().repo_token.should.equal("REPO_TOKEN"); + getOptions(function(err, options){ + options.repo_token.should.equal("REPO_TOKEN"); + done(); + }); }); - it ("should set service_name if it exists", function(){ + it ("should set service_name if it exists", function(done){ process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME"; - getOptions().service_name.should.equal("SERVICE_NAME"); + getOptions(function(err, options){ + options.service_name.should.equal("SERVICE_NAME"); + done(); + }); }); - it ("should set service_name and service_job_id if it's running on travis-ci", function(){ + 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().service_name.should.equal("travis-ci"); - getOptions().service_job_id.should.equal("1234"); + getOptions(function(err, options){ + options.service_name.should.equal("travis-ci"); + options.service_job_id.should.equal("1234"); + done(); + }); }); - it ("should set service_name and service_job_id if it's running on jenkins", function(){ + 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"; - var options = getOptions(); - 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: [] }); + 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(); + }); }); - it ("should set service_name and service_job_id if it's running on circleci", function(){ + 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"; - var options = getOptions(); - 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: [] }); + 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: [] }); + done(); }); + }); }); diff --git a/test/handleInput.js b/test/handleInput.js index 45f0482..f06e8a4 100644 --- a/test/handleInput.js +++ b/test/handleInput.js @@ -9,8 +9,8 @@ describe("handleInput", function(){ sinon.restoreAll(); }); it ("throws an error when there's an error sending", function(done){ - sinon.stub(index, 'getOptions', function(){ - return {}; + sinon.stub(index, 'getOptions', function(cb){ + return cb(null, {}); }); sinon.stub(index, 'sendToCoveralls', function(postData, cb){ try { @@ -25,8 +25,8 @@ describe("handleInput", function(){ index.handleInput(input); }); it ("throws an error when there's a bad status code", function(done){ - sinon.stub(index, 'getOptions', function(){ - return {}; + sinon.stub(index, 'getOptions', function(cb){ + return cb(null, {}); }); sinon.stub(index, 'sendToCoveralls', function(postData, cb){ try { @@ -41,8 +41,8 @@ describe("handleInput", function(){ index.handleInput(input); }); it ("completes successfully when there are now errors", function(done){ - sinon.stub(index, 'getOptions', function(){ - return {}; + sinon.stub(index, 'getOptions', function(cb){ + return cb(null, {}); }); sinon.stub(index, 'sendToCoveralls', function(postData, cb){ cb(null, {statusCode : 200}, "body"); |
