import { execSync } from 'child_process'; import fs from 'fs/promises'; import { testAgent, TestAgentResult } from '../src/services/qualimetrie/testAgent'; jest.mock('child_process', () => ({ execSync: jest.fn() })); jest.mock('fs/promises'); describe('testAgent file read errors', () => { beforeEach(() => { (execSync as jest.Mock).mockClear(); (fs.readFile as jest.Mock).mockClear(); }); it('throws error when coverage summary file missing', async () => { // execSync success (execSync as jest.Mock).mockImplementation(() => undefined); // First fs.readFile for coverage-summary.json throws (fs.readFile as jest.Mock) .mockRejectedValueOnce(new Error('file not found')); const res: TestAgentResult = await testAgent(); expect(res.success).toBe(false); expect(res.output).toMatch(/file not found/); }); });