Skip to content

Commit 20cf369

Browse files
committed
🐛 Fix a bug occuring when version is missing in configuration but passed as argument (#190)
1 parent b12dfec commit 20cf369

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/gitmoji-changelog-cli/src/cli.e2e.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ describe('generate changelog', () => {
6464
fs.writeFileSync(pkg, JSON.stringify(content))
6565

6666
const output = gitmojiChangelog()
67+
console.log(output.toString('utf8'))
6768

6869
expect(output.toString('utf8')).includes(['Cannot retrieve the version from your configuration'])
6970
})
@@ -411,6 +412,19 @@ describe('generate changelog', () => {
411412
expect(getChangelog()).includes(['1.0.0', '1.2.0'])
412413
})
413414

415+
it('should work by passing release as argument without package.json or configuration file', async () => {
416+
const pkg = path.join(testDir, 'package.json')
417+
const { version, ...content } = JSON.parse(fs.readFileSync(pkg).toString('utf8'))
418+
fs.writeFileSync(pkg, JSON.stringify(content))
419+
420+
await makeChanges('file1')
421+
await commit(':sparkles: Add some file')
422+
const output = gitmojiChangelog('1.0.0')
423+
console.log(output.toString('utf8'))
424+
425+
expect(getChangelog()).includes(['1.0.0'])
426+
})
427+
414428
it('should display an error if requested version isn\'t semver', async () => {
415429
const output = gitmojiChangelog('awesomeversion')
416430

packages/gitmoji-changelog-cli/src/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function main(options = {}) {
5656
throw Error(`Cannot retrieve configuration for preset ${options.preset}.`)
5757
}
5858

59-
if (!projectInfo.version) {
59+
if (!projectInfo.version && options.release === 'from-package') {
6060
throw Error('Cannot retrieve the version from your configuration. Check it or you can do "gitmoji-changelog <wanted version>".')
6161
}
6262
} catch (e) {

0 commit comments

Comments
 (0)