1
1
/* eslint-disable prettier/prettier */
2
2
import parseCommitMessage from '../parseCommitMessage' ;
3
3
4
- const COMMIT_MESSAGE = 'Test commit message.' ;
4
+ import {
5
+ COMMIT_MESSAGE ,
6
+ ISSUE_NUMBER ,
7
+ COMMIT_TYPE ,
8
+ MULTI_LINE_COMMIT_MESSAGE ,
9
+ MULTI_LINE_COMMIT_MESSAGE_WITH_TYPE ,
10
+ MULTI_LINE_WIP_COMMIT_MESSAGES ,
11
+ MULTI_LINE_WIP_COMMIT_MESSAGE_WITH_ISSUE_NUMBERS ,
12
+ } from './parserTestData' ;
5
13
6
14
describe ( 'commitlintPluginGitHubTests' , ( ) => {
7
15
it ( 'should return correct issue numbers' , ( ) => {
@@ -79,6 +87,14 @@ describe('commitlintPluginGitHubTests', () => {
79
87
) . toEqual ( [ 123 , 45 ] ) ;
80
88
} ) ;
81
89
90
+ it ( 'should return correct issue numbers for multi-line commit messages' , ( ) => {
91
+ [
92
+ MULTI_LINE_COMMIT_MESSAGE ,
93
+ MULTI_LINE_COMMIT_MESSAGE_WITH_TYPE ,
94
+ MULTI_LINE_WIP_COMMIT_MESSAGE_WITH_ISSUE_NUMBERS ,
95
+ ] . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . issueNumbers ) . toEqual ( [ ISSUE_NUMBER ] ) ) ;
96
+ } ) ;
97
+
82
98
it ( 'should return raw issue numbers' , ( ) => {
83
99
// Non-numeric issue numbers prefix
84
100
expect (
@@ -103,6 +119,14 @@ describe('commitlintPluginGitHubTests', () => {
103
119
) . toEqual ( '#123,#45' ) ;
104
120
} ) ;
105
121
122
+ it ( 'should return correct raw issue numbers for multi-line commit messages' , ( ) => {
123
+ [
124
+ MULTI_LINE_COMMIT_MESSAGE ,
125
+ MULTI_LINE_COMMIT_MESSAGE_WITH_TYPE ,
126
+ MULTI_LINE_WIP_COMMIT_MESSAGE_WITH_ISSUE_NUMBERS ,
127
+ ] . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . rawIssueNumbers ) . toEqual ( `#${ ISSUE_NUMBER } ` ) ) ;
128
+ } ) ;
129
+
106
130
it ( 'should return no raw issue numbers' , ( ) => {
107
131
expect (
108
132
parseCommitMessage ( 'My commit message' ) . rawIssueNumbers
@@ -170,6 +194,11 @@ describe('commitlintPluginGitHubTests', () => {
170
194
) . toEqual ( '' ) ;
171
195
} ) ;
172
196
197
+ it ( 'should return no raw issue numbers for multi-line WIP commit messages without them' , ( ) => {
198
+ MULTI_LINE_WIP_COMMIT_MESSAGES
199
+ . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . rawIssueNumbers ) . toBeUndefined ) ;
200
+ } ) ;
201
+
173
202
it ( 'should return no issue numbers' , ( ) => {
174
203
// Missing issue numbers prefix entirely
175
204
expect (
@@ -294,7 +323,12 @@ describe('commitlintPluginGitHubTests', () => {
294
323
) . toEqual ( [ ] ) ;
295
324
} ) ;
296
325
297
- it ( 'should return correct type' , ( ) => {
326
+ it ( 'should return no issue numbers for multi-line WIP commit messages without them' , ( ) => {
327
+ MULTI_LINE_WIP_COMMIT_MESSAGES
328
+ . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . issueNumbers ) . toEqual ( [ ] ) ) ;
329
+ } ) ;
330
+
331
+ it ( 'should return the correct type' , ( ) => {
298
332
expect (
299
333
parseCommitMessage ( `(#1) ${ COMMIT_MESSAGE } ` ) . type
300
334
) . toBeUndefined ( ) ;
@@ -320,7 +354,11 @@ describe('commitlintPluginGitHubTests', () => {
320
354
) . toEqual ( 'chore' ) ;
321
355
} ) ;
322
356
323
- it ( 'should return an empty type for WIPs' , ( ) => {
357
+ it ( 'should return the correct type for multi-line commit messages with them' , ( ) => {
358
+ expect ( parseCommitMessage ( MULTI_LINE_COMMIT_MESSAGE_WITH_TYPE ) . type ) . toEqual ( COMMIT_TYPE ) ;
359
+ } ) ;
360
+
361
+ it ( 'should return no type for WIP commit messages' , ( ) => {
324
362
expect (
325
363
parseCommitMessage ( `(#123) WIP: ${ COMMIT_MESSAGE } ` ) . type
326
364
) . toBeUndefined ( ) ;
@@ -382,6 +420,14 @@ describe('commitlintPluginGitHubTests', () => {
382
420
) . toBeUndefined ( ) ;
383
421
} ) ;
384
422
423
+ it ( 'should return no type for multi-line commit messages without them' , ( ) => {
424
+ [
425
+ MULTI_LINE_COMMIT_MESSAGE ,
426
+ MULTI_LINE_WIP_COMMIT_MESSAGE_WITH_ISSUE_NUMBERS ,
427
+ ...MULTI_LINE_WIP_COMMIT_MESSAGES ,
428
+ ] . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . type ) . toBeUndefined ( ) ) ;
429
+ } ) ;
430
+
385
431
it ( 'should return correct WIP status' , ( ) => {
386
432
expect (
387
433
parseCommitMessage ( `(#1) ${ COMMIT_MESSAGE } ` ) . isWip
@@ -505,6 +551,20 @@ describe('commitlintPluginGitHubTests', () => {
505
551
) . toBe ( true ) ;
506
552
} ) ;
507
553
554
+ it ( 'should return the correct WIP status for multi-line non-WIP commit messages' , ( ) => {
555
+ [
556
+ MULTI_LINE_COMMIT_MESSAGE ,
557
+ MULTI_LINE_COMMIT_MESSAGE_WITH_TYPE ,
558
+ ] . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . isWip ) . toBe ( false ) ) ;
559
+ } ) ;
560
+
561
+ it ( 'should return the correct WIP status for multi-line WIP commit messages' , ( ) => {
562
+ [
563
+ MULTI_LINE_WIP_COMMIT_MESSAGE_WITH_ISSUE_NUMBERS ,
564
+ ...MULTI_LINE_WIP_COMMIT_MESSAGES ,
565
+ ] . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . isWip ) . toBe ( true ) ) ;
566
+ } ) ;
567
+
508
568
it ( 'should return correct subject' , ( ) => {
509
569
expect (
510
570
parseCommitMessage ( `(#1) ${ COMMIT_MESSAGE } ` ) . subject
@@ -604,4 +664,13 @@ describe('commitlintPluginGitHubTests', () => {
604
664
parseCommitMessage ( `WIP: ${ COMMIT_MESSAGE } (#22)` ) . subject
605
665
) . toEqual ( `${ COMMIT_MESSAGE } (#22)` ) ;
606
666
} ) ;
667
+
668
+ it ( 'should return the correct subject for multi-line commit messages' , ( ) => {
669
+ [
670
+ MULTI_LINE_COMMIT_MESSAGE ,
671
+ MULTI_LINE_COMMIT_MESSAGE_WITH_TYPE ,
672
+ MULTI_LINE_WIP_COMMIT_MESSAGE_WITH_ISSUE_NUMBERS ,
673
+ ...MULTI_LINE_WIP_COMMIT_MESSAGES ,
674
+ ] . forEach ( commitMessage => expect ( parseCommitMessage ( commitMessage ) . subject ) . toEqual ( COMMIT_MESSAGE ) ) ;
675
+ } ) ;
607
676
} ) ;
0 commit comments