diff options
Diffstat (limited to 'test/fetchGitData.js')
| -rw-r--r-- | test/fetchGitData.js | 212 |
1 files changed, 114 insertions, 98 deletions
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(); + }); }); }); |
