@@ -87,7 +87,7 @@ describe('cz-customizable-ghooks', () => {
8787 types : [
8888 { value : 'feat' , name : 'feat: A new feature' } ,
8989 { value : 'fix' , name : 'fix: A bug fix' } ,
90- { value : 'docs' , name : 'docs: Documentation only changes' } ,
90+ { value : 'docs' , name : 'docs: Documentation only changes' }
9191 ] ,
9292
9393 scopes : [
@@ -117,7 +117,7 @@ describe('cz-customizable-ghooks', () => {
117117 } ;
118118
119119 const testData = [
120- { msg : 'feat(customScope): this ok' , expectedResult : false } ,
120+ { msg : 'feat(customScope): this not ok' , expectedResult : false } ,
121121 { msg : 'docs(custom): docs has an override scope' , expectedResult : true } ,
122122 { msg : 'fix(merge): and so does fix' , expectedResult : true } ,
123123 { msg : 'docs(invalidCustom): not a valid custom scope' , expectedResult : false }
@@ -139,6 +139,66 @@ describe('cz-customizable-ghooks', () => {
139139 } ) ;
140140 } ) ;
141141
142+
143+ describe ( 'with no scopes but with scope overridesForTypes' , ( ) => {
144+ let baseScopes = [
145+ { name : 'merge' } ,
146+ { name : 'style' } ,
147+ { name : 'e2eTest' } ,
148+ { name : 'unitTest' }
149+ ] ;
150+ let config = {
151+ types : [
152+ { value : 'feat' , name : 'feat: A new feature' } ,
153+ { value : 'fix' , name : 'fix: A bug fix' } ,
154+ { value : 'docs' , name : 'docs: Documentation only changes' }
155+ ] ,
156+
157+ scopeOverrides : {
158+ fix : baseScopes ,
159+ docs : baseScopes . concat ( { name : 'custom' } )
160+ } ,
161+ allowCustomScopes : false ,
162+ allowBreakingChanges : [ 'feat' , 'fix' ] ,
163+ process : {
164+ exit : ( ) => { }
165+ }
166+ } ;
167+
168+ const testData = [
169+ { msg : 'fix(merge): this ok' , expectedResult : true } ,
170+ { msg : 'docs(custom): this has an override scope' , expectedResult : true } ,
171+ { msg : 'feat(merge): no scopes for feature' , expectedResult : false } ,
172+ { msg : 'docs(invalidCustom): not a valid custom scope' , expectedResult : false }
173+ ] ;
174+
175+ let consoleData = '' ;
176+
177+ beforeEach ( ( ) => {
178+ module = rewire ( '../lib/index' ) ;
179+ module . __set__ ( {
180+ czConfig : config ,
181+ console : {
182+ log : ( data ) => consoleData += data ,
183+ error : ( data ) => consoleData += data
184+ }
185+ } ) ;
186+ } ) ;
187+
188+ afterEach ( ( ) => {
189+ consoleData = '' ;
190+ } ) ;
191+
192+ it ( 'should accept commit messages which match the rules in the config' , ( ) => {
193+ testData . forEach ( test => {
194+ let lines = test . msg . split ( '\n' ) ;
195+
196+ assert . equal ( module . validateMessage ( lines [ 0 ] , test . msg ) , test . expectedResult , test . msg ) ; // + '\n' + consoleData);
197+ } ) ;
198+ } ) ;
199+ } ) ;
200+
201+
142202 describe ( 'error conditions' , ( ) => {
143203 let consoleData = '' ;
144204
@@ -213,7 +273,7 @@ describe('cz-customizable-ghooks', () => {
213273 } ) ;
214274 } ) ;
215275
216- it ( 'should accept commit messages which match the rules in the config' , ( ) => {
276+ it ( 'should reject commit messages which do not match the rules in the config' , ( ) => {
217277 testData . forEach ( test => {
218278 module . __set__ ( { czConfig : test . config } ) ;
219279
@@ -307,6 +367,7 @@ describe('cz-customizable-ghooks', () => {
307367 const commitMsgFileName = __dirname + '/COMMIT_MSG' ;
308368 let consoleData = '' ;
309369 let exitCode ;
370+ let execCall = '' ;
310371 let revert1 , revert2 = ( ) => { } ;
311372
312373 beforeEach ( ( ) => {
@@ -341,6 +402,7 @@ describe('cz-customizable-ghooks', () => {
341402 revert1 ( ) ;
342403 revert2 ( ) ;
343404 deleteCommitMessageFile ( ) ;
405+ execCall = '' ;
344406 } ) ;
345407
346408 function createCommitMessageFile ( msg ) {
@@ -399,5 +461,57 @@ describe('cz-customizable-ghooks', () => {
399461
400462 module . processCLI ( commitMsgFileName , cb ) ;
401463 } ) ;
464+
465+
466+ it ( 'should try to execute a git command to append the branch name to the message by default' , ( done ) => {
467+ createCommitMessageFile ( 'feat(a): something' ) ;
468+
469+ revert2 = module . __set__ ( {
470+ exec : ( cliArg , cb ) => {
471+ execCall = cliArg ;
472+ cb ( null , '' ) ; //err, stdOut
473+ }
474+ } ) ;
475+
476+ function cb ( ) {
477+ assert ( execCall === 'git rev-parse --abbrev-ref HEAD' , execCall + ' should be passed to exec()' ) ;
478+ assert . equal ( exitCode , 0 ) ;
479+ done ( ) ;
480+ }
481+
482+ module . processCLI ( commitMsgFileName , cb ) ;
483+ } ) ;
484+
485+
486+ it ( 'should not try to execute a git command to append the branch name if the config file indicates not to' , ( done ) => {
487+ createCommitMessageFile ( 'feat(a): something' ) ;
488+
489+ revert2 = module . __set__ ( {
490+ exec : ( cliArg , cb ) => {
491+ execCall = cliArg ;
492+ cb ( null , '' ) ; //err, stdOut
493+ } ,
494+ czConfig : {
495+ types : [
496+ { value : 'feat' , name : 'feat: A new feature' }
497+ ] ,
498+ scopes : [
499+ { name : 'a' }
500+ ] ,
501+ scopeOverrides : { } ,
502+ allowCustomScopes : true ,
503+ allowBreakingChanges : [ 'feat' , 'fix' ] ,
504+ appendBranchNameToCommitMessage : false //<--- This has changed from true (default) to false
505+ }
506+ } ) ;
507+
508+ function cb ( ) {
509+ assert ( execCall === '' , 'exec() should not be called with ' + execCall ) ;
510+ assert . equal ( exitCode , 0 ) ;
511+ done ( ) ;
512+ }
513+
514+ module . processCLI ( commitMsgFileName , cb ) ;
515+ } ) ;
402516 } ) ;
403517} ) ;
0 commit comments