Skip to content

Commit 99527bf

Browse files
committed
✅ Test: add test for new rules
1 parent 67525e2 commit 99527bf

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

test/fixtures/.sgcrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@
55
"type": "Add:",
66
"description": "Files added"
77
}
8+
],
9+
"rules": [
10+
{
11+
"max-char-commit-message": true,
12+
"max-char": 72,
13+
"min-char": 10,
14+
"end-with-dot": false
15+
}
816
]
917
}

test/prompConfig.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,38 @@ test('get configuration file equals .sgcrc_default', (t) => {
1111
t.deepEqual(getConfig(), json.readToObjSync(path.join(cwd, '.sgcrc_default')));
1212
});
1313

14-
test('choices are the same as choices generated from .sgcrc_default', (t) => {
15-
const sgc = getConfig();
16-
const configuration = getConfig();
17-
const choicesList = choices(configuration);
14+
test('choices are the same as choices generated from .sgcrc_default', async (t) => {
15+
const sgc = await getConfig();
16+
const choicesList = await choices(sgc);
1817
const choicesArray = [];
1918

20-
Promise.resolve(() => {
21-
sgc.types.forEach((type) => {
22-
const emoji = `${type.emoji} ` || '';
23-
const configType = type.type;
24-
const description = type.description || '';
25-
26-
choicesArray.push({
27-
value: emoji + configType,
28-
name: `${chalk.bold(configType)} ${description}`,
29-
});
30-
}).then(() => {
31-
t.deepEqual(choicesList, choicesArray);
19+
sgc.types.forEach((type) => {
20+
const emoji = `${type.emoji} ` || '';
21+
const configType = type.type;
22+
const description = type.description || '';
23+
24+
choicesArray.push({
25+
value: emoji + configType,
26+
name: `${chalk.bold(configType)} ${description}`,
3227
});
3328
});
29+
30+
t.deepEqual(choicesList, await choicesArray);
3431
});
3532

36-
test('check the values of the question object', (t) => {
37-
const configuration = getConfig();
38-
const choicesList = choices(configuration);
39-
const questionsList = questions(choicesList);
33+
test('check the values of the question object', async (t) => {
34+
const configuration = await getConfig();
35+
const choicesList = await choices(configuration);
36+
const questionsList = await questions(choicesList, configuration);
4037

4138
t.deepEqual(typeof questionsList, 'object');
4239
});
4340

44-
test('validate functions in questions', (t) => {
45-
const configuration = getConfig();
46-
const choicesList = choices(configuration);
47-
const questionsList = questions(choicesList);
41+
test('validate functions in questions', async (t) => {
42+
const configuration = await getConfig();
43+
const choicesList = await choices(configuration);
44+
const questionsList = await questions(choicesList, configuration);
4845

4946
t.deepEqual(questionsList[1].validate('input text'), true);
50-
t.deepEqual(questionsList[1].validate(), 'A commit message is mandatory!');
47+
t.deepEqual(questionsList[1].validate('This message has over 72 characters so test will fails OMG really, it is so looooooooooooooong'), 'The commit message is not allowed to be longer as 72. Consider writing a body.');
5148
});

test/rulesConfig.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import test from 'ava';
2+
import { checkRulesMaxLength, checkRulesMinLength, checkRulesEndWithDot } from '../lib/rulesConfig';
3+
4+
test('checkRulesMaxLength', (t) => {
5+
t.deepEqual(checkRulesMaxLength('1234'), true);
6+
t.deepEqual(checkRulesMaxLength('This is a very loooooooooooooooooooooooooong commit message with over 72 characters'), false);
7+
});
8+
9+
test('checkRulesMinLength', (t) => {
10+
t.deepEqual(checkRulesMinLength('1234'), false);
11+
t.deepEqual(checkRulesMinLength('This is a a commit message'), true);
12+
});
13+
14+
test('checkRulesEndWithDot', (t) => {
15+
t.deepEqual(checkRulesEndWithDot('1234'), true);
16+
t.deepEqual(checkRulesEndWithDot('This is a very a commit message with a dot.'), false);
17+
});

0 commit comments

Comments
 (0)