Skip to content

Commit

Permalink
test: added tests for tag option equals to false
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinskipg committed Apr 18, 2015
1 parent bd58ef0 commit 1fc1e80
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
12 changes: 4 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<a name="">Git changelog</a>
<a name="">My app - Changelog</a>
# (2015-04-18)


## Documentation
## Bug Fixes

- added documentation for explaining the commit message



---
<sub><sup>*Generated with [git-changelog](https:/rafinskipg/git-changelog). If you have any problem or suggestion, create an issue.* :) **Thanks** </sub></sup>
- Github commit url
([c186f2d8](https:/rafinskipg/git-changelog/commit/c186f2d877e7907305953610bcaaef331406178a)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test": "grunt test"
},
"dependencies": {
"commander": "^2.5.0",
"commander": "^2.8.0",
"lodash": "^2.4.1",
"q": "~0.9.7"
},
Expand Down
6 changes: 3 additions & 3 deletions tasks/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ if (process.argv.join('').indexOf('/grunt') === -1) {
}

if (program.tag != undefined){
options.tag = program.tag;

if(program.tag === false){
if(program.tag === false || program.tag === "false"){
options.tag = false;
console.log(' - No tag, getting log since the BigBang');
}else{
options.tag = program.tag;
console.log(' - Generating log since tag %s', program.tag);
}
}
Expand Down
18 changes: 13 additions & 5 deletions tasks/git_changelog_generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var init = function(params){
var deferred = q.defer();

OPTS = params;
OPTS.msg = '';

getRepoUrl().then(function(url){
OPTS.repo_url = url;
Expand All @@ -46,9 +47,11 @@ var init = function(params){
B: '[%s]('+OPTS.repo_url+'/commits/%s)'})
[PROVIDER];

OPTS.msg += 'found remote;';
deferred.resolve(OPTS);
})
.catch(function(){
OPTS.msg += 'not remote;';
deferred.reject("Sorry, you doesn't have configured any origin remote or passed a `repo_url` config value");
});

Expand Down Expand Up @@ -254,6 +257,8 @@ var getPreviousTag = function() {
var deferred = q.defer();
if(OPTS.tag){
deferred.resolve(OPTS.tag);
}else if(OPTS.tag === false){
deferred.resolve(false);
}else{
//IF we dont find a previous tag, we get all the commits from the beggining - The bigbang of the code
child.exec(GIT_TAG_CMD, function(code, stdout, stderr) {
Expand Down Expand Up @@ -298,19 +303,22 @@ var generate = function(params) {
.then(function(tag) {
var fn ;

if(typeof(tag) !== 'undefined' && !OPTS.ignore_tags){
if(typeof(tag) !== 'undefined' && tag !== false && !OPTS.ignore_tags){
log('Reading git log since', tag);
OPTS.msg += 'since tag:'+ tag +';';
fn = function(){ return readGitLog(GIT_LOG_CMD, tag);};
}else{
log('Reading git log since the beggining');
OPTS.msg += 'since beggining;';
fn = function(){ return readGitLog(GIT_NOTAG_LOG_CMD);};
}

fn().then(function(commits) {
log('Parsed', commits.length, 'commits');
log('Generating changelog to', OPTS.file || 'stdout', '(', OPTS.version, ')');
writeChangelog(OPTS.file ? fs.createWriteStream(OPTS.file) : process.stdout, commits);
deferred.resolve();
OPTS.msg += 'parsed commits:'+ commits.length +';';
log('Parsed', commits.length, 'commits');
log('Generating changelog to', OPTS.file || 'stdout', '(', OPTS.version, ')');
writeChangelog(OPTS.file ? fs.createWriteStream(OPTS.file) : process.stdout, commits);
deferred.resolve(OPTS);
});

})
Expand Down
22 changes: 22 additions & 0 deletions test/changelog.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
var fs = require('fs'),
expect = require('chai').expect;
var defaults = require('../tasks/defaults');
var _ = require('lodash');

describe('changelog.js', function() {
var ch = require('../tasks/git_changelog_generate');
Expand Down Expand Up @@ -107,4 +109,24 @@ describe('changelog.js', function() {
})
});
});

describe('Params tests', function() {
it('should read log since beggining if tag is false', function(done) {

var options = _.cloneDeep(defaults);

options.tag = false;
options.name = 'my name';

ch.generate(options)
.then(function(opts){
expect(opts.msg).to.be.a('string');
expect(opts.msg.indexOf('since beggining')).to.not.equal(-1);
done();
})
.catch(function(err){
console.log('error', err);
})
});
});
});

0 comments on commit 1fc1e80

Please sign in to comment.