Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
test: πŸ’ update format, two new tests (custom, dynamic custom)
Browse files Browse the repository at this point in the history
βœ… Closes: 81
  • Loading branch information
JeromeFitz committed Feb 27, 2021
1 parent 54b32ed commit d8096aa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
1 change: 1 addition & 0 deletions test/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
79 changes: 53 additions & 26 deletions test/formatCommitMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<type><(scope)>: <emoji><subject>',
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: {
Expand Down Expand Up @@ -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]');
});
});

0 comments on commit d8096aa

Please sign in to comment.