forked from JPeer264/node-semantic-git-commit-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestions.js
More file actions
167 lines (121 loc) · 4.92 KB
/
Copy pathquestions.js
File metadata and controls
167 lines (121 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import test from 'ava';
import fs from 'fs-extra';
import os from 'os';
import path from 'path';
import { withEmoji, withoutEmoji } from './fixtures/questions';
import getConfig from '../lib/getConfig';
import questions, {
choices,
initMessage,
initQuestion,
} from '../lib/questions';
const cwd = process.cwd();
const date = new Date();
const homedir = os.homedir();
const fixtures = path.join(cwd, 'test', 'fixtures');
const datetime = date.toISOString().slice(0, 10);
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 4);
let globalExist = false;
// rename global .sgcrc
test.before(() => {
// rename global config
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
globalExist = true;
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}-${datetime}.back`));
}
// rename local sgcrc
fs.renameSync(path.join(cwd, '.sgcrc'), path.join(cwd, '.sgcrc_default'));
});
test.after.always(() => {
// rename global config
if (globalExist) {
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}-${datetime}.back`), path.join(homedir, '.sgcrc'));
}
// rename local sgcrc
fs.renameSync(path.join(cwd, '.sgcrc_default'), path.join(cwd, '.sgcrc'));
});
test('choices are rendered without emoji', (t) => {
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
const choicesList = choices(sgc);
t.deepEqual(choicesList, withoutEmoji);
});
test('choices are rendered with emoji (default)', (t) => {
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
sgc.emoji = true;
const choicesList = choices(sgc);
t.deepEqual(choicesList, withEmoji);
});
test('check the values of the question object', (t) => {
const config = getConfig();
const questionsList = questions(config);
t.is(typeof questionsList, 'object');
});
test('TYPES | upperCase (default)', (t) => {
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
const choicesList = choices(sgc);
t.is(choicesList[0].value, 'Add:');
});
test('TYPES | lowerCase', (t) => {
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
sgc.lowercaseTypes = true;
const choicesList = choices(sgc);
t.is(choicesList[0].value, 'add:');
});
test('SCOPE | check if scope is off by default', (t) => {
const config = getConfig();
const questionsList = questions(config);
t.is(questionsList[1].when(), false);
});
test('SCOPE | check if scope filters correctly', (t) => {
const config = getConfig();
const questionsList = questions(config);
t.is(questionsList[1].filter('answer'), '(answer)');
t.is(questionsList[1].filter(''), '');
});
test('SCOPE | check if scope validates correctly', (t) => {
const config = getConfig();
const questionsList = questions(config);
t.is(questionsList[1].validate('not correct'), 'No whitespaces allowed');
t.is(questionsList[1].validate('correct'), true);
});
test('COMMIT | validate functions in questions', (t) => {
const config = getConfig();
const questionsList = questions(config);
t.is(questionsList[2].validate('', 'Fix: '), 'The commit message is not allowed to be empty');
t.is(questionsList[2].validate('input text', 'Fix: '), true);
t.is(questionsList[2].validate('This message has over 72 characters. So this test will definitely fail. I can guarantee that I am telling the truth', 'Fix: '), 'The commit message is not allowed to be longer as 72 character, but is 125 character long. Consider writing a body.\n');
});
test('COMMIT | when and default functions in questions', (t) => {
const config = getConfig();
const questionsList = questions(config);
t.is(questionsList[4].when({ body: true }), true);
t.is(questionsList[4].when({ body: false }), false);
t.deepEqual(questionsList[4].default({ type: ':wrench: Chore:', description: 'This is a commit message!', body: true }), ':wrench: Chore: This is a commit message!\n\n\n');
});
test('CONFIRM EDITOR | check if it shows if it has to', (t) => {
const config = getConfig();
const questionsList = questions(config);
t.is(questionsList[3].when(), config.body);
});
test('INIT COMMIT | check message without emoji', (t) => {
const config = getConfig();
const message = initMessage(config);
t.is(message, config.initialCommit.message);
});
test('INIT COMMIT | check message with emoji', (t) => {
const config = getConfig();
config.emoji = true;
const message = initMessage(config);
t.is(message, `${config.initialCommit.emoji} ${config.initialCommit.message}`);
});
test('INIT QUESTION | check message without emoji', (t) => {
const config = getConfig();
const question = initQuestion(config);
t.is(question.message, `Confirm as first commit message: "${config.initialCommit.message}"`);
});
test('INIT QUESTION | check message with emoji', (t) => {
const config = getConfig();
config.emoji = true;
const question = initQuestion(config);
t.is(question.message, `Confirm as first commit message: "${config.initialCommit.emoji} ${config.initialCommit.message}"`);
});