@@ -16,31 +16,77 @@ it('allows valid PR titles that use the default types', async () => {
1616
1717it ( 'throws for PR titles without a type' , async ( ) => {
1818 await expect ( validatePrTitle ( 'Fix bug' ) ) . rejects . toThrow (
19- / N o r e l e a s e t y p e f o u n d i n p u l l r e q u e s t t i t l e " F i x b u g " ./
19+ ' No release type found in pull request title "Fix bug".'
2020 ) ;
2121} ) ;
2222
2323it ( 'throws for PR titles with an unknown type' , async ( ) => {
2424 await expect ( validatePrTitle ( 'foo: Bar' ) ) . rejects . toThrow (
25- / U n k n o w n r e l e a s e t y p e " f o o " f o u n d i n p u l l r e q u e s t t i t l e " f o o : B a r " ./
25+ ' Unknown release type "foo" found in pull request title "foo: Bar".'
2626 ) ;
2727} ) ;
2828
29+ describe ( 'defined scopes' , ( ) => {
30+ it ( 'allows a missing scope by default' , async ( ) => {
31+ await validatePrTitle ( 'fix: Bar' ) ;
32+ } ) ;
33+
34+ it ( 'allows all scopes by default' , async ( ) => {
35+ await validatePrTitle ( 'fix(core): Bar' ) ;
36+ } ) ;
37+
38+ it ( 'allows a missing scope when custom scopes are defined' , async ( ) => {
39+ await validatePrTitle ( 'fix: Bar' , { scopes : [ 'foo' ] } ) ;
40+ } ) ;
41+
42+ it ( 'allows a matching scope' , async ( ) => {
43+ await validatePrTitle ( 'fix(core): Bar' , { scopes : [ 'core' ] } ) ;
44+ } ) ;
45+
46+ it ( 'throws when an unknown scope is detected' , async ( ) => {
47+ await expect (
48+ validatePrTitle ( 'fix(core): Bar' , { scopes : [ 'foo' ] } )
49+ ) . rejects . toThrow (
50+ 'Unknown scope "core" found in pull request title "fix(core): Bar". Use one of the available scopes: foo.'
51+ ) ;
52+ } ) ;
53+
54+ describe ( 'require scope' , ( ) => {
55+ it ( 'passes when a scope is provided' , async ( ) => {
56+ await validatePrTitle ( 'fix(core): Bar' , {
57+ scopes : [ 'core' ] ,
58+ requireScope : true
59+ } ) ;
60+ } ) ;
61+
62+ it ( 'throws when a scope is missing' , async ( ) => {
63+ await expect (
64+ validatePrTitle ( 'fix: Bar' , {
65+ scopes : [ 'foo' , 'bar' ] ,
66+ requireScope : true
67+ } )
68+ ) . rejects . toThrow (
69+ 'No scope found in pull request title "fix: Bar". Use one of the available scopes: foo, bar.'
70+ ) ;
71+ } ) ;
72+ } ) ;
73+ } ) ;
74+
2975describe ( 'custom types' , ( ) => {
3076 it ( 'allows PR titles with a supported type' , async ( ) => {
3177 const inputs = [ 'foo: Foobar' , 'bar: Foobar' , 'baz: Foobar' ] ;
3278 const types = [ 'foo' , 'bar' , 'baz' ] ;
3379
3480 for ( let index = 0 ; index < inputs . length ; index ++ ) {
35- await validatePrTitle ( inputs [ index ] , types ) ;
81+ await validatePrTitle ( inputs [ index ] , { types} ) ;
3682 }
3783 } ) ;
3884
3985 it ( 'throws for PR titles with an unknown type' , async ( ) => {
4086 await expect (
41- validatePrTitle ( 'fix: Foobar' , [ 'foo' , 'bar' ] )
87+ validatePrTitle ( 'fix: Foobar' , { types : [ 'foo' , 'bar' ] } )
4288 ) . rejects . toThrow (
43- / U n k n o w n r e l e a s e t y p e " f i x " f o u n d i n p u l l r e q u e s t t i t l e " f i x : F o o b a r " ./
89+ ' Unknown release type "fix" found in pull request title "fix: Foobar".'
4490 ) ;
4591 } ) ;
4692} ) ;
0 commit comments