From 20cf3690dd0acd0712f3068368c80ade1422cd5b Mon Sep 17 00:00:00 2001 From: Yvonnick FRIN Date: Wed, 23 Sep 2020 09:30:29 +0200 Subject: [PATCH] :bug: Fix a bug occuring when version is missing in configuration but passed as argument (#190) --- packages/gitmoji-changelog-cli/src/cli.e2e.js | 14 ++++++++++++++ packages/gitmoji-changelog-cli/src/cli.js | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/gitmoji-changelog-cli/src/cli.e2e.js b/packages/gitmoji-changelog-cli/src/cli.e2e.js index 61c33d3..1b2d5f1 100644 --- a/packages/gitmoji-changelog-cli/src/cli.e2e.js +++ b/packages/gitmoji-changelog-cli/src/cli.e2e.js @@ -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']) }) @@ -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') diff --git a/packages/gitmoji-changelog-cli/src/cli.js b/packages/gitmoji-changelog-cli/src/cli.js index 348d784..d519d82 100644 --- a/packages/gitmoji-changelog-cli/src/cli.js +++ b/packages/gitmoji-changelog-cli/src/cli.js @@ -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 ".') } } catch (e) {