mirror of
https://github.com/yamadashy/repomix.git
synced 2026-06-11 15:37:16 +02:00
Merge pull request #632 from sakamossan/exit-code-2
feat(cli): Set exit code when repomix fails
This commit is contained in:
@@ -140,6 +140,7 @@ export const run = async () => {
|
||||
await program.parseAsync(process.argv);
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+12
-11
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user