diff options
Diffstat (limited to 'test/fetchGitData.js')
| -rw-r--r-- | test/fetchGitData.js | 204 |
1 files changed, 107 insertions, 97 deletions
diff --git a/test/fetchGitData.js b/test/fetchGitData.js index 012e129..f15b179 100644 --- a/test/fetchGitData.js +++ b/test/fetchGitData.js @@ -1,179 +1,189 @@ -var should = require('should'); -var fetchGitData = require('../lib/fetchGitData'); -var getOptions = require('../index').getOptions; +'use strict'; -describe("fetchGitData", function(){ - beforeEach(function(){ - process.env = {PATH: process.env.PATH}; +const should = require('should'); +const fetchGitData = require('../lib/fetchGitData'); +const { getOptions } = require('..'); + +describe('fetchGitData', () => { + beforeEach(() => { + process.env = { PATH: process.env.PATH }; }); - it("should throw an error when no data is passed", function() { + it('should throw an error when no data is passed', () => { fetchGitData.should.throw(/fetchGitData requires a callback/); }); - it('should throw an error when no git context is provided', function(done) { - fetchGitData(undefined, function(err){ + it('should throw an error when no git context is provided', done => { + fetchGitData(undefined, err => { err.should.match(/No options passed/); done(); }); }); - it("should throw an error if no head is provided", function(done) { + it('should throw an error if no head is provided', done => { fetchGitData({ - }, function(err){ + }, err => { err.should.match(/You must provide the head/); done(); }); }); - it("should throw an error if no head.id is provided", function(done) { + it('should throw an error if no head.id is provided', done => { fetchGitData({ head: {} - }, function(err){ + }, err => { err.should.match(/You must provide the head.id/); done(); }); }); - it("should return default values", function(done) { - var options = fetchGitData({ + it('should return default values', done => { + fetchGitData({ head: { - id: "COMMIT_HASH" + id: 'COMMIT_HASH' } - }, function(err, options){ + }, (err, options) => { + should.not.exist(err); options.should.eql({ - "head": { - "id": "COMMIT_HASH", - "author_name": "Unknown Author", - "author_email": "", - "committer_name": "Unknown Committer", - "committer_email": "", - "message": "Unknown Commit Message" + 'head': { + 'id': 'COMMIT_HASH', + 'author_name': 'Unknown Author', + 'author_email': '', + 'committer_name': 'Unknown Committer', + 'committer_email': '', + 'message': 'Unknown Commit Message' }, - "branch": "", - "remotes": [] + 'branch': '', + 'remotes': [] }); done(); }); }); - it("should override default values", function(done) { - var options = fetchGitData({ - "head": { - "id": "COMMIT_HASH", - "author_name": "MY AUTHOR", - "author_email": "", - "committer_name": "MY COMMITTER", - "committer_email": "", - "message": "MY COMMIT MESSAGE" + it('should override default values', done => { + fetchGitData({ + 'head': { + 'id': 'COMMIT_HASH', + 'author_name': 'MY AUTHOR', + 'author_email': '', + 'committer_name': 'MY COMMITTER', + 'committer_email': '', + 'message': 'MY COMMIT MESSAGE' }, - "branch": "TEST", - "remotes": [ + 'branch': 'TEST', + 'remotes': [ { - "name": "TEST", - "url": "test-url" + 'name': 'TEST', + 'url': 'test-url' } ] - }, function(err, options){ + }, (err, options) => { + should.not.exist(err); options.should.eql({ - "head": { - "id": "COMMIT_HASH", - "author_name": "MY AUTHOR", - "author_email": "", - "committer_name": "MY COMMITTER", - "committer_email": "", - "message": "MY COMMIT MESSAGE" + 'head': { + 'id': 'COMMIT_HASH', + 'author_name': 'MY AUTHOR', + 'author_email': '', + 'committer_name': 'MY COMMITTER', + 'committer_email': '', + 'message': 'MY COMMIT MESSAGE' }, - "branch": "TEST", - "remotes": [ + 'branch': 'TEST', + 'remotes': [ { - "name": "TEST", - "url": "test-url" + 'name': 'TEST', + 'url': 'test-url' } ] }); done(); }); }); - it("should convert git.branch to a string", function(done) { + it('should convert git.branch to a string', done => { fetchGitData({ - "head": { - "id": "COMMIT_HASH" + 'head': { + 'id': 'COMMIT_HASH' }, - "branch": { - "covert": "to a string" + 'branch': { + 'covert': 'to a string' } - }, function(err, str){ + }, (err, str) => { + should.not.exist(err); str.branch.should.be.String(); fetchGitData({ - "head": { - "id": "COMMIT_HASH" + 'head': { + 'id': 'COMMIT_HASH' }, - "branch": ["convert", "to", "a", "string"] - }, function(err, str){ + 'branch': ['convert', 'to', 'a', 'string'] + }, (err, str) => { + should.not.exist(err); str.branch.should.be.String(); done(); }); }); }); - it("should convert git.remotes to an array", function(done) { + it('should convert git.remotes to an array', done => { fetchGitData({ - "head": { - "id": "COMMIT_HASH" + 'head': { + 'id': 'COMMIT_HASH' }, - "remotes": "convert from string to an array" - }, function(err, arr){ + 'remotes': 'convert from string to an array' + }, (err, arr) => { + should.not.exist(err); arr.remotes.should.be.instanceof(Array); fetchGitData({ - "head": { - "id": "COMMIT_HASH" + 'head': { + 'id': 'COMMIT_HASH' }, - "remotes": { - "convert": "from object to an array" + 'remotes': { + 'convert': 'from object to an array' } - }, function(err, arr){ + }, (err, arr) => { + should.not.exist(err); arr.remotes.should.be.instanceof(Array); done(); }); }); }); - it("should save passed remotes", function(done) { + it('should save passed remotes', done => { fetchGitData({ - "head": { - "id": "COMMIT_HASH" + 'head': { + 'id': 'COMMIT_HASH' }, - "remotes": [ + 'remotes': [ { - "name": "test", - "url": "https://my.test.url" + 'name': 'test', + 'url': 'https://my.test.url' } ] - }, function(err, options){ + }, (err, options) => { + should.not.exist(err); options.should.eql({ - "head": { - "id": "COMMIT_HASH", - "author_name": "Unknown Author", - "author_email": "", - "committer_name": "Unknown Committer", - "committer_email": "", - "message": "Unknown Commit Message" + 'head': { + 'id': 'COMMIT_HASH', + 'author_name': 'Unknown Author', + 'author_email': '', + 'committer_name': 'Unknown Committer', + 'committer_email': '', + 'message': 'Unknown Commit Message' }, - "branch": "", - "remotes": [ + 'branch': '', + 'remotes': [ { - "name": "test", - "url": "https://my.test.url" + 'name': 'test', + 'url': 'https://my.test.url' } ] }); done(); }); }); - 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"; - getOptions(function(err, options){ + it('should execute git commands when a valid commit hash is given', done => { + process.env.COVERALLS_GIT_COMMIT = 'HEAD'; + process.env.COVERALLS_GIT_BRANCH = 'master'; + getOptions((err, options) => { + should.not.exist(err); options = options.git; options.head.should.be.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.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.String(); - options.should.have.property("remotes"); + options.should.have.property('remotes'); options.remotes.should.be.instanceof(Array); options.remotes.length.should.be.above(0); done(); |
