1 | const buildCommit = require('../buildCommit');
|
2 |
|
3 | describe('buildCommit()', () => {
|
4 | const answers = {
|
5 | type: 'feat',
|
6 | scope: 'app',
|
7 | subject: 'this is a new feature',
|
8 | };
|
9 |
|
10 | it('subject with default subject separator', () => {
|
11 | const options = {};
|
12 | expect(buildCommit(answers, options)).toEqual('feat(app): this is a new feature');
|
13 | });
|
14 |
|
15 | it('subject with custom subject separator option', () => {
|
16 | const options = {
|
17 | subjectSeparator: ' - ',
|
18 | };
|
19 | expect(buildCommit(answers, options)).toEqual('feat(app) - this is a new feature');
|
20 | });
|
21 |
|
22 | it('subject 1 empty character separator', () => {
|
23 | const options = {
|
24 | subjectSeparator: ' ',
|
25 | };
|
26 | expect(buildCommit(answers, options)).toEqual('feat(app) this is a new feature');
|
27 | });
|
28 |
|
29 | describe('without scope', () => {
|
30 | it('subject without scope', () => {
|
31 | const answersNoScope = {
|
32 | type: 'feat',
|
33 | subject: 'this is a new feature',
|
34 | };
|
35 | const options = {};
|
36 | expect(buildCommit(answersNoScope, options)).toEqual('feat: this is a new feature');
|
37 | });
|
38 |
|
39 | it('subject without scope', () => {
|
40 | const answersNoScope = {
|
41 | type: 'feat',
|
42 | subject: 'this is a new feature',
|
43 | };
|
44 | const options = {
|
45 | subjectSeparator: ' - ',
|
46 | };
|
47 | expect(buildCommit(answersNoScope, options)).toEqual('feat - this is a new feature');
|
48 | });
|
49 | });
|
50 |
|
51 | describe('type prefix and type suffix', () => {
|
52 | it('subject with both', () => {
|
53 | const answersNoScope = {
|
54 | type: 'feat',
|
55 | subject: 'this is a new feature',
|
56 | };
|
57 | const options = {
|
58 | typePrefix: '[',
|
59 | typeSuffix: ']',
|
60 | subjectSeparator: ' ',
|
61 | };
|
62 | expect(buildCommit(answersNoScope, options)).toEqual('[feat] this is a new feature');
|
63 | });
|
64 | });
|
65 |
|
66 | describe('pipe replaced with new line', () => {
|
67 |
|
68 | const expecteMessage = `feat: this is a new feature\n
|
69 | body with new line now
|
70 | body line2
|
71 |
|
72 | ISSUES CLOSED: footer with new line
|
73 | line 2`;
|
74 |
|
75 | it('should add breakline for body and footer', () => {
|
76 | const answersNoScope = {
|
77 | type: 'feat',
|
78 | subject: 'this is a new feature',
|
79 | body: 'body with new line now|body line2',
|
80 | footer: 'footer with new line|line 2',
|
81 | };
|
82 | const options = {};
|
83 |
|
84 | expect(buildCommit(answersNoScope, options)).toEqual(expecteMessage);
|
85 | });
|
86 |
|
87 | it('should override breakline character with option breaklineChar', () => {
|
88 | const answersNoScope = {
|
89 | type: 'feat',
|
90 | subject: 'this is a new feature',
|
91 | body: 'body with new line now@@@body line2',
|
92 | footer: 'footer with new line@@@line 2',
|
93 | };
|
94 | const options = {
|
95 | breaklineChar: '@@@',
|
96 | };
|
97 |
|
98 | expect(buildCommit(answersNoScope, options)).toEqual(expecteMessage);
|
99 | });
|
100 | });
|
101 | });
|