@@ -5,7 +5,11 @@ const setup = require('../setup.js')
5
5
const setupDependabot = async ( t , { branches = [ 'main' ] , ...config } = { } ) => {
6
6
const s = await setup ( t , {
7
7
package : {
8
- templateOSS : config ,
8
+ templateOSS : {
9
+ ...config ,
10
+ // Include branches in the templateOSS config so they get processed
11
+ branches : branches . length > 1 ? branches : undefined ,
12
+ } ,
9
13
} ,
10
14
mocks : {
11
15
'@npmcli/git' : {
@@ -101,3 +105,170 @@ t.test('no dependabot', async t => {
101
105
t . equal ( s . dependabot , false )
102
106
t . equal ( s . postDependabot , false )
103
107
} )
108
+
109
+ t . test ( 'custom interval' , async t => {
110
+ const s = await setupDependabot ( t , {
111
+ dependabotInterval : 'weekly' ,
112
+ } )
113
+
114
+ t . match ( s . dependabot [ 0 ] , {
115
+ schedule : { interval : 'weekly' } ,
116
+ } )
117
+ } )
118
+
119
+ t . test ( 'branch-specific interval' , async t => {
120
+ const s = await setupDependabot ( t , {
121
+ dependabot : {
122
+ main : { interval : 'monthly' } ,
123
+ } ,
124
+ } )
125
+
126
+ t . match ( s . dependabot [ 0 ] , {
127
+ schedule : { interval : 'monthly' } ,
128
+ } )
129
+ } )
130
+
131
+ t . test ( 'mixed interval configuration' , async t => {
132
+ const s = await setupDependabot ( t , {
133
+ branches : [ 'main' , 'develop' ] ,
134
+ dependabotInterval : 'weekly' ,
135
+ dependabot : {
136
+ main : { interval : 'monthly' } ,
137
+ } ,
138
+ } )
139
+
140
+ t . equal ( s . dependabot . length , 2 )
141
+
142
+ // main branch should use branch-specific interval
143
+ const mainBranch = s . dependabot . find ( d => d [ 'target-branch' ] === 'main' )
144
+ t . match ( mainBranch , {
145
+ schedule : { interval : 'monthly' } ,
146
+ } )
147
+
148
+ // develop branch should use global interval
149
+ const developBranch = s . dependabot . find ( d => d [ 'target-branch' ] === 'develop' )
150
+ t . match ( developBranch , {
151
+ schedule : { interval : 'weekly' } ,
152
+ } )
153
+ } )
154
+
155
+ t . test ( 'branch-specific interval with strategy' , async t => {
156
+ const s = await setupDependabot ( t , {
157
+ dependabot : {
158
+ main : { interval : 'weekly' , strategy : 'auto' } ,
159
+ } ,
160
+ } )
161
+
162
+ t . match ( s . dependabot [ 0 ] , {
163
+ schedule : { interval : 'weekly' } ,
164
+ 'versioning-strategy' : 'auto' ,
165
+ } )
166
+ } )
167
+
168
+ t . test ( 'global interval with branch-specific strategy only' , async t => {
169
+ const s = await setupDependabot ( t , {
170
+ dependabotInterval : 'monthly' ,
171
+ dependabot : {
172
+ main : { strategy : 'lockfile-only' } ,
173
+ } ,
174
+ } )
175
+
176
+ t . match ( s . dependabot [ 0 ] , {
177
+ schedule : { interval : 'monthly' } ,
178
+ 'versioning-strategy' : 'lockfile-only' ,
179
+ } )
180
+ } )
181
+
182
+ t . test ( 'fallback to daily when no interval specified' , async t => {
183
+ const s = await setupDependabot ( t , {
184
+ dependabot : 'increase-if-necessary' ,
185
+ } )
186
+
187
+ t . match ( s . dependabot [ 0 ] , {
188
+ schedule : { interval : 'daily' } ,
189
+ 'versioning-strategy' : 'increase-if-necessary' ,
190
+ } )
191
+ } )
192
+
193
+ t . test ( 'mixed branches with some having interval and some not' , async t => {
194
+ const s = await setupDependabot ( t , {
195
+ branches : [ 'main' , 'develop' , 'staging' ] ,
196
+ dependabotInterval : 'weekly' ,
197
+ dependabot : {
198
+ main : { interval : 'monthly' } ,
199
+ develop : { strategy : 'auto' } ,
200
+ // staging gets global interval
201
+ } ,
202
+ } )
203
+
204
+ t . equal ( s . dependabot . length , 3 )
205
+
206
+ const mainBranch = s . dependabot . find ( d => d [ 'target-branch' ] === 'main' )
207
+ t . match ( mainBranch , {
208
+ schedule : { interval : 'monthly' } ,
209
+ } )
210
+
211
+ const developBranch = s . dependabot . find ( d => d [ 'target-branch' ] === 'develop' )
212
+ t . match ( developBranch , {
213
+ schedule : { interval : 'weekly' } ,
214
+ 'versioning-strategy' : 'auto' ,
215
+ } )
216
+
217
+ const stagingBranch = s . dependabot . find ( d => d [ 'target-branch' ] === 'staging' )
218
+ t . match ( stagingBranch , {
219
+ schedule : { interval : 'weekly' } ,
220
+ } )
221
+ } )
222
+
223
+ t . test ( 'empty branch config falls back to global interval' , async t => {
224
+ const s = await setupDependabot ( t , {
225
+ dependabotInterval : 'monthly' ,
226
+ dependabot : {
227
+ main : { } , // empty object should fall back to global interval
228
+ } ,
229
+ } )
230
+
231
+ t . match ( s . dependabot [ 0 ] , {
232
+ schedule : { interval : 'monthly' } ,
233
+ } )
234
+ } )
235
+
236
+ t . test ( 'no package interval and no branch interval falls back to default' , async t => {
237
+ const s = await setupDependabot ( t , {
238
+ // no dependabotInterval at package level
239
+ dependabot : {
240
+ main : { } , // empty object, no interval
241
+ } ,
242
+ } )
243
+
244
+ t . match ( s . dependabot [ 0 ] , {
245
+ schedule : { interval : 'daily' } , // should fall back to default
246
+ } )
247
+ } )
248
+
249
+ t . test ( 'branch config as string without interval falls back properly' , async t => {
250
+ const s = await setupDependabot ( t , {
251
+ // no dependabotInterval at package level
252
+ dependabot : {
253
+ main : 'auto' , // string config, no interval property
254
+ } ,
255
+ } )
256
+
257
+ t . match ( s . dependabot [ 0 ] , {
258
+ schedule : { interval : 'daily' } , // should fall back to default
259
+ 'versioning-strategy' : 'auto' ,
260
+ } )
261
+ } )
262
+
263
+ t . test ( 'falsy package interval and no branch interval falls back to default' , async t => {
264
+ const s = await setupDependabot ( t , {
265
+ dependabotInterval : null , // explicitly falsy
266
+ dependabot : {
267
+ main : { } , // empty object, no interval
268
+ } ,
269
+ } )
270
+
271
+ t . match ( s . dependabot [ 0 ] , {
272
+ schedule : { interval : 'daily' } , // should fall back to default
273
+ } )
274
+ } )
0 commit comments