1- import type { Commit } from ' conventional-commits-parser' ;
2- import type { Rule } from ' @commitlint/types' ;
1+ import type { Commit } from " conventional-commits-parser"
2+ import type { Rule } from " @commitlint/types"
33import rule from "."
44
5- describe ( ' scope-pattern' , ( ) => {
5+ describe ( " scope-pattern" , ( ) => {
66 const ruleFn = rule as Rule < [ string , string ?] >
77 const createCommit = ( scope ?: string ) : Commit => {
88 return {
9- type : ' feat' ,
9+ type : " feat" ,
1010 scope : scope ,
1111 header : `feat(${ scope } ): some message` ,
1212 body : null ,
@@ -17,45 +17,45 @@ describe('scope-pattern', () => {
1717 notes : [ ] as Commit . Note [ ] ,
1818 references : [ ] as Commit . Reference [ ]
1919 } as Commit
20- } ;
21-
22- it ( ' passes when scope matches pattern and "always" is used' , async ( ) => {
23- const result = await ruleFn ( createCommit ( ' core' ) , ' always' , [ ' ^core$' ] ) ;
24- expect ( result ) . toEqual ( [ true , '' ] ) ;
25- } ) ;
26-
27- it ( ' fails when scope does not match pattern and "always" is used' , async ( ) => {
28- const result = await ruleFn ( createCommit ( ' utils' ) , ' always' , [ ' ^core$' ] ) ;
29- expect ( result ) . toEqual ( [ false , ' scope must match pattern: ^core$' ] ) ;
30- } ) ;
31-
32- it ( ' passes when scope does not match pattern and "never" is used' , async ( ) => {
33- const result = await ruleFn ( createCommit ( ' utils' ) , ' never' , [ ' ^core$' ] ) ;
34- expect ( result ) . toEqual ( [ true , '' ] ) ;
35- } ) ;
36-
37- it ( ' fails when scope matches pattern and "never" is used' , async ( ) => {
38- const result = await ruleFn ( createCommit ( ' core' ) , ' never' , [ ' ^core$' ] ) ;
39- expect ( result ) . toEqual ( [ false , ' scope must not match pattern: ^core$' ] ) ;
40- } ) ;
41-
42- it ( ' passes when scope is undefined' , async ( ) => {
43- const result = await ruleFn ( createCommit ( undefined ) , ' always' , [ ' ^core$' ] ) ;
44- expect ( result ) . toEqual ( [ true , '' ] ) ;
45- } ) ;
46-
47- it ( ' uses default "when" and "value" when not provided' , async ( ) => {
48- const result = await ruleFn ( createCommit ( ' anyscope' ) ) ;
49- expect ( result ) . toEqual ( [ true , '' ] ) ;
50- } ) ;
51-
52- it ( ' uses default "value" when only "when" is provided' , async ( ) => {
53- const result = await ruleFn ( createCommit ( ' anyscope' ) , ' always' ) ;
54- expect ( result ) . toEqual ( [ true , '' ] ) ;
55- } ) ;
56-
57- it ( ' uses custom message when provided and fails' , async ( ) => {
58- const result = await ruleFn ( createCommit ( ' utils' ) , ' always' , [ ' ^core$' , ' Custom message' ] ) ;
59- expect ( result ) . toEqual ( [ false , ' Custom message' ] ) ;
60- } ) ;
61- } ) ;
20+ }
21+
22+ it ( " passes when scope matches pattern and \ "always\ " is used" , async ( ) => {
23+ const result = await ruleFn ( createCommit ( " core" ) , " always" , [ " ^core$" ] )
24+ expect ( result ) . toEqual ( [ true , "" ] )
25+ } )
26+
27+ it ( " fails when scope does not match pattern and \ "always\ " is used" , async ( ) => {
28+ const result = await ruleFn ( createCommit ( " utils" ) , " always" , [ " ^core$" ] )
29+ expect ( result ) . toEqual ( [ false , " scope must match pattern: ^core$" ] )
30+ } )
31+
32+ it ( " passes when scope does not match pattern and \ "never\ " is used" , async ( ) => {
33+ const result = await ruleFn ( createCommit ( " utils" ) , " never" , [ " ^core$" ] )
34+ expect ( result ) . toEqual ( [ true , "" ] )
35+ } )
36+
37+ it ( " fails when scope matches pattern and \ "never\ " is used" , async ( ) => {
38+ const result = await ruleFn ( createCommit ( " core" ) , " never" , [ " ^core$" ] )
39+ expect ( result ) . toEqual ( [ false , " scope must not match pattern: ^core$" ] )
40+ } )
41+
42+ it ( " passes when scope is undefined" , async ( ) => {
43+ const result = await ruleFn ( createCommit ( undefined ) , " always" , [ " ^core$" ] )
44+ expect ( result ) . toEqual ( [ true , "" ] )
45+ } )
46+
47+ it ( " uses default \ "when\ " and \ "value\ " when not provided" , async ( ) => {
48+ const result = await ruleFn ( createCommit ( " anyscope" ) )
49+ expect ( result ) . toEqual ( [ true , "" ] )
50+ } )
51+
52+ it ( " uses default \ "value\ " when only \ "when\ " is provided" , async ( ) => {
53+ const result = await ruleFn ( createCommit ( " anyscope" ) , " always" )
54+ expect ( result ) . toEqual ( [ true , "" ] )
55+ } )
56+
57+ it ( " uses custom message when provided and fails" , async ( ) => {
58+ const result = await ruleFn ( createCommit ( " utils" ) , " always" , [ " ^core$" , " Custom message" ] )
59+ expect ( result ) . toEqual ( [ false , " Custom message" ] )
60+ } )
61+ } )
0 commit comments