@@ -2,7 +2,7 @@ import { describe, expect, it } from '@jest/globals';
22import { bumpMinSemverRange } from '../../bump/bumpMinSemverRange' ;
33
44describe ( 'bumpMinSemverRange' , ( ) => {
5- it ( 'bumps * to *' , ( ) => {
5+ it ( 'preserves *' , ( ) => {
66 const result = bumpMinSemverRange ( '1.0.0' , '*' ) ;
77 expect ( result ) . toBe ( '*' ) ;
88 } ) ;
@@ -17,43 +17,60 @@ describe('bumpMinSemverRange', () => {
1717 expect ( result ) . toBe ( 'file:/absolute/path/to/package' ) ;
1818 } ) ;
1919
20- it ( 'attaches ~ to semver range' , ( ) => {
21- const result = bumpMinSemverRange ( '1.3.0' , '~1.2.0' ) ;
22- expect ( result ) . toBe ( '~1.3.0' ) ;
20+ it ( 'preserves catalog: protocol' , ( ) => {
21+ let result = bumpMinSemverRange ( '1.0.0' , 'catalog:' ) ;
22+ expect ( result ) . toBe ( 'catalog:' ) ;
23+ result = bumpMinSemverRange ( '1.0.0' , 'catalog:foo' ) ;
24+ expect ( result ) . toBe ( 'catalog:foo' ) ;
2325 } ) ;
2426
25- it ( 'bumps ^ to semver range ', ( ) => {
26- const result = bumpMinSemverRange ( '1.3.0' , '^ 1.2.0' ) ;
27- expect ( result ) . toBe ( '^ 1.3.0' ) ;
27+ it . each ( [ '~' , '^' ] ) ( 'preserves %s and bumps to new version ', prefix => {
28+ const result = bumpMinSemverRange ( '1.3.0' , ` ${ prefix } 1.2.0` ) ;
29+ expect ( result ) . toBe ( ` ${ prefix } 1.3.0` ) ;
2830 } ) ;
2931
30- it ( 'will return the min version if unknown format ' , ( ) => {
31- const result = bumpMinSemverRange ( '1.3.0' , '# 1.2.0' ) ;
32- expect ( result ) . toBe ( '1.3.0' ) ;
32+ it ( 'returns range from new version to next major with >= ' , ( ) => {
33+ const result = bumpMinSemverRange ( '1.3.0' , '>= 1.2.0 <2.0 .0' ) ;
34+ expect ( result ) . toBe ( '>= 1.3.0 <2.0 .0' ) ;
3335 } ) ;
3436
35- it ( 'will return a minor range generally if a range is specified with >= or >' , ( ) => {
36- const result = bumpMinSemverRange ( '1.3.0' , '>= 1.2.0 <2.0.0' ) ;
37+ it ( 'returns range from new version to next major with >' , ( ) => {
38+ const result = bumpMinSemverRange ( '1.3.0' , '>1.2.0 <2.0.0' ) ;
3739 expect ( result ) . toBe ( '>=1.3.0 <2.0.0' ) ;
3840 } ) ;
3941
40- it ( 'will return a minor range generally if a range is specified with x - y ' , ( ) => {
42+ it ( 'returns range from new version to next major with - ' , ( ) => {
4143 const result = bumpMinSemverRange ( '1.3.0' , '1.2.0 - 2.0.0' ) ;
4244 expect ( result ) . toBe ( '1.3.0 - 2.0.0' ) ;
4345 } ) ;
4446
45- it . each ( [ 'workspace:*' , 'workspace:~' , 'workspace:^' ] ) ( 'will preserve %s' , workspaceVersion => {
47+ it . each ( [ 'workspace:*' , 'workspace:~' , 'workspace:^' ] ) ( 'preserves %s' , workspaceVersion => {
4648 const result = bumpMinSemverRange ( '1.3.0' , workspaceVersion ) ;
4749 expect ( result ) . toBe ( workspaceVersion ) ;
4850 } ) ;
4951
50- it ( 'bumps workspace:~1.2.0 to workspace semver range' , ( ) => {
52+ it ( 'bumps workspace:~x.y.z to workspace range with new version ' , ( ) => {
5153 const result = bumpMinSemverRange ( '1.2.1' , 'workspace:~1.2.0' ) ;
5254 expect ( result ) . toBe ( 'workspace:~1.2.1' ) ;
5355 } ) ;
5456
55- it ( 'bumps workspace:^1.2.0 to workspace semver range' , ( ) => {
57+ it ( 'bumps workspace:^x.y.z to workspace range with new version ' , ( ) => {
5658 const result = bumpMinSemverRange ( '1.3.0' , 'workspace:^1.2.0' ) ;
5759 expect ( result ) . toBe ( 'workspace:^1.3.0' ) ;
5860 } ) ;
61+
62+ it ( 'uses the new version for exact version match' , ( ) => {
63+ const result = bumpMinSemverRange ( '1.3.0' , '1.2.0' ) ;
64+ expect ( result ) . toBe ( '1.3.0' ) ;
65+ } ) ;
66+
67+ it ( 'uses the new version if unknown non-semver format' , ( ) => {
68+ const result = bumpMinSemverRange ( '1.3.0' , '#1.2.0' ) ;
69+ expect ( result ) . toBe ( '1.3.0' ) ;
70+ } ) ;
71+
72+ it ( 'preserves unrecognized range if new version satisfies it' , ( ) => {
73+ const result = bumpMinSemverRange ( '1.3.0' , '1' ) ;
74+ expect ( result ) . toBe ( '1' ) ;
75+ } ) ;
5976} ) ;
0 commit comments