@@ -2,7 +2,11 @@ import {
2
2
ChangedFilesMatchConfig ,
3
3
checkAllChangedFiles ,
4
4
checkAnyChangedFiles ,
5
- toChangedFilesMatchConfig
5
+ toChangedFilesMatchConfig ,
6
+ checkIfAnyGlobMatchesAnyFile ,
7
+ checkIfAllGlobsMatchAnyFile ,
8
+ checkIfAnyGlobMatchesAllFiles ,
9
+ checkIfAllGlobsMatchAllFiles
6
10
} from '../src/changedFiles' ;
7
11
8
12
jest . mock ( '@actions/core' ) ;
@@ -11,20 +15,28 @@ jest.mock('@actions/github');
11
15
describe ( 'checkAllChangedFiles' , ( ) => {
12
16
const changedFiles = [ 'foo.txt' , 'bar.txt' ] ;
13
17
14
- describe ( 'when the globs match every file that has been changed' , ( ) => {
15
- const globs = [ '*.txt' ] ;
18
+ describe ( 'when all given glob pattern configs matched' , ( ) => {
19
+ const globPatternsConfigs = [
20
+ { AnyGlobToAnyFile : [ 'foo.txt' ] } ,
21
+ { AnyGlobToAllFiles : [ '*.txt' ] } ,
22
+ { AllGlobsToAllFiles : [ '**' ] }
23
+ ] ;
16
24
17
25
it ( 'returns true' , ( ) => {
18
- const result = checkAllChangedFiles ( changedFiles , globs ) ;
26
+ const result = checkAllChangedFiles ( changedFiles , globPatternsConfigs ) ;
19
27
expect ( result ) . toBe ( true ) ;
20
28
} ) ;
21
29
} ) ;
22
30
23
- describe ( `when the globs don't match every file that has changed` , ( ) => {
24
- const globs = [ 'foo.txt' ] ;
31
+ describe ( `when some given glob pattern config did not match` , ( ) => {
32
+ const globPatternsConfigs = [
33
+ { AnyGlobToAnyFile : [ '*.md' ] } ,
34
+ { AnyGlobToAllFiles : [ '*.txt' ] } ,
35
+ { AllGlobsToAllFiles : [ '**' ] }
36
+ ] ;
25
37
26
38
it ( 'returns false' , ( ) => {
27
- const result = checkAllChangedFiles ( changedFiles , globs ) ;
39
+ const result = checkAllChangedFiles ( changedFiles , globPatternsConfigs ) ;
28
40
expect ( result ) . toBe ( false ) ;
29
41
} ) ;
30
42
} ) ;
@@ -33,20 +45,26 @@ describe('checkAllChangedFiles', () => {
33
45
describe ( 'checkAnyChangedFiles' , ( ) => {
34
46
const changedFiles = [ 'foo.txt' , 'bar.txt' ] ;
35
47
36
- describe ( 'when any glob matches any of the files that have changed' , ( ) => {
37
- const globs = [ '*.txt' , '*.md' ] ;
48
+ describe ( 'when any given glob pattern config matched' , ( ) => {
49
+ const globPatternsConfigs = [
50
+ { AnyGlobToAnyFile : [ '*.md' ] } ,
51
+ { AnyGlobToAllFiles : [ '*.txt' ] }
52
+ ] ;
38
53
39
54
it ( 'returns true' , ( ) => {
40
- const result = checkAnyChangedFiles ( changedFiles , globs ) ;
55
+ const result = checkAnyChangedFiles ( changedFiles , globPatternsConfigs ) ;
41
56
expect ( result ) . toBe ( true ) ;
42
57
} ) ;
43
58
} ) ;
44
59
45
- describe ( 'when none of the globs match any files that have changed' , ( ) => {
46
- const globs = [ '*.md' ] ;
60
+ describe ( 'when none of the given glob pattern configs matched' , ( ) => {
61
+ const globPatternsConfigs = [
62
+ { AnyGlobToAnyFile : [ '*.md' ] } ,
63
+ { AnyGlobToAllFiles : [ '!*.txt' ] }
64
+ ] ;
47
65
48
66
it ( 'returns false' , ( ) => {
49
- const result = checkAnyChangedFiles ( changedFiles , globs ) ;
67
+ const result = checkAnyChangedFiles ( changedFiles , globPatternsConfigs ) ;
50
68
expect ( result ) . toBe ( false ) ;
51
69
} ) ;
52
70
} ) ;
@@ -63,44 +81,140 @@ describe('toChangedFilesMatchConfig', () => {
63
81
} ) ;
64
82
65
83
describe ( `when there is a 'changed-files' key in the config` , ( ) => {
66
- describe ( 'and the value is an array of strings' , ( ) => {
67
- const config = { 'changed-files' : [ 'testing' ] } ;
84
+ describe ( 'but the glob pattern config key is not provided' , ( ) => {
85
+ const config = { 'changed-files' : [ 'bar' ] } ;
86
+
87
+ it ( 'throws the error' , ( ) => {
88
+ expect ( ( ) => {
89
+ toChangedFilesMatchConfig ( config ) ;
90
+ } ) . toThrow (
91
+ `The "changed-files" section must have a valid config structure. Please read the action documentation for more information`
92
+ ) ;
93
+ } ) ;
94
+ } ) ;
68
95
69
- it ( 'sets the value in the config object' , ( ) => {
70
- const result = toChangedFilesMatchConfig ( config ) ;
71
- expect ( result ) . toEqual < ChangedFilesMatchConfig > ( {
72
- changedFiles : [ 'testing' ]
73
- } ) ;
96
+ describe ( 'but the glob pattern config key is not valid' , ( ) => {
97
+ const config = { 'changed-files' : [ { NotValidConfigKey : [ 'bar' ] } ] } ;
98
+
99
+ it ( 'throws the error' , ( ) => {
100
+ expect ( ( ) => {
101
+ toChangedFilesMatchConfig ( config ) ;
102
+ } ) . toThrow (
103
+ `Unknown config options were under "changed-files": NotValidConfigKey`
104
+ ) ;
74
105
} ) ;
75
106
} ) ;
76
107
77
- describe ( 'and the value is a string' , ( ) => {
78
- const config = { 'changed-files' : 'testing' } ;
108
+ describe ( 'and the glob pattern config key is provided' , ( ) => {
109
+ describe ( 'and the value is an array of strings' , ( ) => {
110
+ const config = { 'changed-files' : [ { AnyGlobToAnyFile : [ 'testing' ] } ] } ;
79
111
80
- it ( `sets the string as an array in the config object` , ( ) => {
81
- const result = toChangedFilesMatchConfig ( config ) ;
82
- expect ( result ) . toEqual < ChangedFilesMatchConfig > ( {
83
- changedFiles : [ 'testing' ]
112
+ it ( 'sets the value in the config object' , ( ) => {
113
+ const result = toChangedFilesMatchConfig ( config ) ;
114
+ expect ( result ) . toEqual < ChangedFilesMatchConfig > ( {
115
+ changedFiles : [ { AnyGlobToAnyFile : [ 'testing' ] } ]
116
+ } ) ;
84
117
} ) ;
85
118
} ) ;
86
- } ) ;
87
119
88
- describe ( 'but the value is an empty string' , ( ) => {
89
- const config = { 'changed-files' : '' } ;
120
+ describe ( 'and the value is a string' , ( ) => {
121
+ const config = { 'changed-files' : [ { AnyGlobToAnyFile : 'testing' } ] } ;
90
122
91
- it ( `returns an empty object` , ( ) => {
92
- const result = toChangedFilesMatchConfig ( config ) ;
93
- expect ( result ) . toEqual < ChangedFilesMatchConfig > ( { } ) ;
123
+ it ( `sets the string as an array in the config object` , ( ) => {
124
+ const result = toChangedFilesMatchConfig ( config ) ;
125
+ expect ( result ) . toEqual < ChangedFilesMatchConfig > ( {
126
+ changedFiles : [ { AnyGlobToAnyFile : [ 'testing' ] } ]
127
+ } ) ;
128
+ } ) ;
94
129
} ) ;
95
130
} ) ;
131
+ } ) ;
132
+ } ) ;
96
133
97
- describe ( 'but the value is an empty array ' , ( ) => {
98
- const config = { 'changed-files' : [ ] } ;
134
+ describe ( 'checkIfAnyGlobMatchesAnyFile ' , ( ) => {
135
+ const changedFiles = [ 'foo.txt' , 'bar.txt' ] ;
99
136
100
- it ( `returns an empty object` , ( ) => {
101
- const result = toChangedFilesMatchConfig ( config ) ;
102
- expect ( result ) . toEqual < ChangedFilesMatchConfig > ( { } ) ;
103
- } ) ;
137
+ describe ( 'when any given glob pattern matched any file' , ( ) => {
138
+ const globPatterns = [ '*.md' , 'foo.txt' ] ;
139
+
140
+ it ( 'returns true' , ( ) => {
141
+ const result = checkIfAnyGlobMatchesAnyFile ( changedFiles , globPatterns ) ;
142
+ expect ( result ) . toBe ( true ) ;
143
+ } ) ;
144
+ } ) ;
145
+
146
+ describe ( 'when none of the given glob pattern matched any file' , ( ) => {
147
+ const globPatterns = [ '*.md' , '!*.txt' ] ;
148
+
149
+ it ( 'returns false' , ( ) => {
150
+ const result = checkIfAnyGlobMatchesAnyFile ( changedFiles , globPatterns ) ;
151
+ expect ( result ) . toBe ( false ) ;
152
+ } ) ;
153
+ } ) ;
154
+ } ) ;
155
+
156
+ describe ( 'checkIfAllGlobsMatchAnyFile' , ( ) => {
157
+ const changedFiles = [ 'foo.txt' , 'bar.txt' ] ;
158
+
159
+ describe ( 'when all given glob patterns matched any file' , ( ) => {
160
+ const globPatterns = [ '**/bar.txt' , 'bar.txt' ] ;
161
+
162
+ it ( 'returns true' , ( ) => {
163
+ const result = checkIfAllGlobsMatchAnyFile ( changedFiles , globPatterns ) ;
164
+ expect ( result ) . toBe ( true ) ;
165
+ } ) ;
166
+ } ) ;
167
+
168
+ describe ( 'when some of the given glob patterns did not match any file' , ( ) => {
169
+ const globPatterns = [ '*.txt' , '*.md' ] ;
170
+
171
+ it ( 'returns false' , ( ) => {
172
+ const result = checkIfAllGlobsMatchAnyFile ( changedFiles , globPatterns ) ;
173
+ expect ( result ) . toBe ( false ) ;
174
+ } ) ;
175
+ } ) ;
176
+ } ) ;
177
+
178
+ describe ( 'checkIfAnyGlobMatchesAllFiles' , ( ) => {
179
+ const changedFiles = [ 'foo.txt' , 'bar.txt' ] ;
180
+
181
+ describe ( 'when any given glob pattern matched all files' , ( ) => {
182
+ const globPatterns = [ '*.md' , '*.txt' ] ;
183
+
184
+ it ( 'returns true' , ( ) => {
185
+ const result = checkIfAnyGlobMatchesAllFiles ( changedFiles , globPatterns ) ;
186
+ expect ( result ) . toBe ( true ) ;
187
+ } ) ;
188
+ } ) ;
189
+
190
+ describe ( 'when none of the given glob patterns matched all files' , ( ) => {
191
+ const globPatterns = [ '*.md' , 'bar.txt' , 'foo.txt' ] ;
192
+
193
+ it ( 'returns false' , ( ) => {
194
+ const result = checkIfAnyGlobMatchesAllFiles ( changedFiles , globPatterns ) ;
195
+ expect ( result ) . toBe ( false ) ;
196
+ } ) ;
197
+ } ) ;
198
+ } ) ;
199
+
200
+ describe ( 'checkIfAllGlobsMatchAllFiles' , ( ) => {
201
+ const changedFiles = [ 'foo.txt' , 'bar.txt' ] ;
202
+
203
+ describe ( 'when all given glob patterns matched all files' , ( ) => {
204
+ const globPatterns = [ '*.txt' , '**' ] ;
205
+
206
+ it ( 'returns true' , ( ) => {
207
+ const result = checkIfAllGlobsMatchAllFiles ( changedFiles , globPatterns ) ;
208
+ expect ( result ) . toBe ( true ) ;
209
+ } ) ;
210
+ } ) ;
211
+
212
+ describe ( 'when some of the given glob patterns did not match all files' , ( ) => {
213
+ const globPatterns = [ '**' , 'foo.txt' ] ;
214
+
215
+ it ( 'returns false' , ( ) => {
216
+ const result = checkIfAllGlobsMatchAllFiles ( changedFiles , globPatterns ) ;
217
+ expect ( result ) . toBe ( false ) ;
104
218
} ) ;
105
219
} ) ;
106
220
} ) ;
0 commit comments