import { execSync } from 'child_process'; import fs from 'fs/promises'; import { lintAgent, LintAgentResult } from '../src/services/qualimetrie/lintAgent'; jest.mock('child_process', () => ({ execSync: jest.fn() })); jest.mock('fs/promises'); describe('lintAgent invalid JSON handling', () => { beforeEach(() => { (execSync as jest.Mock).mockClear(); (fs.writeFile as jest.Mock).mockClear(); }); it('should handle invalid JSON output gracefully', async () => { const error: any = new Error('eslint failed'); // No stdout or stderr: raw empty (execSync as jest.Mock).mockImplementation(() => { throw error; }); const result: LintAgentResult = await lintAgent(); expect(result.passed).toBe(false); expect(result.metrics).toMatchObject({ errors: 0, warnings: 0 }); expect(result.metrics?.files).toBe(0); expect(result.metrics?.total).toBe(0); expect(result.metrics?.fixable).toBe(0); expect(result.detailPath).toBe('eslint-report.json'); expect(result.output).toBe(''); }); });