@@ -2,6 +2,17 @@ import { describe, expect, it } from 'vitest'
22import { generateMessage } from '../src/generator'
33import type { CommitizenGitOptions } from '../src/shared'
44
5+ function stripAnsi ( value : string ) {
6+ const ansiCodes = [
7+ '\u001B[32m' ,
8+ '\u001B[33m' ,
9+ '\u001B[36m' ,
10+ '\u001B[39m' ,
11+ '\u001B[0m' ,
12+ ]
13+ return ansiCodes . reduce ( ( result , code ) => result . split ( code ) . join ( '' ) , value )
14+ }
15+
516/**
617 * @description generateMessage Test
718 */
@@ -53,6 +64,17 @@ describe('generateMessage()', () => {
5364 }
5465 expect ( generateMessage ( answers , options ) ) . toEqual ( 'feat: add a new feature' )
5566 } )
67+
68+ it ( 'colorized custom scope should trim spaces before output' , ( ) => {
69+ const options = { }
70+ const answers = {
71+ type : 'feat' ,
72+ scope : '___CUSTOM___' ,
73+ customScope : 'app ' ,
74+ subject : 'add a new feature' ,
75+ }
76+ expect ( stripAnsi ( generateMessage ( answers , options , true ) ) ) . toEqual ( 'feat(app): add a new feature' )
77+ } )
5678 } )
5779
5880 describe ( 'subject' , ( ) => {
@@ -98,6 +120,16 @@ describe('generateMessage()', () => {
98120 }
99121 expect ( generateMessage ( answers , options ) ) . toEqual ( 'feat(app): add a new feature :sparkles:' )
100122 } )
123+
124+ it ( 'colorized subject should trim spaces before output' , ( ) => {
125+ const options = { }
126+ const answers = {
127+ type : 'feat' ,
128+ scope : 'app' ,
129+ subject : 'add a new feature ' ,
130+ }
131+ expect ( stripAnsi ( generateMessage ( answers , options , true ) ) ) . toEqual ( 'feat(app): add a new feature' )
132+ } )
101133 } )
102134
103135 describe ( 'body' , ( ) => {
0 commit comments