@@ -9,6 +9,11 @@ import { GeminiService } from './providers/gemini/gemini.service';
99import { PixelmatchService } from '../pixelmatch/pixelmatch.service' ;
1010import { DiffResult } from '../../../test-runs/diffResult' ;
1111
12+ jest . mock ( 'zod/v3' , ( ) => {
13+ const actualZod = jest . requireActual ( 'zod' ) ;
14+ return actualZod ;
15+ } ) ;
16+
1217const initService = async ( {
1318 getImageMock = jest . fn ( ) ,
1419 ollamaGenerateMock = jest . fn ( ) ,
@@ -222,12 +227,11 @@ describe('VlmService', () => {
222227 it . each ( [
223228 [ 'empty string' , '' , DEFAULT_CONFIG ] ,
224229 [ 'invalid JSON' , 'invalid' , DEFAULT_CONFIG ] ,
225- [ 'partial config' , '{"model":"llava:7b"}' , { ... DEFAULT_CONFIG , model : 'llava:7b' } ] ,
230+ [ 'partial config' , '{"model":"llava:7b"}' , { model : 'llava:7b' } ] ,
226231 [
227232 'full config' ,
228233 '{"model":"llava:13b","prompt":"Custom prompt","temperature":0.2,"useThinking":true}' ,
229234 {
230- ...DEFAULT_CONFIG ,
231235 model : 'llava:13b' ,
232236 prompt : 'Custom prompt' ,
233237 temperature : 0.2 ,
@@ -277,23 +281,24 @@ describe('VlmService', () => {
277281 expect ( ollamaGenerateMock ) . not . toHaveBeenCalled ( ) ;
278282 } ) ;
279283
280- it ( 'should throw error when Gemini API key is missing' , async ( ) => {
284+ it ( 'should handle error when Gemini API key is missing' , async ( ) => {
281285 const pixelmatchResult = createPixelmatchResult ( { } ) ;
282286 const pixelmatchGetDiffMock = jest . fn ( ) . mockResolvedValue ( pixelmatchResult ) ;
283287 const { getImageMock } = createImageMocks ( ) ;
284288 const service = await initService ( { getImageMock, pixelmatchGetDiffMock } ) ;
285289
286- await expect (
287- service . getDiff (
288- { baseline : 'baseline' , image : 'image' , diffTollerancePercent : 0.1 , ignoreAreas : [ ] , saveDiffAsFile : false } ,
289- {
290- provider : 'gemini' as const ,
291- model : 'gemini-1.5-pro' ,
292- prompt : DEFAULT_CONFIG . prompt ,
293- temperature : 0.1 ,
294- } as any
295- )
296- ) . rejects . toThrow ( 'Gemini API key is required' ) ;
290+ const result = await service . getDiff (
291+ { baseline : 'baseline' , image : 'image' , diffTollerancePercent : 0.1 , ignoreAreas : [ ] , saveDiffAsFile : false } ,
292+ {
293+ provider : 'gemini' as const ,
294+ model : 'gemini-1.5-pro' ,
295+ prompt : DEFAULT_CONFIG . prompt ,
296+ temperature : 0.1 ,
297+ } as any
298+ ) ;
299+
300+ expect ( result . vlmDescription ) . toContain ( 'VLM analysis failed' ) ;
301+ expect ( result . status ) . toBe ( TestStatus . unresolved ) ;
297302 } ) ;
298303 } ) ;
299304} ) ;
0 commit comments