diff --git a/test/__snapshots__/cli.test.js.snap b/test/__snapshots__/cli.test.js.snap index 9dedd3f1..397cac20 100644 --- a/test/__snapshots__/cli.test.js.snap +++ b/test/__snapshots__/cli.test.js.snap @@ -10,6 +10,7 @@ exports[`git-cz --help 1`] = ` -h, --help show usage information -v, --version print version info and exit --disable-emoji don't add emoji to commit title + --format custom formatting options for subject --non-interactive run git-cz in non-interactive mode non-interactive mode options: diff --git a/test/formatCommitMessage.test.js b/test/formatCommitMessage.test.js index 24562efe..3cffa4a2 100644 --- a/test/formatCommitMessage.test.js +++ b/test/formatCommitMessage.test.js @@ -4,33 +4,15 @@ const formatCommitMessage = require('../lib/formatCommitMessage'); const defaultConfig = { disableEmoji: false, - format: '{type} {scope}: {subject}', + format: '{type}{scope}: {emoji}{subject}', breakingChangePrefix: '๐Ÿงจ ', closedIssuePrefix: 'โœ… ', closedIssueMessage: 'Closes: ', commitMessageFormat: '<(scope)>: ', - list: [ - 'test', - 'feat', - 'fix', - 'chore', - 'docs', - 'refactor', - 'style', - 'ci', - 'perf' - ], + list: ['test', 'feat', 'fix', 'chore', 'docs', 'refactor', 'style', 'ci', 'perf'], maxMessageLength: 64, minMessageLength: 3, - questions: [ - 'type', - 'scope', - 'subject', - 'body', - 'breaking', - 'issues', - 'lerna' - ], + questions: ['type', 'scope', 'subject', 'body', 'breaking', 'issues', 'lerna'], scopes: [], types: { chore: { @@ -101,21 +83,66 @@ const defaultState = { }; describe('formatCommitMessage()', () => { - it('formats correctly a basic message ("feat" type, emoji, and message)', () => { - const message = formatCommitMessage({...defaultState}); + it('does not include emoji, if emojis disabled in config (no scope)', () => { + const message = formatCommitMessage({ + ...defaultState, + config: { + ...defaultConfig, + disableEmoji: true + } + }); + + expect(message).equal('feat: First commit'); + }); + + it('does not include emoji, if emojis disabled in config (with scope)', () => { + const message = formatCommitMessage({ + ...defaultState, + answers: { + ...defaultState.answers, + scope: 'init' + }, + config: { + ...defaultConfig, + disableEmoji: true + } + }); + + expect(message).equal('feat(init): First commit'); + }); + + it('does not include emoji, if emojis disabled in config (custom)', () => { + const message = formatCommitMessage({ + ...defaultState, + answers: { + ...defaultState.answers, + scope: 'init' + }, + config: { + ...defaultConfig, + format: '{subject} :{scope}{type}', + disableEmoji: true + } + }); - expect(message).to.equal('feat: ๐ŸŽธ First commit'); + expect(message).equal('First commit :(init)feat'); }); - it('does not include emoji, if emojis disabled in config', () => { + it('does not include emoji, if emojis disabled in config (dynamic custom)', () => { + const isDynamic = true; const message = formatCommitMessage({ ...defaultState, + answers: { + ...defaultState.answers, + scope: 'init' + }, config: { ...defaultConfig, + format: `{subject} :{scope}{type}${isDynamic && ' [skip ci]'}`, disableEmoji: true } }); - expect(message).to.equal('feat: First commit'); + expect(message).equal('First commit :(init)feat [skip ci]'); }); });