@@ -2,6 +2,15 @@ import { describe, it, expect, vi } from "vitest";
2
2
import { Conflict , MergeContext , mergeObject , BuiltInStrategies , statusToString } from "./merger" ;
3
3
import { DROP } from "./utils" ;
4
4
5
+ // Mock logger
6
+ const mockLogger = {
7
+ debug : vi . fn ( ) ,
8
+ info : vi . fn ( ) ,
9
+ warn : vi . fn ( ) ,
10
+ error : vi . fn ( ) ,
11
+ flush : vi . fn ( ) ,
12
+ } ;
13
+
5
14
// Mock resolveStrategies so we control strategy order
6
15
vi . mock ( "./strategy-resolver" , ( ) => ( {
7
16
resolveStrategies : vi . fn ( ( ) => [ "ours" , "theirs" , "merge" ] ) ,
@@ -33,7 +42,15 @@ describe("statusToString", () => {
33
42
34
43
describe ( "BuiltInStrategies" , ( ) => {
35
44
const ctx = makeCtx ( ) ;
36
- const args = { ours : 1 , theirs : 2 , base : 0 , path : "x" , ctx, conflicts : [ ] as Conflict [ ] } ;
45
+ const args = {
46
+ ours : 1 ,
47
+ theirs : 2 ,
48
+ base : 0 ,
49
+ path : "x" ,
50
+ ctx,
51
+ conflicts : [ ] as Conflict [ ] ,
52
+ logger : mockLogger ,
53
+ } ;
37
54
38
55
it ( "ours returns ours" , ( ) => {
39
56
const r = BuiltInStrategies . ours ( args ) ;
@@ -96,6 +113,7 @@ describe("BuiltInStrategies", () => {
96
113
theirs : { a : 2 } ,
97
114
base : { a : 0 } ,
98
115
path : "obj" ,
116
+ logger : mockLogger ,
99
117
} ;
100
118
const r = await BuiltInStrategies . merge ( objArgs ) ;
101
119
expect ( r . status ) . toBe ( StrategyStatus_OK ) ;
@@ -113,7 +131,15 @@ describe("mergeObject", () => {
113
131
it ( "returns ours if equal" , async ( ) => {
114
132
const ctx = makeCtx ( ) ;
115
133
const conflicts : Conflict [ ] = [ ] ;
116
- const v = await mergeObject ( { ours : 1 , theirs : 1 , base : 0 , path : "x" , ctx, conflicts } ) ;
134
+ const v = await mergeObject ( {
135
+ ours : 1 ,
136
+ theirs : 1 ,
137
+ base : 0 ,
138
+ path : "x" ,
139
+ ctx,
140
+ conflicts,
141
+ logger : mockLogger ,
142
+ } ) ;
117
143
expect ( v ) . toBe ( 1 ) ;
118
144
expect ( conflicts ) . toHaveLength ( 0 ) ;
119
145
} ) ;
@@ -122,15 +148,29 @@ describe("mergeObject", () => {
122
148
( resolveStrategies as any ) . mockReturnValueOnce ( [ "theirs" ] ) ;
123
149
const ctx = makeCtx ( ) ;
124
150
const conflicts : Conflict [ ] = [ ] ;
125
- const v = await mergeObject ( { ours : 1 , theirs : 2 , path : "p" , ctx, conflicts } ) ;
151
+ const v = await mergeObject ( {
152
+ ours : 1 ,
153
+ theirs : 2 ,
154
+ path : "p" ,
155
+ ctx,
156
+ conflicts,
157
+ logger : mockLogger ,
158
+ } ) ;
126
159
expect ( v ) . toBe ( 2 ) ;
127
160
} ) ;
128
161
129
162
it ( "records SKIP as conflict" , async ( ) => {
130
163
( resolveStrategies as any ) . mockReturnValueOnce ( [ "skip" ] ) ;
131
164
const ctx = makeCtx ( ) ;
132
165
const conflicts : Conflict [ ] = [ ] ;
133
- const v = await mergeObject ( { ours : "a" , theirs : "b" , path : "p" , ctx, conflicts } ) ;
166
+ const v = await mergeObject ( {
167
+ ours : "a" ,
168
+ theirs : "b" ,
169
+ path : "p" ,
170
+ ctx,
171
+ conflicts,
172
+ logger : mockLogger ,
173
+ } ) ;
134
174
expect ( v ) . toBeUndefined ( ) ;
135
175
expect ( conflicts [ 0 ] . reason ) . toMatch ( / S k i p / ) ;
136
176
} ) ;
@@ -139,7 +179,15 @@ describe("mergeObject", () => {
139
179
( resolveStrategies as any ) . mockReturnValueOnce ( [ "non-empty" ] ) ;
140
180
const ctx = makeCtx ( ) ;
141
181
const conflicts : Conflict [ ] = [ ] ;
142
- const v = await mergeObject ( { ours : "" , theirs : "" , base : "" , path : "p" , ctx, conflicts } ) ;
182
+ const v = await mergeObject ( {
183
+ ours : "" ,
184
+ theirs : "" ,
185
+ base : "" ,
186
+ path : "p" ,
187
+ ctx,
188
+ conflicts,
189
+ logger : mockLogger ,
190
+ } ) ;
143
191
expect ( v ) . toBeUndefined ( ) ;
144
192
expect ( conflicts [ 0 ] ) . toMatchObject ( {
145
193
path : "p" ,
0 commit comments