Merge pull request #632 from sakamossan/exit-code-2

feat(cli): Set exit code when repomix fails
This commit is contained in:
Kazuki Yamada
2025-06-05 23:55:40 +09:00
committed by GitHub
2 changed files with 13 additions and 11 deletions
+1
View File
@@ -140,6 +140,7 @@ export const run = async () => {
await program.parseAsync(process.argv);
} catch (error) {
handleError(error);
process.exit(1);
}
};
+12 -11
View File
@@ -1,3 +1,4 @@
import { program } from 'commander';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import * as defaultAction from '../../src/cli/actions/defaultAction.js';
import * as initAction from '../../src/cli/actions/initAction.js';
@@ -36,16 +37,6 @@ vi.mock('../../src/shared/logger', () => ({
setLogLevelByEnv: vi.fn(),
}));
vi.mock('commander', () => ({
program: {
description: vi.fn().mockReturnThis(),
arguments: vi.fn().mockReturnThis(),
option: vi.fn().mockReturnThis(),
action: vi.fn().mockReturnThis(),
parseAsync: vi.fn().mockResolvedValue(undefined),
},
}));
vi.mock('../../src/cli/actions/defaultAction');
vi.mock('../../src/cli/actions/initAction');
vi.mock('../../src/cli/actions/remoteAction');
@@ -163,8 +154,18 @@ describe('cliRun', () => {
vi.mocked(versionAction.runVersionAction).mockResolvedValue();
});
test('should run without arguments', async () => {
test('should call process.exit(1) on error', async () => {
const exitSpy = vi.spyOn(process, 'exit').mockImplementationOnce(() => undefined as never);
const parseSpy = vi.spyOn(program, 'description').mockImplementationOnce(() => {
throw Error();
});
const handleErrorSpy = vi.spyOn(logger, 'error');
await expect(run()).resolves.not.toThrow();
expect(exitSpy).toHaveBeenCalledWith(1);
expect(handleErrorSpy).toHaveBeenCalled();
exitSpy.mockReset();
parseSpy.mockReset();
handleErrorSpy.mockReset();
});
describe('executeAction', () => {