From f6240b114f71a37bd6d2eba4ea7a78183bbd8dee Mon Sep 17 00:00:00 2001 From: donmahallem Date: Thu, 9 Jan 2020 19:09:24 +0100 Subject: [PATCH] Fix issue #255 (#256) * fix issue #255 * added test to _getReleaseBlocks to handle just one tag too --- lib/src/Gren.js | 2 +- test/Gren.spec.js | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/src/Gren.js b/lib/src/Gren.js index 9ba4ced5..776da091 100644 --- a/lib/src/Gren.js +++ b/lib/src/Gren.js @@ -1127,7 +1127,7 @@ class Gren { this._validateRequiredTagsExists(tags, this.options.tags); const releaseDates = this._sortReleasesByDate(await Promise.all(this._getTagDates(tags))); - const selectedTags = (this._getSelectedTags(releaseDates) || [releaseDates[0], releaseDates[1]]); + const selectedTags = (this._getSelectedTags(releaseDates) || (releaseDates.length > 1 ? [releaseDates[0], releaseDates[1]] : releaseDates)); loaded(`Tags found: ${selectedTags.map(({ name }) => name).join(', ')}`); diff --git a/test/Gren.spec.js b/test/Gren.spec.js index 022e3dfc..8423d4fc 100644 --- a/test/Gren.spec.js +++ b/test/Gren.spec.js @@ -610,17 +610,32 @@ describe('Gren', () => { }); }); - it('_getReleaseBlocks', done => { - gren.options.tags = ['0.12.0', '0.11.0']; - gren._getReleaseBlocks() - .then(releaseBlocks => { - assert.isArray(releaseBlocks, 'The releaseBlocks is an Array'); - releaseBlocks.forEach(block => { - assert.hasAllKeys(block, ['id', 'release', 'name', 'published_at', 'body']); - }); - done(); - }) - .catch(err => done(err)); - }).timeout(10000); + describe('_getReleaseBlocks', () => { + it('more than one tag', done => { + gren.options.tags = ['0.12.0', '0.11.0']; + gren._getReleaseBlocks() + .then(releaseBlocks => { + assert.isArray(releaseBlocks, 'The releaseBlocks is an Array'); + releaseBlocks.forEach(block => { + assert.hasAllKeys(block, ['id', 'release', 'name', 'published_at', 'body']); + }); + done(); + }) + .catch(err => done(err)); + }).timeout(10000); + + it('just one tag', done => { + gren.options.tags = ['0.11.0']; + gren._getReleaseBlocks() + .then(releaseBlocks => { + assert.isArray(releaseBlocks, 'The releaseBlocks is an Array'); + releaseBlocks.forEach(block => { + assert.hasAllKeys(block, ['id', 'release', 'name', 'published_at', 'body']); + }); + done(); + }) + .catch(err => done(err)); + }).timeout(10000); + }); }); });