Skip to content

Commit c0e6696

Browse files
committed
test: improve coverage to 80.86%
- Add comprehensive tests for handleGetConventionalCommits - Test conventional commit parsing and breaking change detection - Add tests for commit types, scopes, and release tracking - Increase handlers.ts coverage from 76.8% to 90.4%
1 parent d80b527 commit c0e6696

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

src/handlers.test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,89 @@ describe('Handler Functions', () => {
223223
expect(result).toHaveProperty('staleFiles');
224224
});
225225
});
226+
227+
describe('handleGetConventionalCommits', () => {
228+
let conventionalRepo: string;
229+
230+
beforeAll(() => {
231+
conventionalRepo = join(tmpdir(), `conventional-test-${Date.now()}`);
232+
mkdirSync(conventionalRepo, { recursive: true });
233+
234+
execSync('git init', { cwd: conventionalRepo });
235+
execSync('git config user.email "test@example.com"', { cwd: conventionalRepo });
236+
execSync('git config user.name "Test User"', { cwd: conventionalRepo });
237+
238+
writeFileSync(join(conventionalRepo, 'file1.txt'), 'content1\n');
239+
execSync('git add .', { cwd: conventionalRepo });
240+
execSync('git commit -m "feat(core): add new feature"', { cwd: conventionalRepo });
241+
242+
writeFileSync(join(conventionalRepo, 'file2.txt'), 'content2\n');
243+
execSync('git add .', { cwd: conventionalRepo });
244+
execSync('git commit -m "fix: resolve bug"', { cwd: conventionalRepo });
245+
246+
writeFileSync(join(conventionalRepo, 'file3.txt'), 'content3\n');
247+
execSync('git add .', { cwd: conventionalRepo });
248+
execSync('git commit -m "feat!: breaking change"', { cwd: conventionalRepo });
249+
250+
execSync('git tag v1.0.0', { cwd: conventionalRepo });
251+
});
252+
253+
it('should analyze conventional commits', () => {
254+
const result = handlers.handleGetConventionalCommits({
255+
repo_path: conventionalRepo,
256+
since: testDate,
257+
});
258+
259+
expect(result).toHaveProperty('totalCommits');
260+
expect(result).toHaveProperty('conventionalCommits');
261+
expect(result).toHaveProperty('conventionalPercentage');
262+
expect(result).toHaveProperty('commitTypes');
263+
expect(result).toHaveProperty('topScopes');
264+
expect(result).toHaveProperty('breakingChanges');
265+
expect(result).toHaveProperty('recentReleases');
266+
expect(result).toHaveProperty('releaseFrequency');
267+
268+
expect(result.totalCommits).toBe(3);
269+
expect(result.conventionalCommits).toBe(3);
270+
expect(result.conventionalPercentage).toBe('100.0%');
271+
expect(result.breakingChanges).toBe(1);
272+
});
273+
274+
it('should identify commit types', () => {
275+
const result = handlers.handleGetConventionalCommits({
276+
repo_path: conventionalRepo,
277+
since: testDate,
278+
});
279+
280+
expect(Array.isArray(result.commitTypes)).toBe(true);
281+
const types = result.commitTypes.map((t: any) => t.type);
282+
expect(types).toContain('feat');
283+
expect(types).toContain('fix');
284+
});
285+
286+
it('should identify scopes', () => {
287+
const result = handlers.handleGetConventionalCommits({
288+
repo_path: conventionalRepo,
289+
since: testDate,
290+
});
291+
292+
expect(Array.isArray(result.topScopes)).toBe(true);
293+
if (result.topScopes.length > 0) {
294+
expect(result.topScopes[0]).toHaveProperty('scope');
295+
expect(result.topScopes[0]).toHaveProperty('count');
296+
}
297+
});
298+
299+
it('should list releases', () => {
300+
const result = handlers.handleGetConventionalCommits({
301+
repo_path: conventionalRepo,
302+
since: testDate,
303+
});
304+
305+
expect(Array.isArray(result.recentReleases)).toBe(true);
306+
expect(result.recentReleases.length).toBeGreaterThan(0);
307+
expect(result.recentReleases[0]).toHaveProperty('tag');
308+
expect(result.recentReleases[0]).toHaveProperty('date');
309+
});
310+
});
226311
});

src/server-handlers.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,32 @@ describe('Server Request Handlers', () => {
8282
});
8383
});
8484

85+
describe('get_conventional_commits handler', () => {
86+
it('should require repo_path and since', () => {
87+
const args = { repo_path: '/test', since: '2025-11-01' };
88+
expect(args.repo_path).toBeDefined();
89+
expect(args.since).toBeDefined();
90+
});
91+
92+
it('should parse conventional commit format', () => {
93+
const message = 'feat(core): add new feature';
94+
const regex = /^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(([^)]+)\))?(!)?:/;
95+
const match = message.match(regex);
96+
97+
expect(match).not.toBeNull();
98+
expect(match![1]).toBe('feat');
99+
expect(match![3]).toBe('core');
100+
});
101+
102+
it('should detect breaking changes', () => {
103+
const message1 = 'feat!: breaking change';
104+
const message2 = 'feat: normal change\n\nBREAKING CHANGE: details';
105+
106+
expect(message1.includes('!')).toBe(true);
107+
expect(message2.includes('BREAKING CHANGE')).toBe(true);
108+
});
109+
});
110+
85111
describe('Error handling', () => {
86112
it('should handle git command failures', () => {
87113
vi.mocked(execSync).mockImplementation(() => {

0 commit comments

Comments
 (0)