Skip to content

Commit

Permalink
Fix: take formattedMessage if editor is undefined (closes #77) (#78)
Browse files Browse the repository at this point in the history
(ref: #77)
  • Loading branch information
JPeer264 committed Apr 4, 2019
1 parent 54ea475 commit dc0e5d7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/helpers/formatters.js
Expand Up @@ -27,7 +27,11 @@ export const formatMessage = (answers, argv) => {

const type = combineTypeScope(combinedAnswers.type, combinedAnswers.scope);
const formattedMessage = `${type} ${(combinedAnswers.message || '').trim()}`;
const result = answers.body ? combinedAnswers.editor : formattedMessage;
let result = formattedMessage;

if (combinedAnswers.editor) {
result = answers.body ? combinedAnswers.editor : formattedMessage;
}

return result;
};
Empty file modified lib/index.js 100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -4,8 +4,8 @@
"description": "A CLI for semantic git commits",
"main": "dest",
"bin": {
"semantic-git-commit": "dest/index.js",
"sgc": "dest/index.js"
"semantic-git-commit": "./dest/index.js",
"sgc": "./dest/index.js"
},
"scripts": {
"pretest": "npm run lint & npm run babel",
Expand Down
41 changes: 41 additions & 0 deletions test/helper/formatters.js
Expand Up @@ -93,3 +93,44 @@ test('FORMATMESSAGE | should format message with more argv overrides', (t) => {

t.is(message, 'myTypeOverwrite (myScopeOverwrite): messageOverwrite');
});

test('FORMATMESSAGE | should format when editor is undefined but body is set to true', (t) => {
const message = formatMessage(
{
type: 'myType',
scope: 'myScope',
message: 'message',
body: true,
},
);

t.is(message, 'myType (myScope): message');
});

test('FORMATMESSAGE | should take editor when editor is not undefined and body is set to true', (t) => {
const message = formatMessage(
{
type: 'myType',
scope: 'myScope',
message: 'message',
body: true,
editor: 'take this',
},
);

t.is(message, 'take this');
});

test('FORMATMESSAGE | should format when editor is not undefined and body is set to false', (t) => {
const message = formatMessage(
{
type: 'myType',
scope: 'myScope',
message: 'message',
body: false,
editor: 'take this',
},
);

t.is(message, 'myType (myScope): message');
});

0 comments on commit dc0e5d7

Please sign in to comment.