From 888617bff0b3e54689aab04ce417e0e42953c6b6 Mon Sep 17 00:00:00 2001 From: Nick Balestra Date: Sun, 23 Jul 2017 15:45:54 +0100 Subject: [PATCH] fix(CLI): correctly exit with 1 when validation fails Addresses a bug introduces with the PR #92 where the CLI wasn't exiting the process anymore in case of error --- lib/cli.js | 12 ++++-------- test/cli.test.js | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 26e0161..15c5f03 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -87,14 +87,10 @@ if (process.argv.join('').indexOf('mocha') === -1) { var validate = function (commit) { if (!validateMessage(commit.message) && commit.errorLog) { fs.appendFileSync(commit.errorLog, commit.message + '\n'); + process.exit(1); + } else { + process.exit(0); } }; - - try { - validate(getCommit()); - process.exit(0); - } catch (err) { - console.error(err); - process.exit(1); - } + validate(getCommit()); } diff --git a/test/cli.test.js b/test/cli.test.js index 1cc2cf6..2697562 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -73,7 +73,7 @@ describe('cli', function() { var result = executeCliBySource(cliSource, commitMessage); expect(result.stdout.toString()).to.eql('Aborting commit due to empty commit message.\n'); expect(result.stderr.toString()).to.eql(''); - expect(result.status).to.eql(0); + expect(result.status).to.eql(1); }); }); } @@ -87,7 +87,7 @@ describe('cli', function() { 'Please fix your commit message (and consider using http://npm.im/commitizen)\n\n' ].join('')); expect(result.stderr.toString()).to.eql('INVALID COMMIT MSG: does not match "(): " !\n'); - expect(result.status).to.eql(0); + expect(result.status).to.eql(1); }); }); @@ -103,7 +103,7 @@ describe('cli', function() { 'INVALID COMMIT MSG: "patch" is not allowed type ! ', 'Valid types are: feat, fix, docs, style, refactor, perf, test, chore, revert, custom\n' ].join('')); - expect(result.status).to.eql(0); + expect(result.status).to.eql(1); }); }); });