Skip to content

Commit

Permalink
🐛 Fix a bug occuring when version is missing in configuration but pas…
Browse files Browse the repository at this point in the history
…sed as argument (#190)
  • Loading branch information
frinyvonnick committed Sep 25, 2020
1 parent b12dfec commit 20cf369
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/gitmoji-changelog-cli/src/cli.e2e.js
Expand Up @@ -64,6 +64,7 @@ describe('generate changelog', () => {
fs.writeFileSync(pkg, JSON.stringify(content))

const output = gitmojiChangelog()
console.log(output.toString('utf8'))

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

it('should work by passing release as argument without package.json or configuration file', async () => {
const pkg = path.join(testDir, 'package.json')
const { version, ...content } = JSON.parse(fs.readFileSync(pkg).toString('utf8'))
fs.writeFileSync(pkg, JSON.stringify(content))

await makeChanges('file1')
await commit(':sparkles: Add some file')
const output = gitmojiChangelog('1.0.0')
console.log(output.toString('utf8'))

expect(getChangelog()).includes(['1.0.0'])
})

it('should display an error if requested version isn\'t semver', async () => {
const output = gitmojiChangelog('awesomeversion')

Expand Down
2 changes: 1 addition & 1 deletion packages/gitmoji-changelog-cli/src/cli.js
Expand Up @@ -56,7 +56,7 @@ async function main(options = {}) {
throw Error(`Cannot retrieve configuration for preset ${options.preset}.`)
}

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

0 comments on commit 20cf369

Please sign in to comment.