/
index.spec.ts
1144 lines (1137 loc) · 47.4 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import nock from 'nock';
import { getConfig, mocked, partial } from '../../../../../test/util';
import qJson from '../../../../config/npm/__fixtures__/01.json';
import helmetJson from '../../../../config/npm/__fixtures__/02.json';
import coffeelintJson from '../../../../config/npm/__fixtures__/coffeelint.json';
import nextJson from '../../../../config/npm/__fixtures__/next.json';
import typescriptJson from '../../../../config/npm/__fixtures__/typescript.json';
import vueJson from '../../../../config/npm/__fixtures__/vue.json';
import webpackJson from '../../../../config/npm/__fixtures__/webpack.json';
import { CONFIG_VALIDATION } from '../../../../constants/error-messages';
import * as datasourceDocker from '../../../../datasource/docker';
import { id as datasourceDockerId } from '../../../../datasource/docker';
import * as datasourceGitSubmodules from '../../../../datasource/git-submodules';
import { id as datasourceGitSubmodulesId } from '../../../../datasource/git-submodules';
import { id as datasourceGithubTagsId } from '../../../../datasource/github-tags';
import { id as datasourceNpmId } from '../../../../datasource/npm';
import { id as datasourcePackagistId } from '../../../../datasource/packagist';
import { id as datasourcePypiId } from '../../../../datasource/pypi';
import { id as dockerVersioningId } from '../../../../versioning/docker';
import { id as gitVersioningId } from '../../../../versioning/git';
import { id as npmVersioningId } from '../../../../versioning/npm';
import { id as pep440VersioningId } from '../../../../versioning/pep440';
import { id as poetryVersioningId } from '../../../../versioning/poetry';
import * as lookup from '.';
jest.mock('../../../../datasource/docker');
jest.mock('../../../../datasource/git-submodules');
qJson.latestVersion = '1.4.1';
const docker = mocked(datasourceDocker) as any;
docker.defaultRegistryUrls = ['https://index.docker.io'];
const gitSubmodules = mocked(datasourceGitSubmodules);
let config: lookup.LookupUpdateConfig;
describe('workers/repository/process/lookup', () => {
beforeEach(() => {
// TODO: fix types
config = partial<lookup.LookupUpdateConfig>(getConfig());
config.manager = 'npm';
config.versioning = npmVersioningId;
config.rangeStrategy = 'replace';
jest.resetAllMocks();
});
describe('.lookupUpdates()', () => {
it('returns rollback for pinned version', async () => {
config.currentValue = '0.9.99';
config.depName = 'q';
config.datasource = datasourceNpmId;
config.rollbackPrs = true;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('returns rollback for ranged version', async () => {
config.currentValue = '^0.9.99';
config.depName = 'q';
config.datasource = datasourceNpmId;
config.rollbackPrs = true;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports minor and major upgrades for tilde ranges', async () => {
config.currentValue = '^0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports lock file updates mixed with regular updates', async () => {
config.currentValue = '^0.4.0';
config.rangeStrategy = 'update-lockfile';
config.depName = 'q';
config.datasource = datasourceNpmId;
config.lockedVersion = '0.4.0';
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('returns multiple updates if grouping but separateMajorMinor=true', async () => {
config.groupName = 'somegroup';
config.currentValue = '0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(2);
});
it('returns additional update if grouping but separateMinorPatch=true', async () => {
config.groupName = 'somegroup';
config.currentValue = '0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.separateMinorPatch = true;
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(3);
});
it('returns one update if grouping and separateMajorMinor=false', async () => {
config.groupName = 'somegroup';
config.currentValue = '0.4.0';
config.rangeStrategy = 'pin';
config.separateMajorMinor = false;
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
});
it('returns only one update if automerging', async () => {
config.automerge = true;
config.currentValue = '0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
});
it('returns only one update if automerging major', async () => {
config.major = { automerge: true };
config.currentValue = '^0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('returns both updates if automerging minor', async () => {
config.minor = { automerge: true };
config.currentValue = '^0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('enforces allowedVersions', async () => {
config.currentValue = '0.4.0';
config.allowedVersions = '<1';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(1);
});
it('enforces allowedVersions with regex', async () => {
config.currentValue = '0.4.0';
config.allowedVersions = '/^0/';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(1);
});
it('enforces allowedVersions with negativee regex', async () => {
config.currentValue = '0.4.0';
config.allowedVersions = '!/^1/';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(1);
});
it('falls back to semver syntax allowedVersions', async () => {
config.currentValue = '0.4.0';
config.allowedVersions = '<1';
config.depName = 'q';
config.versioning = dockerVersioningId; // this doesn't make sense but works for this test
config.datasource = datasourceNpmId; // this doesn't make sense but works for this test
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(1);
});
it('falls back to pep440 syntax allowedVersions', async () => {
config.currentValue = '0.4.0';
config.allowedVersions = '==0.9.4';
config.depName = 'q';
config.versioning = poetryVersioningId; // this doesn't make sense but works for this test
config.datasource = datasourceNpmId; // this doesn't make sense but works for this test
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(1);
});
it('skips invalid allowedVersions', async () => {
config.currentValue = '0.4.0';
config.allowedVersions = 'less than 1';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
await expect(lookup.lookupUpdates(config)).rejects.toThrow(
Error(CONFIG_VALIDATION)
);
});
it('returns minor update if separate patches not configured', async () => {
config.currentValue = '0.9.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(2);
expect(res.updates[0].updateType).not.toEqual('patch');
expect(res.updates[1].updateType).not.toEqual('patch');
});
it('returns patch update if automerging patch', async () => {
config.patch = {
automerge: true,
};
config.currentValue = '0.9.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates[0].updateType).toEqual('patch');
});
it('returns minor update if automerging both patch and minor', async () => {
config.patch = {
automerge: true,
};
config.minor = {
automerge: true,
};
config.currentValue = '0.9.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates[0].updateType).toEqual('minor');
});
it('returns patch update if separateMinorPatch', async () => {
config.separateMinorPatch = true;
config.currentValue = '0.9.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('returns patch minor and major', async () => {
config.separateMinorPatch = true;
config.currentValue = '0.8.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(3);
expect(res.updates).toMatchSnapshot();
});
it('disables major release separation (major)', async () => {
config.separateMajorMinor = false;
config.currentValue = '^0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('disables major release separation (minor)', async () => {
config.separateMajorMinor = false;
config.currentValue = '1.0.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('uses minimum version for vulnerabilityAlerts', async () => {
config.currentValue = '1.0.0';
config.vulnerabilityAlert = true;
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = (await lookup.lookupUpdates(config)).updates;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(1);
});
it('supports minor and major upgrades for ranged versions', async () => {
config.currentValue = '~0.4.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('ignores pinning for ranges when other upgrade exists', async () => {
config.currentValue = '~0.9.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades minor ranged versions', async () => {
config.currentValue = '~1.0.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('widens minor ranged versions if configured', async () => {
config.currentValue = '~1.3.0';
config.rangeStrategy = 'widen';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('replaces minor complex ranged versions if configured', async () => {
config.currentValue = '~1.2.0 || ~1.3.0';
config.rangeStrategy = 'replace';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('widens major ranged versions if configured', async () => {
config.currentValue = '^2.0.0';
config.rangeStrategy = 'widen';
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('replaces major complex ranged versions if configured', async () => {
config.currentValue = '^1.0.0 || ^2.0.0';
config.rangeStrategy = 'replace';
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('pins minor ranged versions', async () => {
config.currentValue = '^1.0.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('uses the locked version for pinning', async () => {
config.currentValue = '^1.0.0';
config.lockedVersion = '1.0.0';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('ignores minor ranged versions when not pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '^1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(0);
});
it('upgrades tilde ranges', async () => {
config.rangeStrategy = 'pin';
config.currentValue = '~1.3.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades .x minor ranges', async () => {
config.currentValue = '1.3.x';
config.rangeStrategy = 'pin';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades tilde ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '~1.3.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades .x major ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '0.x';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades .x minor ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '1.3.x';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades .x complex minor ranges without pinning', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '1.2.x - 1.3.x';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades shorthand major ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades shorthand minor ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '1.3';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades multiple tilde ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '~0.7.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades multiple caret ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '^0.7.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports complex ranges', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '^0.7.0 || ^0.8.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(2);
expect(res.updates[0]).toMatchSnapshot();
});
it('supports complex major ranges', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '^1.0.0 || ^2.0.0';
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports complex major hyphen ranges', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '1.x - 2.x';
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('widens .x OR ranges', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '1.x || 2.x';
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('widens stanndalone major OR ranges', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '1 || 2';
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports complex tilde ranges', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '~1.2.0 || ~1.3.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('returns nothing for greater than ranges', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '>= 0.7.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(0);
});
it('upgrades less than equal ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '<= 0.7.2';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades less than ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '< 0.7.2';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades less than major ranges', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '< 1';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades less than equal minor ranges', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '<= 1.3';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades equal minor ranges', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '=1.3.1';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades less than equal major ranges', async () => {
config.rangeStrategy = 'replace';
config.respectLatest = false;
config.currentValue = '<= 1';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('upgrades major less than equal ranges', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '<= 1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates[0].newValue).toEqual('<= 1.4.1');
});
it('upgrades major less than ranges without pinning', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '< 1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates[0].newValue).toEqual('< 2.0.0');
});
it('upgrades major greater than less than ranges without pinning', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '>= 0.5.0 < 1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates[0].newValue).toEqual('>= 0.5.0 < 2.0.0');
});
it('upgrades minor greater than less than ranges without pinning', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '>= 0.5.0 <0.8';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates[0].newValue).toEqual('>= 0.5.0 <0.10');
expect(res.updates[1].newValue).toEqual('>= 0.5.0 <1.5');
});
it('upgrades minor greater than less than equals ranges without pinning', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '>= 0.5.0 <= 0.8.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates[0].newValue).toEqual('>= 0.5.0 <= 0.9.7');
expect(res.updates[1].newValue).toEqual('>= 0.5.0 <= 1.4.1');
});
it('rejects reverse ordered less than greater than', async () => {
config.rangeStrategy = 'widen';
config.currentValue = '<= 0.8.0 >= 0.5.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
});
it('supports > latest versions if configured', async () => {
config.respectLatest = false;
config.currentValue = '1.4.1';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('should ignore unstable versions if the current version is stable', async () => {
config.currentValue = '2.5.16';
config.depName = 'vue';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/vue').reply(200, vueJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(0);
});
it('should allow unstable versions if the ignoreUnstable=false', async () => {
config.currentValue = '2.5.16';
config.ignoreUnstable = false;
config.depName = 'vue';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/vue').reply(200, vueJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('2.5.17-beta.0');
});
it('should allow unstable versions if the current version is unstable', async () => {
config.currentValue = '3.1.0-dev.20180731';
config.depName = 'typescript';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('3.1.0-dev.20180813');
});
it('should not jump unstable versions', async () => {
config.currentValue = '3.0.1-insiders.20180726';
config.depName = 'typescript';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('3.0.1');
});
it('should follow dist-tag even if newer version exists', async () => {
config.currentValue = '3.0.1-insiders.20180713';
config.depName = 'typescript';
config.datasource = datasourceNpmId;
config.followTag = 'insiders';
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('3.0.1-insiders.20180726');
});
it('should roll back to dist-tag if current version is higher', async () => {
config.currentValue = '3.1.0-dev.20180813';
config.depName = 'typescript';
config.datasource = datasourceNpmId;
config.followTag = 'insiders';
config.rollbackPrs = true;
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('3.0.1-insiders.20180726');
});
it('should jump unstable versions if followTag', async () => {
config.currentValue = '3.0.0-insiders.20180706';
config.depName = 'typescript';
config.datasource = datasourceNpmId;
config.followTag = 'insiders';
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('3.0.1-insiders.20180726');
});
it('should update nothing if current version is dist-tag', async () => {
config.currentValue = '3.0.1-insiders.20180726';
config.depName = 'typescript';
config.datasource = datasourceNpmId;
config.followTag = 'insiders';
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(0);
});
it('should warn if no version matches dist-tag', async () => {
config.currentValue = '3.0.1-dev.20180726';
config.depName = 'typescript';
config.datasource = datasourceNpmId;
config.followTag = 'foo';
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(0);
expect(res.warnings).toHaveLength(1);
expect(res.warnings[0].message).toEqual(
"Can't find version with tag foo for typescript"
);
});
it('should treat zero zero tilde ranges as 0.0.x', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '~0.0.34';
config.depName = '@types/helmet';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/@types%2Fhelmet')
.reply(200, helmetJson);
expect((await lookup.lookupUpdates(config)).updates).toEqual([]);
});
it('should treat zero zero caret ranges as pinned', async () => {
config.rangeStrategy = 'replace';
config.currentValue = '^0.0.34';
config.depName = '@types/helmet';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/@types%2Fhelmet')
.reply(200, helmetJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('should downgrade from missing versions', async () => {
config.currentValue = '1.16.1';
config.depName = 'coffeelint';
config.datasource = datasourceNpmId;
config.rollbackPrs = true;
nock('https://registry.npmjs.org')
.get('/coffeelint')
.reply(200, coffeelintJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(1);
expect(res.updates[0]).toMatchSnapshot();
});
it('should upgrade to only one major', async () => {
config.currentValue = '1.0.0';
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(2);
});
it('should upgrade to two majors', async () => {
config.currentValue = '1.0.0';
config.separateMultipleMajor = true;
config.depName = 'webpack';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org')
.get('/webpack')
.reply(200, webpackJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(3);
});
it('does not jump major unstable', async () => {
config.currentValue = '^4.4.0-canary.3';
config.rangeStrategy = 'replace';
config.depName = 'next';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/next').reply(200, nextJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(0);
});
it('supports in-range caret updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '^1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports in-range tilde updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '~1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports in-range tilde patch updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '~1.0.0';
config.depName = 'q';
config.separateMinorPatch = true;
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports in-range gte updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '>=1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('supports majorgte updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '>=0.9.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('rejects in-range unsupported operator', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '>1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('rejects non-fully specified in-range updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '1.x';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('rejects complex range in-range updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '^0.9.0 || ^1.0.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('replaces non-range in-range updates', async () => {
config.depName = 'q';
config.datasource = datasourceNpmId;
config.packageFile = 'package.json';
config.rangeStrategy = 'bump';
config.currentValue = '1.0.0';
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('handles github 404', async () => {
config.depName = 'foo';
config.datasource = datasourceGithubTagsId;
config.packageFile = 'package.json';
config.currentValue = '1.0.0';
nock('https://pypi.org').get('/pypi/foo/json').reply(404);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('handles pypi 404', async () => {
config.depName = 'foo';
config.datasource = datasourcePypiId;
config.packageFile = 'requirements.txt';
config.currentValue = '1.0.0';
nock('https://api.github.com')
.get('/repos/some/repo/git/refs/tags?per_page=100')
.reply(404);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('handles packagist', async () => {
config.depName = 'foo/bar';
config.datasource = datasourcePackagistId;
config.packageFile = 'composer.json';
config.currentValue = '1.0.0';
config.registryUrls = ['https://packagist.org'];
nock('https://packagist.org').get('/packages/foo/bar.json').reply(404);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('handles unknown datasource', async () => {
config.depName = 'foo';
config.datasource = 'typo';
config.packageFile = 'package.json';
config.currentValue = '1.0.0';
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('handles PEP440', async () => {
config.manager = 'pip_requirements';
config.versioning = pep440VersioningId;
config.manager = 'pip_requirements';
config.versioning = 'pep440';
config.rangeStrategy = 'pin';
config.lockedVersion = '0.9.4';
config.currentValue = '~=0.9';
config.depName = 'q';
// TODO: we are using npm as source to test pep440
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
});
it('returns complex object', async () => {
config.currentValue = '1.3.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeDefined();
});
it('ignores deprecated', async () => {
config.currentValue = '1.3.0';
config.depName = 'q2';
config.datasource = datasourceNpmId;
const returnJson = JSON.parse(JSON.stringify(qJson));
returnJson.name = 'q2';
returnJson.versions['1.4.1'].deprecated = 'true';
nock('https://registry.npmjs.org').get('/q2').reply(200, returnJson);
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot();
expect(res.updates[0].toVersion).toEqual('1.4.0');
});
it('is deprecated', async () => {
config.currentValue = '1.3.0';
config.depName = 'q3';
config.datasource = datasourceNpmId;
const returnJson = {
...JSON.parse(JSON.stringify(qJson)),
name: 'q3',
deprecated: true,
repository: { url: null, directory: 'test' },
};
nock('https://registry.npmjs.org').get('/q3').reply(200, returnJson);
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot();
expect(res.updates[0].toVersion).toEqual('1.4.1');
});
it('skips unsupported values', async () => {
config.currentValue = 'alpine';
config.depName = 'node';
config.datasource = datasourceDockerId;
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot();
});
it('skips undefined values', async () => {
config.depName = 'node';
config.datasource = datasourceDockerId;
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot();
});
it('handles digest pin', async () => {
config.currentValue = '8.0.0';
config.depName = 'node';
config.datasource = datasourceDockerId;
config.pinDigests = true;
docker.getReleases.mockResolvedValueOnce({
releases: [
{
version: '8.0.0',
},
{
version: '8.1.0',
},
],
});
docker.getDigest.mockResolvedValueOnce('sha256:abcdef1234567890');
docker.getDigest.mockResolvedValueOnce('sha256:0123456789abcdef');
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot();
});
['8.1.0', '8.1', '8'].forEach((currentValue) => {
it('skips uncompatible versions for ' + currentValue, async () => {