import { Command } from 'commander'; import * as laModule from '../src/services/qualimetrie/lintAgent'; // Mock lintAgent to control CLI output jest.mock('../src/services/qualimetrie/lintAgent', () => ({ ...jest.requireActual('../src/services/qualimetrie/lintAgent'), lintAgent: jest.fn(), })); const { cli, lintAgent } = laModule; describe('lintAgent CLI', () => { beforeEach(() => jest.clearAllMocks()); it('exposes correct command and description', () => { expect(cli.command).toBe('qualimetrie:lint'); expect(cli.description).toMatch(/ESLint/); }); it('builder returns the same command', () => { const cmd = new Command(); const res = cli.builder(cmd); expect(res).toBe(cmd); }); it('handler logs lintAgent result', async () => { const fakeRes = { passed: true, metrics: { errors: 0, warnings: 1 }, detailPath: 'path' }; (lintAgent as jest.Mock).mockResolvedValue(fakeRes); const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); await cli.handler(undefined); expect(lintAgent).toHaveBeenCalled(); expect(logSpy).toHaveBeenCalledWith(fakeRes); logSpy.mockRestore(); }); });