diff --git a/README.md b/README.md index 225fedc..748baa2 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ npm i --save-dev mcfly-semantic-release In your `package.json` ```json "scripts": { - "release": "mcfly-semantic-release" + "release": "mcfly-semantic-release" } ``` @@ -23,7 +23,7 @@ Optionnaly additional files can be added to also have their version bumped ```json "scripts": { -"release": "mcfly-semantic-release.js --files ./package.json ./bower.json ./config.xml" + "release": "mcfly-semantic-release.js --files ./package.json ./bower.json ./config.xml" } ``` diff --git a/lib/gitHelper.js b/lib/gitHelper.js index 18ca23b..3708668 100644 --- a/lib/gitHelper.js +++ b/lib/gitHelper.js @@ -4,6 +4,10 @@ global.Promise = require('bluebird'); const git = require('simple-git')(); const _ = require('lodash'); +/** + * Gets the current branch + * @returns {Promise.} The name of the current branch + */ var getCurrentBranch = function() { return Promise .fromCallback((cb) => { @@ -26,7 +30,13 @@ var commitVersion = function(version) { }); }; -var getRemoteRepository = function() { +/** + * Gets a remote repository + * @param {String} remotename The name of the remote repository, default to 'origin' + * @returns {Promise.} The result object with url, owner, and repo + */ +var getRemoteRepository = function(remotename) { + remotename = remotename || 'origin'; return Promise .fromCallback((cb) => { git @@ -35,7 +45,7 @@ var getRemoteRepository = function() { .then(remotes => { return _.chain(remotes) .find(remote => { - return remote.name === 'origin'; + return remote.name === remotename; }) .value(); }) @@ -54,6 +64,10 @@ var getRemoteRepository = function() { }); }; +/** + * Check if the repo is clean + * @returns {Promise.} true if the repo is clean, false otherwise + */ var isClean = function() { return Promise .fromCallback(cb => { diff --git a/test/mocha/fileHelper.spec.js b/test/mocha/fileHelper.spec.js new file mode 100644 index 0000000..a66262a --- /dev/null +++ b/test/mocha/fileHelper.spec.js @@ -0,0 +1,30 @@ +'use strict'; +var fileHelper = require('../../lib/fileHelper'); +var expect = require('chai').expect; +const packageName = 'dummy'; +describe('fileHelper', () => { + describe('readTextFile()', () => { + it('without dirname should succeed', () => { + var res = fileHelper.readTextFile('./test/assets/package.json'); + expect(res.length).to.be.above(1); + }); + + it('with dirname should succeed', () => { + var res = fileHelper.readTextFile('./package.json', './test/assets'); + expect(res.length).to.be.above(1); + }); + }); + + describe('readJsonFile()', () => { + it('without dirname should succeed', () => { + var res = fileHelper.readJsonFile('./test/assets/package.json'); + expect(res.name).to.equal(packageName); + }); + + it('with dirname should succeed', () => { + var res = fileHelper.readJsonFile('./package.json', './test/assets'); + expect(res.name).to.equal(packageName); + }); + }); + +}); diff --git a/test/mocha/gitHelper.spec.js b/test/mocha/gitHelper.spec.js index cceede2..5c2d279 100644 --- a/test/mocha/gitHelper.spec.js +++ b/test/mocha/gitHelper.spec.js @@ -16,7 +16,7 @@ describe('gitHelper', () => { }); }); describe('getRemoteRepository()', () => { - it('should return remote repository', (done) => { + it('should return remote origin repository', (done) => { gitHelper.getRemoteRepository() .then(remote => { @@ -28,6 +28,17 @@ describe('gitHelper', () => { }) .catch(done); }); + + it('should throw error with an unknow remote', (done) => { + gitHelper.getRemoteRepository('dummy') + .then(remote => { + done(new Error('should throw an error')); + }) + .catch(err => { + expect(err).not.to.be.null; + done(); + }); + }); }); describe('isClean()', () => {