@@ -55,25 +55,69 @@ describe('defined scopes', () => {
5555 await validatePrTitle ( 'fix(core): Bar' , { scopes : [ 'core' ] } ) ;
5656 } ) ;
5757
58+ it ( 'allows a regex matching scope' , async ( ) => {
59+ await validatePrTitle ( 'fix(CORE): Bar' , { scopes : [ '[A-Z]+' ] } ) ;
60+ } ) ;
61+
5862 it ( 'allows multiple matching scopes' , async ( ) => {
5963 await validatePrTitle ( 'fix(core,e2e): Bar' , {
6064 scopes : [ 'core' , 'e2e' , 'web' ]
6165 } ) ;
6266 } ) ;
6367
68+ it ( 'allows multiple regex matching scopes' , async ( ) => {
69+ await validatePrTitle ( 'fix(CORE,WEB): Bar' , {
70+ scopes : [ '[A-Z]+' ]
71+ } ) ;
72+ } ) ;
73+
6474 it ( 'throws when an unknown scope is detected within multiple scopes' , async ( ) => {
6575 await expect (
6676 validatePrTitle ( 'fix(core,e2e,foo,bar): Bar' , { scopes : [ 'foo' , 'core' ] } )
6777 ) . rejects . toThrow (
68- 'Unknown scopes "e2e,bar" found in pull request title "fix(core,e2e,foo,bar): Bar". Use one of the available scopes: foo, core.'
78+ 'Unknown scopes "e2e,bar" found in pull request title "fix(core,e2e,foo,bar): Bar". Scope must match one of: foo, core.'
79+ ) ;
80+ } ) ;
81+
82+ it ( 'throws when an unknown scope is detected within multiple scopes' , async ( ) => {
83+ await expect (
84+ validatePrTitle ( 'fix(CORE,e2e,foo,bar): Bar' , {
85+ scopes : [ 'foo' , '[A-Z]+' ]
86+ } )
87+ ) . rejects . toThrow (
88+ 'Unknown scopes "e2e,bar" found in pull request title "fix(CORE,e2e,foo,bar): Bar". Scope must match one of: foo, [A-Z]+.'
6989 ) ;
7090 } ) ;
7191
7292 it ( 'throws when an unknown scope is detected' , async ( ) => {
7393 await expect (
7494 validatePrTitle ( 'fix(core): Bar' , { scopes : [ 'foo' ] } )
7595 ) . rejects . toThrow (
76- 'Unknown scope "core" found in pull request title "fix(core): Bar". Use one of the available scopes: foo.'
96+ 'Unknown scope "core" found in pull request title "fix(core): Bar". Scope must match one of: foo.'
97+ ) ;
98+ } ) ;
99+
100+ it ( 'throws when an unknown scope is detected for auto-wrapped regex matching' , async ( ) => {
101+ await expect (
102+ validatePrTitle ( 'fix(score): Bar' , { scopes : [ 'core' ] } )
103+ ) . rejects . toThrow (
104+ 'Unknown scope "score" found in pull request title "fix(score): Bar". Scope must match one of: core.'
105+ ) ;
106+ } ) ;
107+
108+ it ( 'throws when an unknown scope is detected for auto-wrapped regex matching when input is already wrapped' , async ( ) => {
109+ await expect (
110+ validatePrTitle ( 'fix(score): Bar' , { scopes : [ '^[A-Z]+$' ] } )
111+ ) . rejects . toThrow (
112+ 'Unknown scope "score" found in pull request title "fix(score): Bar". Scope must match one of: ^[A-Z]+$.'
113+ ) ;
114+ } ) ;
115+
116+ it ( 'throws when an unknown scope is detected for regex matching' , async ( ) => {
117+ await expect (
118+ validatePrTitle ( 'fix(core): Bar' , { scopes : [ '[A-Z]+' ] } )
119+ ) . rejects . toThrow (
120+ 'Unknown scope "core" found in pull request title "fix(core): Bar". Scope must match one of: [A-Z]+.'
77121 ) ;
78122 } ) ;
79123
@@ -93,7 +137,7 @@ describe('defined scopes', () => {
93137 requireScope : true
94138 } )
95139 ) . rejects . toThrow (
96- 'No scope found in pull request title "fix: Bar". Use one of the available scopes : foo, bar.'
140+ 'No scope found in pull request title "fix: Bar". Scope must match one of : foo, bar.'
97141 ) ;
98142 } ) ;
99143 } ) ;
@@ -103,21 +147,31 @@ describe('defined scopes', () => {
103147 await validatePrTitle ( 'fix(core): Bar' , { disallowScopes : [ 'release' ] } ) ;
104148 } ) ;
105149
150+ it ( 'passes when a single scope is provided, but not present in disallowScopes with one regex item' , async ( ) => {
151+ await validatePrTitle ( 'fix(core): Bar' , { disallowScopes : [ '[A-Z]+' ] } ) ;
152+ } ) ;
153+
106154 it ( 'passes when multiple scopes are provided, but not present in disallowScopes with one item' , async ( ) => {
107155 await validatePrTitle ( 'fix(core,e2e,bar): Bar' , {
108156 disallowScopes : [ 'release' ]
109157 } ) ;
110158 } ) ;
111159
160+ it ( 'passes when multiple scopes are provided, but not present in disallowScopes with one regex item' , async ( ) => {
161+ await validatePrTitle ( 'fix(core,e2e,bar): Bar' , {
162+ disallowScopes : [ '[A-Z]+' ]
163+ } ) ;
164+ } ) ;
165+
112166 it ( 'passes when a single scope is provided, but not present in disallowScopes with multiple items' , async ( ) => {
113167 await validatePrTitle ( 'fix(core): Bar' , {
114- disallowScopes : [ 'release' , 'test' ]
168+ disallowScopes : [ 'release' , 'test' , '[A-Z]+' ]
115169 } ) ;
116170 } ) ;
117171
118172 it ( 'passes when multiple scopes are provided, but not present in disallowScopes with multiple items' , async ( ) => {
119173 await validatePrTitle ( 'fix(core,e2e,bar): Bar' , {
120- disallowScopes : [ 'release' , 'test' ]
174+ disallowScopes : [ 'release' , 'test' , '[A-Z]+' ]
121175 } ) ;
122176 } ) ;
123177
@@ -127,6 +181,12 @@ describe('defined scopes', () => {
127181 ) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
128182 } ) ;
129183
184+ it ( 'throws when a single scope is provided and it is present in disallowScopes with one regex item' , async ( ) => {
185+ await expect (
186+ validatePrTitle ( 'fix(RELEASE): Bar' , { disallowScopes : [ '[A-Z]+' ] } )
187+ ) . rejects . toThrow ( 'Disallowed scope was found: RELEASE' ) ;
188+ } ) ;
189+
130190 it ( 'throws when a single scope is provided and it is present in disallowScopes with multiple item' , async ( ) => {
131191 await expect (
132192 validatePrTitle ( 'fix(release): Bar' , {
@@ -135,6 +195,14 @@ describe('defined scopes', () => {
135195 ) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
136196 } ) ;
137197
198+ it ( 'throws when a single scope is provided and it is present in disallowScopes with multiple regex item' , async ( ) => {
199+ await expect (
200+ validatePrTitle ( 'fix(RELEASE): Bar' , {
201+ disallowScopes : [ '[A-Z]+' , '^[A-Z].+$' ]
202+ } )
203+ ) . rejects . toThrow ( 'Disallowed scope was found: RELEASE' ) ;
204+ } ) ;
205+
138206 it ( 'throws when multiple scopes are provided and one of them is present in disallowScopes with one item ' , async ( ) => {
139207 await expect (
140208 validatePrTitle ( 'fix(release,e2e): Bar' , {
@@ -143,6 +211,14 @@ describe('defined scopes', () => {
143211 ) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
144212 } ) ;
145213
214+ it ( 'throws when multiple scopes are provided and one of them is present in disallowScopes with one regex item ' , async ( ) => {
215+ await expect (
216+ validatePrTitle ( 'fix(RELEASE,e2e): Bar' , {
217+ disallowScopes : [ '[A-Z]+' ]
218+ } )
219+ ) . rejects . toThrow ( 'Disallowed scope was found: RELEASE' ) ;
220+ } ) ;
221+
146222 it ( 'throws when multiple scopes are provided and one of them is present in disallowScopes with multiple items ' , async ( ) => {
147223 await expect (
148224 validatePrTitle ( 'fix(release,e2e): Bar' , {
@@ -151,12 +227,20 @@ describe('defined scopes', () => {
151227 ) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
152228 } ) ;
153229
230+ it ( 'throws when multiple scopes are provided and one of them is present in disallowScopes with multiple items ' , async ( ) => {
231+ await expect (
232+ validatePrTitle ( 'fix(RELEASE,e2e): Bar' , {
233+ disallowScopes : [ '[A-Z]+' , 'test' ]
234+ } )
235+ ) . rejects . toThrow ( 'Disallowed scope was found: RELEASE' ) ;
236+ } ) ;
237+
154238 it ( 'throws when multiple scopes are provided and more than one of them are present in disallowScopes' , async ( ) => {
155239 await expect (
156- validatePrTitle ( 'fix(release,test): Bar' , {
157- disallowScopes : [ 'release' , 'test' ]
240+ validatePrTitle ( 'fix(release,test,CORE ): Bar' , {
241+ disallowScopes : [ 'release' , 'test' , '[A-Z]+' ]
158242 } )
159- ) . rejects . toThrow ( 'Disallowed scopes were found: release, test' ) ;
243+ ) . rejects . toThrow ( 'Disallowed scopes were found: release, test, CORE ' ) ;
160244 } ) ;
161245 } ) ;
162246
0 commit comments