|
| 1 | +import { join } from 'node:path'; |
| 2 | +import { compareReportFiles } from '@code-pushup/core'; |
| 3 | +import { PERSIST_FILENAME, PERSIST_OUTPUT_DIR } from '@code-pushup/models'; |
| 4 | +import { DEFAULT_CLI_CONFIGURATION } from '../../../mocks/constants'; |
| 5 | +import { yargsCli } from '../yargs-cli'; |
| 6 | +import { yargsCompareCommandObject } from './compare-command'; |
| 7 | + |
| 8 | +vi.mock('@code-pushup/core', async () => { |
| 9 | + const core: object = await vi.importActual('@code-pushup/core'); |
| 10 | + const { CORE_CONFIG_MOCK }: typeof import('@code-pushup/test-utils') = |
| 11 | + await vi.importActual('@code-pushup/test-utils'); |
| 12 | + return { |
| 13 | + ...core, |
| 14 | + autoloadRc: vi.fn().mockResolvedValue(CORE_CONFIG_MOCK), |
| 15 | + compareReportFiles: vi.fn(), |
| 16 | + }; |
| 17 | +}); |
| 18 | + |
| 19 | +describe('compare-command', () => { |
| 20 | + it('should parse input paths from command line and output path from persist config', async () => { |
| 21 | + await yargsCli( |
| 22 | + ['compare', '--before=source-report.json', '--after=target-report.json'], |
| 23 | + { ...DEFAULT_CLI_CONFIGURATION, commands: [yargsCompareCommandObject()] }, |
| 24 | + ).parseAsync(); |
| 25 | + |
| 26 | + expect(compareReportFiles).toHaveBeenCalledWith< |
| 27 | + Parameters<typeof compareReportFiles> |
| 28 | + >( |
| 29 | + { before: 'source-report.json', after: 'target-report.json' }, |
| 30 | + join(PERSIST_OUTPUT_DIR, `${PERSIST_FILENAME}-diff.json`), |
| 31 | + ); |
| 32 | + }); |
| 33 | +}); |
0 commit comments