Skip to content

Commit

Permalink
feat(app): Improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiat committed Jun 20, 2016
1 parent 2fab58b commit f2caf56
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ npm i --save-dev mcfly-semantic-release
In your `package.json`
```json
"scripts": {
"release": "mcfly-semantic-release"
"release": "mcfly-semantic-release"
}
```

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"
}
```

Expand Down
18 changes: 16 additions & 2 deletions lib/gitHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ global.Promise = require('bluebird');
const git = require('simple-git')();
const _ = require('lodash');

/**
* Gets the current branch
* @returns {Promise.<String>} The name of the current branch
*/
var getCurrentBranch = function() {
return Promise
.fromCallback((cb) => {
Expand All @@ -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.<Object>} The result object with url, owner, and repo
*/
var getRemoteRepository = function(remotename) {
remotename = remotename || 'origin';
return Promise
.fromCallback((cb) => {
git
Expand All @@ -35,7 +45,7 @@ var getRemoteRepository = function() {
.then(remotes => {
return _.chain(remotes)
.find(remote => {
return remote.name === 'origin';
return remote.name === remotename;
})
.value();
})
Expand All @@ -54,6 +64,10 @@ var getRemoteRepository = function() {
});
};

/**
* Check if the repo is clean
* @returns {Promise.<Boolean>} true if the repo is clean, false otherwise
*/
var isClean = function() {
return Promise
.fromCallback(cb => {
Expand Down
30 changes: 30 additions & 0 deletions test/mocha/fileHelper.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

});
13 changes: 12 additions & 1 deletion test/mocha/gitHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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()', () => {
Expand Down

0 comments on commit f2caf56

Please sign in to comment.