|
1 | 1 | import { describe, it, expect } from 'vitest'; |
2 | | -import { validateDate, validateRepoPath, parseCommitData, runGitCommand, sanitizeInput } from './git-metrics.js'; |
| 2 | +import { validateDate, validateRepoPath, runGitCommand, sanitizeInput } from './git-metrics.js'; |
3 | 3 | import { resolve } from 'path'; |
4 | 4 | import { mkdirSync, rmSync } from 'fs'; |
5 | 5 |
|
@@ -79,54 +79,6 @@ describe('runGitCommand', () => { |
79 | 79 | }); |
80 | 80 | }); |
81 | 81 |
|
82 | | -describe('parseCommitData', () => { |
83 | | - it('should parse commit data with files', () => { |
84 | | - const output = runGitCommand( |
85 | | - REPO, |
86 | | - 'git log --since="2020-01-01" -5 --pretty=format:"%ad|%H" --date=short --numstat' |
87 | | - ); |
88 | | - const commits = parseCommitData(output); |
89 | | - |
90 | | - expect(Array.isArray(commits)).toBe(true); |
91 | | - if (commits.length > 0) { |
92 | | - expect(commits[0]).toHaveProperty('hash'); |
93 | | - expect(commits[0]).toHaveProperty('date'); |
94 | | - expect(commits[0]).toHaveProperty('files'); |
95 | | - expect(Array.isArray(commits[0].files)).toBe(true); |
96 | | - } |
97 | | - }); |
98 | | - |
99 | | - it('should handle empty output', () => { |
100 | | - const commits = parseCommitData(''); |
101 | | - expect(commits).toEqual([]); |
102 | | - }); |
103 | | - |
104 | | - it('should parse file changes correctly', () => { |
105 | | - const sampleOutput = `abc123|John Doe|john@example.com|2025-11-21|Initial commit |
106 | | -1\t2\tfile1.txt |
107 | | -3\t4\tfile2.txt |
108 | | -def456|Jane Doe|jane@example.com|2025-11-20|Fix bug |
109 | | -5\t6\tfile3.txt`; |
110 | | - |
111 | | - const commits = parseCommitData(sampleOutput); |
112 | | - expect(commits).toHaveLength(2); |
113 | | - expect(commits[0].date).toBe('2025-11-21'); |
114 | | - expect(commits[0].hash).toBe('abc123'); |
115 | | - expect(commits[0].files).toHaveLength(2); |
116 | | - expect(commits[0].files[0]).toEqual({ file: 'file1.txt', additions: 1, deletions: 2 }); |
117 | | - expect(commits[1].files[0]).toEqual({ file: 'file3.txt', additions: 5, deletions: 6 }); |
118 | | - }); |
119 | | - |
120 | | - it('should handle commits without files', () => { |
121 | | - const sampleOutput = `abc123|John Doe|john@example.com|2025-11-21|Initial commit |
122 | | -def456|Jane Doe|jane@example.com|2025-11-20|Fix bug`; |
123 | | - |
124 | | - const commits = parseCommitData(sampleOutput); |
125 | | - expect(commits).toHaveLength(2); |
126 | | - expect(commits[0].files).toHaveLength(0); |
127 | | - expect(commits[1].files).toHaveLength(0); |
128 | | - }); |
129 | | -}); |
130 | 82 |
|
131 | 83 | describe('Git Operations', () => { |
132 | 84 | it('should get commit stats', () => { |
@@ -179,32 +131,6 @@ describe('Git Operations', () => { |
179 | 131 | expect(typeof fileCount).toBe('object'); |
180 | 132 | }); |
181 | 133 |
|
182 | | - it('should calculate velocity trends', () => { |
183 | | - const output = runGitCommand( |
184 | | - REPO, |
185 | | - 'git log --since="2020-01-01" -10 --pretty=format:"%ad|%H" --date=short --numstat' |
186 | | - ); |
187 | | - |
188 | | - const commits = parseCommitData(output); |
189 | | - const periods: Record<string, { commits: number }> = {}; |
190 | | - |
191 | | - for (const commit of commits) { |
192 | | - if (!commit.date || typeof commit.date !== 'string') continue; |
193 | | - const date = new Date(commit.date); |
194 | | - if (isNaN(date.getTime())) continue; |
195 | | - |
196 | | - const weekStart = new Date(date); |
197 | | - weekStart.setDate(date.getDate() - date.getDay()); |
198 | | - const periodKey = weekStart.toISOString().split('T')[0]; |
199 | | - |
200 | | - if (!periods[periodKey]) { |
201 | | - periods[periodKey] = { commits: 0 }; |
202 | | - } |
203 | | - periods[periodKey].commits++; |
204 | | - } |
205 | | - |
206 | | - expect(typeof periods).toBe('object'); |
207 | | - }); |
208 | 134 |
|
209 | 135 | it('should handle date validation in velocity calculation', () => { |
210 | 136 | const commits = [ |
|
0 commit comments