1
1
import { describe , it , expect , beforeEach } from "vitest" ;
2
2
import plugin , { semverMax , semverMin , semverOurs , semverTheirs } from "./index" ;
3
- import { StrategyStatus } from "git-json-resolver" ;
3
+ import {
4
+ StrategyStatus_OK ,
5
+ StrategyStatus_CONTINUE ,
6
+ StrategyStatus_FAIL ,
7
+ } from "git-json-resolver/utils" ;
4
8
5
9
const run = ( fn : any , ours : any , theirs : any ) => fn ( { ours, theirs, base : undefined , path : [ ] } ) ;
6
10
@@ -20,109 +24,109 @@ describe("git-json-resolver-semver", () => {
20
24
describe ( "semver-max" , ( ) => {
21
25
it ( "picks higher when both valid" , ( ) => {
22
26
const r = run ( semverMax , "1.2.3" , "1.3.0" ) ;
23
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
27
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
24
28
expect ( r . value ) . toBe ( "1.3.0" ) ;
25
29
} ) ;
26
30
27
31
it ( "prefers valid when only one is valid" , ( ) => {
28
32
const r = run ( semverMax , "1.2.3" , "banana" ) ;
29
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
33
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
30
34
expect ( r . value ) . toBe ( "1.2.3" ) ;
31
35
} ) ;
32
36
33
37
it ( "respects fallback=continue when both invalid" , async ( ) => {
34
38
await reset ( { preferValid : false , fallback : "continue" } ) ;
35
39
const r = run ( semverMax , "foo" , "bar" ) ;
36
- expect ( r . status ) . toBe ( StrategyStatus . CONTINUE ) ;
40
+ expect ( r . status ) . toBe ( StrategyStatus_CONTINUE ) ;
37
41
} ) ;
38
42
39
43
it ( "respects fallback=ours/theirs/error" , async ( ) => {
40
44
await reset ( { preferValid : false , fallback : "ours" } ) ;
41
45
let r = run ( semverMax , "foo" , "bar" ) ;
42
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
46
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
43
47
expect ( r . value ) . toBe ( "foo" ) ;
44
48
45
49
await reset ( { preferValid : false , fallback : "theirs" } ) ;
46
50
r = run ( semverMax , "foo" , "bar" ) ;
47
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
51
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
48
52
expect ( r . value ) . toBe ( "bar" ) ;
49
53
50
54
await reset ( { preferValid : false , fallback : "error" } ) ;
51
55
r = run ( semverMax , "foo" , "bar" ) ;
52
- expect ( r . status ) . toBe ( StrategyStatus . FAIL ) ;
56
+ expect ( r . status ) . toBe ( StrategyStatus_FAIL ) ;
53
57
} ) ;
54
58
55
59
it ( "strict=false allows prereleases/ranges" , async ( ) => {
56
60
await reset ( { strict : false } ) ;
57
61
const r1 = run ( semverMax , "1.2.3" , "1.2.3-beta.1" ) ;
58
- expect ( r1 . status ) . toBe ( StrategyStatus . OK ) ;
62
+ expect ( r1 . status ) . toBe ( StrategyStatus_OK ) ;
59
63
expect ( r1 . value ) . toBe ( "1.2.3" ) ; // release > prerelease
60
64
61
65
const r2 = run ( semverMax , "^1.2.3" , "1.3.0" ) ;
62
66
// validate("^1.2.3") is true in non-strict; compareVersions("^1.2.3", "1.3.0")
63
67
// is not meaningful, so preferValid should push to 1.3.0 only when one side valid.
64
68
// Here both are considered valid, so we trust compareVersions result.
65
- expect ( [ StrategyStatus . OK , StrategyStatus . CONTINUE ] ) . toContain ( r2 . status ) ;
69
+ expect ( [ StrategyStatus_OK , StrategyStatus_CONTINUE ] ) . toContain ( r2 . status ) ;
66
70
} ) ;
67
71
68
72
it ( "strict=true rejects prereleases" , async ( ) => {
69
73
await reset ( { strict : true } ) ;
70
74
const r = run ( semverMax , "1.2.3-beta.1" , "1.2.3" ) ;
71
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
75
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
72
76
expect ( r . value ) . toBe ( "1.2.3" ) ; // only ours invalid → pick valid theirs via preferValid
73
77
} ) ;
74
78
} ) ;
75
79
76
80
describe ( "semver-min" , ( ) => {
77
81
it ( "picks lower when both valid" , ( ) => {
78
82
const r = run ( semverMin , "2.0.0" , "2.1.0" ) ;
79
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
83
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
80
84
expect ( r . value ) . toBe ( "2.0.0" ) ;
81
85
} ) ;
82
86
83
87
it ( "prefers valid when only one is valid" , ( ) => {
84
88
const r = run ( semverMin , "banana" , "2.1.0" ) ;
85
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
89
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
86
90
expect ( r . value ) . toBe ( "2.1.0" ) ;
87
91
} ) ;
88
92
89
93
it ( "strict=false handles prerelease ordering" , async ( ) => {
90
94
await reset ( { strict : false } ) ;
91
95
const r = run ( semverMin , "1.2.3" , "1.2.3-beta.1" ) ;
92
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
96
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
93
97
expect ( r . value ) . toBe ( "1.2.3-beta.1" ) ; // prerelease < release
94
98
} ) ;
95
99
} ) ;
96
100
97
101
describe ( "semver-ours / semver-theirs" , ( ) => {
98
102
it ( "semver-ours returns ours when ours is valid" , ( ) => {
99
103
const r = run ( semverOurs , "1.0.0" , "2.0.0" ) ;
100
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
104
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
101
105
expect ( r . value ) . toBe ( "1.0.0" ) ;
102
106
} ) ;
103
107
104
108
it ( "semver-ours falls back to valid theirs when ours invalid" , ( ) => {
105
109
const r = run ( semverOurs , "banana" , "1.0.1" ) ;
106
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
110
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
107
111
expect ( r . value ) . toBe ( "1.0.1" ) ;
108
112
} ) ;
109
113
110
114
it ( "semver-theirs returns theirs when theirs is valid" , ( ) => {
111
115
const r = run ( semverTheirs , "1.2.3" , "2.0.0" ) ;
112
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
116
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
113
117
expect ( r . value ) . toBe ( "2.0.0" ) ;
114
118
} ) ;
115
119
116
120
it ( "semver-theirs falls back to valid ours when theirs invalid" , ( ) => {
117
121
const r = run ( semverTheirs , "1.2.3" , "carrot" ) ;
118
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
122
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
119
123
expect ( r . value ) . toBe ( "1.2.3" ) ;
120
124
} ) ;
121
125
122
126
it ( "falls back per config when neither valid" , async ( ) => {
123
127
await reset ( { preferValid : false , fallback : "theirs" } ) ;
124
128
const r = run ( semverOurs , "foo" , "bar" ) ;
125
- expect ( r . status ) . toBe ( StrategyStatus . OK ) ;
129
+ expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
126
130
expect ( r . value ) . toBe ( "bar" ) ;
127
131
} ) ;
128
132
} ) ;
0 commit comments