@@ -55,25 +55,69 @@ describe('defined scopes', () => {
55
55
await validatePrTitle ( 'fix(core): Bar' , { scopes : [ 'core' ] } ) ;
56
56
} ) ;
57
57
58
+ it ( 'allows a regex matching scope' , async ( ) => {
59
+ await validatePrTitle ( 'fix(CORE): Bar' , { scopes : [ '[A-Z]+' ] } ) ;
60
+ } ) ;
61
+
58
62
it ( 'allows multiple matching scopes' , async ( ) => {
59
63
await validatePrTitle ( 'fix(core,e2e): Bar' , {
60
64
scopes : [ 'core' , 'e2e' , 'web' ]
61
65
} ) ;
62
66
} ) ;
63
67
68
+ it ( 'allows multiple regex matching scopes' , async ( ) => {
69
+ await validatePrTitle ( 'fix(CORE,WEB): Bar' , {
70
+ scopes : [ '[A-Z]+' ]
71
+ } ) ;
72
+ } ) ;
73
+
64
74
it ( 'throws when an unknown scope is detected within multiple scopes' , async ( ) => {
65
75
await expect (
66
76
validatePrTitle ( 'fix(core,e2e,foo,bar): Bar' , { scopes : [ 'foo' , 'core' ] } )
67
77
) . 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]+.'
69
89
) ;
70
90
} ) ;
71
91
72
92
it ( 'throws when an unknown scope is detected' , async ( ) => {
73
93
await expect (
74
94
validatePrTitle ( 'fix(core): Bar' , { scopes : [ 'foo' ] } )
75
95
) . 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]+.'
77
121
) ;
78
122
} ) ;
79
123
@@ -93,7 +137,7 @@ describe('defined scopes', () => {
93
137
requireScope : true
94
138
} )
95
139
) . 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.'
97
141
) ;
98
142
} ) ;
99
143
} ) ;
@@ -103,21 +147,31 @@ describe('defined scopes', () => {
103
147
await validatePrTitle ( 'fix(core): Bar' , { disallowScopes : [ 'release' ] } ) ;
104
148
} ) ;
105
149
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
+
106
154
it ( 'passes when multiple scopes are provided, but not present in disallowScopes with one item' , async ( ) => {
107
155
await validatePrTitle ( 'fix(core,e2e,bar): Bar' , {
108
156
disallowScopes : [ 'release' ]
109
157
} ) ;
110
158
} ) ;
111
159
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
+
112
166
it ( 'passes when a single scope is provided, but not present in disallowScopes with multiple items' , async ( ) => {
113
167
await validatePrTitle ( 'fix(core): Bar' , {
114
- disallowScopes : [ 'release' , 'test' ]
168
+ disallowScopes : [ 'release' , 'test' , '[A-Z]+' ]
115
169
} ) ;
116
170
} ) ;
117
171
118
172
it ( 'passes when multiple scopes are provided, but not present in disallowScopes with multiple items' , async ( ) => {
119
173
await validatePrTitle ( 'fix(core,e2e,bar): Bar' , {
120
- disallowScopes : [ 'release' , 'test' ]
174
+ disallowScopes : [ 'release' , 'test' , '[A-Z]+' ]
121
175
} ) ;
122
176
} ) ;
123
177
@@ -127,6 +181,12 @@ describe('defined scopes', () => {
127
181
) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
128
182
} ) ;
129
183
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
+
130
190
it ( 'throws when a single scope is provided and it is present in disallowScopes with multiple item' , async ( ) => {
131
191
await expect (
132
192
validatePrTitle ( 'fix(release): Bar' , {
@@ -135,6 +195,14 @@ describe('defined scopes', () => {
135
195
) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
136
196
} ) ;
137
197
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
+
138
206
it ( 'throws when multiple scopes are provided and one of them is present in disallowScopes with one item ' , async ( ) => {
139
207
await expect (
140
208
validatePrTitle ( 'fix(release,e2e): Bar' , {
@@ -143,6 +211,14 @@ describe('defined scopes', () => {
143
211
) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
144
212
} ) ;
145
213
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
+
146
222
it ( 'throws when multiple scopes are provided and one of them is present in disallowScopes with multiple items ' , async ( ) => {
147
223
await expect (
148
224
validatePrTitle ( 'fix(release,e2e): Bar' , {
@@ -151,12 +227,20 @@ describe('defined scopes', () => {
151
227
) . rejects . toThrow ( 'Disallowed scope was found: release' ) ;
152
228
} ) ;
153
229
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
+
154
238
it ( 'throws when multiple scopes are provided and more than one of them are present in disallowScopes' , async ( ) => {
155
239
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]+' ]
158
242
} )
159
- ) . rejects . toThrow ( 'Disallowed scopes were found: release, test' ) ;
243
+ ) . rejects . toThrow ( 'Disallowed scopes were found: release, test, CORE ' ) ;
160
244
} ) ;
161
245
} ) ;
162
246
0 commit comments