Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
fix(doFlush): one it is the only potential release
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Feb 6, 2016
1 parent 609afab commit cc3b5db
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var _ = require('lodash');
function conventionalChangelogWriter(context, options) {
var savedKeyCommit;
var commits = [];
var firstGeneration = true;
var neverGenerated = true;

context = _.extend({
commit: 'commits',
Expand Down Expand Up @@ -78,7 +80,6 @@ function conventionalChangelogWriter(context, options) {
options.commitsSort = util.functionify(options.commitsSort);
options.noteGroupsSort = util.functionify(options.noteGroupsSort);
options.notesSort = util.functionify(options.notesSort);
var firstGeneration = true;

return through.obj(function(chunk, enc, cb) {
try {
Expand All @@ -93,6 +94,7 @@ function conventionalChangelogWriter(context, options) {
}

if (generateOn(keyCommit, commits, context, options)) {
neverGenerated = false;
result = util.generate(options, commits, context, keyCommit);
if (options.includeDetails) {
this.push({
Expand All @@ -107,6 +109,7 @@ function conventionalChangelogWriter(context, options) {
}
} else {
if (generateOn(keyCommit, commits, context, options)) {
neverGenerated = false;
result = util.generate(options, commits, context, savedKeyCommit);

if (!firstGeneration || options.doFlush) {
Expand Down Expand Up @@ -136,7 +139,7 @@ function conventionalChangelogWriter(context, options) {
cb(err);
}
}, function(cb) {
if (!options.doFlush && options.reverse) {
if (!options.doFlush && (options.reverse || neverGenerated)) {
cb(null);
return;
}
Expand Down
67 changes: 65 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ describe('conventionalChangelogWriter', function() {
}));
});

it('should not flush', function(done) {
it('should not flush when previous release is generated', function(done) {
var i = 0;

var upstream = through.obj();
Expand Down Expand Up @@ -573,6 +573,37 @@ describe('conventionalChangelogWriter', function() {
done();
}));
});

it('should not flush when it is the only potential release', function(done) {
var i = 0;

var upstream = through.obj();
upstream.write({
header: 'feat(scope): broadcast $destroy event on scope destruction',
body: null,
footer: null,
notes: [{
title: 'BREAKING CHANGE',
text: 'No backward compatibility.'
}],
references: [],
committerDate: '2015-04-07 14:17:05 +1000'
});
upstream.end();

upstream
.pipe(conventionalChangelogWriter({
version: 'v2.0.0'
}, {
doFlush: false
}))
.pipe(through(function() {
done(new Error('should not flush when it is the only potential release'));
}, function() {
expect(i).to.equal(0);
done();
}));
});
});

describe('when commits are reversed', function() {
Expand Down Expand Up @@ -710,7 +741,7 @@ describe('conventionalChangelogWriter', function() {
}));
});

it('should not flush', function(done) {
it('should not flush when previous release is generated', function(done) {
var i = 0;

var upstream = through.obj();
Expand Down Expand Up @@ -749,6 +780,38 @@ describe('conventionalChangelogWriter', function() {
}));
});
});

it('should not flush when it is the only potential release', function(done) {
var i = 0;

var upstream = through.obj();
upstream.write({
header: 'feat(scope): broadcast $destroy event on scope destruction',
body: null,
footer: null,
notes: [{
title: 'BREAKING CHANGE',
text: 'No backward compatibility.'
}],
references: [],
committerDate: '2015-04-07 14:17:05 +1000'
});
upstream.end();

upstream
.pipe(conventionalChangelogWriter({
version: 'v2.0.0'
}, {
reverse: true,
doFlush: false
}))
.pipe(through(function() {
done(new Error('should not flush when it is the only potential release'));
}, function() {
expect(i).to.equal(0);
done();
}));
});
});

it('should sort notes on `text` by default', function(done) {
Expand Down

0 comments on commit cc3b5db

Please sign in to comment.