Skip to content

Commit b70f814

Browse files
authored
Merge pull request #23 from JPeer264/feature/removeemojies
Feature/removeemojies
2 parents 3326e5c + 039b1d5 commit b70f814

File tree

6 files changed

+63
-28
lines changed

6 files changed

+63
-28
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,25 @@ $ sgc
4141
You can even create a global config. Just go to your users home and create a `.sgcrc`. The global config will be triggered if no project configurations are present.
4242

4343
**Options:**
44+
- [emojies](#emojies)
4445
- [types](#types)
4546
- [rules](#rules)
4647

48+
### emojies
49+
50+
**Type:** `boolean`
51+
52+
**Default:** `true`
53+
54+
A boolean to enable emojies at the beginning of a commit message
55+
56+
Example:
57+
```json
58+
{
59+
"emojies": true
60+
}
61+
```
62+
4763
### types
4864

4965
> Types will define your git commits.

lib/promptConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const choices = (configuration) => {
55
const choicesList = [];
66

77
configuration.types.forEach((type) => {
8-
const emoji = `${type.emoji} ` || '';
8+
const isEmojies = configuration.emojies === undefined ? true : configuration.emojies;
9+
const emoji = isEmojies && type.emoji ? `${type.emoji} ` : '';
910
const configType = type.type;
1011
const description = type.description || '';
1112

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"pretest": "npm run lint & npm run babel",
12-
"test": "nyc ava",
12+
"test": "nyc ava -s",
1313
"lint": "eslint lib test",
1414
"babel": "babel lib -d dest",
1515
"prepublish": "npm run babel",

test/fixtures/questions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import chalk from 'chalk';
2+
3+
const withEmoji = [
4+
{
5+
name: `${chalk.bold('Add:')} Files added`,
6+
value: ':emo: Add:',
7+
},
8+
];
9+
10+
const withoutEmoji = [
11+
{
12+
name: `${chalk.bold('Add:')} Files added`,
13+
value: 'Add:',
14+
},
15+
];
16+
17+
export {
18+
withEmoji,
19+
withoutEmoji,
20+
};

test/getConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test('read config from a .sgcrc_default', (t) => {
3838
t.deepEqual(getConfig(), json.readToObjSync(path.join(cwd, '.sgcrc_default')));
3939
});
4040

41-
test('read config from package.json', (t) => {
41+
test.serial('read config from package.json', (t) => {
4242
const sgcrc = json.readToObjSync(path.join(fixtures, '.sgcrc'));
4343
const packageJson = json.readToObjSync(path.join(cwd, 'package.json'));
4444

test/prompConfig.js renamed to test/promptConfig.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import os from 'os';
22
import test from 'ava';
33
import path from 'path';
4-
import chalk from 'chalk';
54
import fs from 'fs-extra';
65
import json from 'json-extra';
76

87
import getConfig from '../lib/getConfig';
98
import { choices, questions } from '../lib/promptConfig';
9+
import { withEmoji, withoutEmoji } from './fixtures/questions';
1010

1111
const cwd = process.cwd();
12-
const homedir = os.homedir();
1312
const date = new Date();
13+
const homedir = os.homedir();
14+
const fixtures = path.join(cwd, 'test', 'fixtures');
1415
const datetime = date.toISOString().slice(0, 10);
1516
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 4);
1617

1718
let globalExist = false;
1819

19-
2020
// rename global .sgcrc
2121
test.before(() => {
2222
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
@@ -35,37 +35,35 @@ test('get configuration file equals .sgcrc_default', (t) => {
3535
t.deepEqual(getConfig(), json.readToObjSync(path.join(cwd, '.sgcrc_default')));
3636
});
3737

38-
test('choices are the same as choices generated from .sgcrc_default', async (t) => {
39-
const sgc = await getConfig();
40-
const choicesList = await choices(sgc);
41-
const choicesArray = [];
38+
test('choices are rendered without emojis', (t) => {
39+
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
40+
41+
sgc.emojies = false;
42+
43+
const choicesList = choices(sgc);
4244

43-
sgc.types.forEach((type) => {
44-
const emoji = `${type.emoji} ` || '';
45-
const configType = type.type;
46-
const description = type.description || '';
45+
t.deepEqual(choicesList, withoutEmoji);
46+
});
4747

48-
choicesArray.push({
49-
value: emoji + configType,
50-
name: `${chalk.bold(configType)} ${description}`,
51-
});
52-
});
48+
test('choices are rendered with emojis (default)', (t) => {
49+
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
50+
const choicesList = choices(sgc);
5351

54-
t.deepEqual(choicesList, await choicesArray);
52+
t.deepEqual(choicesList, withEmoji);
5553
});
5654

57-
test('check the values of the question object', async (t) => {
58-
const configuration = await getConfig();
59-
const choicesList = await choices(configuration);
60-
const questionsList = await questions(choicesList, configuration);
55+
test('check the values of the question object', (t) => {
56+
const configuration = getConfig();
57+
const choicesList = choices(configuration);
58+
const questionsList = questions(choicesList, configuration);
6159

6260
t.deepEqual(typeof questionsList, 'object');
6361
});
6462

65-
test('validate functions in questions', async (t) => {
66-
const configuration = await getConfig();
67-
const choicesList = await choices(configuration);
68-
const questionsList = await questions(choicesList, configuration);
63+
test('validate functions in questions', (t) => {
64+
const configuration = getConfig();
65+
const choicesList = choices(configuration);
66+
const questionsList = questions(choicesList, configuration);
6967

7068
t.deepEqual(questionsList[1].validate('input text'), true);
7169
t.deepEqual(questionsList[1].validate('This message has over 72 characters. So this test will definitely fail. I can guarantee that I am telling the truth'), 'The commit message is not allowed to be longer as 72. Consider writing a body.\n');

0 commit comments

Comments
 (0)