Skip to content

Commit c029b07

Browse files
committed
test(cli): add integration test for index command storage size
- Verify index command displays storage size after indexing - Create sample TypeScript file, run indexer, check output - Uses --no-git --no-github for faster test execution
1 parent ad88c79 commit c029b07

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

packages/cli/src/commands/commands.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from 'node:path';
44
import { Command } from 'commander';
55
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
66
import { cleanCommand } from './clean';
7+
import { indexCommand } from './index';
78
import { initCommand } from './init';
89

910
describe('CLI Commands', () => {
@@ -72,4 +73,58 @@ describe('CLI Commands', () => {
7273
expect(forceOption?.short).toBe('-f');
7374
});
7475
});
76+
77+
describe('index command', () => {
78+
it('should have correct command name and description', () => {
79+
expect(indexCommand.name()).toBe('index');
80+
expect(indexCommand.description()).toBe(
81+
'Index a repository (code, git history, GitHub issues/PRs)'
82+
);
83+
});
84+
85+
it('should display storage size after indexing', async () => {
86+
const indexDir = path.join(testDir, 'index-test');
87+
await fs.mkdir(indexDir, { recursive: true });
88+
89+
// Create a simple TypeScript file to index
90+
await fs.writeFile(
91+
path.join(indexDir, 'sample.ts'),
92+
`export function greet(name: string): string {
93+
return \`Hello, \${name}!\`;
94+
}
95+
96+
export class Calculator {
97+
add(a: number, b: number): number {
98+
return a + b;
99+
}
100+
}`
101+
);
102+
103+
// Capture logger output
104+
const loggedMessages: string[] = [];
105+
const loggerModule = await import('../utils/logger.js');
106+
const originalLog = loggerModule.logger.log;
107+
vi.spyOn(loggerModule.logger, 'log').mockImplementation((msg: string) => {
108+
loggedMessages.push(msg);
109+
});
110+
111+
// Mock process.exit to prevent test termination
112+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
113+
114+
// Create a program and add the command
115+
const program = new Command();
116+
program.addCommand(indexCommand);
117+
118+
// Run index command (skip git and github for faster test)
119+
await program.parseAsync(['node', 'cli', 'index', indexDir, '--no-git', '--no-github']);
120+
121+
exitSpy.mockRestore();
122+
loggerModule.logger.log = originalLog;
123+
124+
// Verify storage size is in the output
125+
const storageSizeLog = loggedMessages.find((msg) => msg.includes('Storage size:'));
126+
expect(storageSizeLog).toBeDefined();
127+
expect(storageSizeLog).toMatch(/Storage size:.*\d+(\.\d+)?\s*(B|KB|MB|GB)/);
128+
}, 30000); // 30s timeout for indexing
129+
});
75130
});

0 commit comments

Comments
 (0)