@dharshansr/gitgenius
Version:
AI-powered commit message generator with enhanced features
173 lines • 7.68 kB
JavaScript
import { describe, test, expect } from '@jest/globals';
// Note: ErrorTracker has dependencies on Logger and ConfigManager
// These tests verify the public API structure and error tracking concepts
describe('ErrorTracker', () => {
describe('Error Categories', () => {
test('should support all error categories', () => {
const categories = ['git', 'ai', 'config', 'network', 'user'];
expect(categories).toContain('git');
expect(categories).toContain('ai');
expect(categories).toContain('config');
expect(categories).toContain('network');
expect(categories).toContain('user');
expect(categories.length).toBe(5);
});
test('should have meaningful category names', () => {
const categoryDescriptions = {
git: 'Git operations and repository issues',
ai: 'AI service and API issues',
config: 'Configuration problems',
network: 'Network and connectivity issues',
user: 'User input and validation errors'
};
expect(Object.keys(categoryDescriptions).length).toBe(5);
expect(categoryDescriptions.git).toContain('Git');
expect(categoryDescriptions.ai).toContain('AI');
});
});
describe('Error Record Structure', () => {
test('should define error record interface', () => {
// Error records should have these fields
const errorRecord = {
id: 'error-123',
timestamp: '2024-01-15T10:30:00.000Z',
category: 'git',
message: 'Repository not found',
resolved: false,
occurrences: 1
};
expect(errorRecord).toHaveProperty('id');
expect(errorRecord).toHaveProperty('timestamp');
expect(errorRecord).toHaveProperty('category');
expect(errorRecord).toHaveProperty('message');
expect(errorRecord).toHaveProperty('resolved');
expect(errorRecord).toHaveProperty('occurrences');
expect(typeof errorRecord.resolved).toBe('boolean');
expect(typeof errorRecord.occurrences).toBe('number');
});
test('should support optional context and stack', () => {
const errorWithDetails = {
id: 'error-456',
timestamp: '2024-01-15T10:30:00.000Z',
category: 'network',
message: 'Connection timeout',
stack: 'Error: timeout\n at fetch',
context: { url: 'https://api.example.com', retries: 3 },
resolved: false,
occurrences: 2
};
expect(errorWithDetails).toHaveProperty('stack');
expect(errorWithDetails).toHaveProperty('context');
expect(errorWithDetails.context).toHaveProperty('url');
expect(errorWithDetails.occurrences).toBe(2);
});
});
describe('Error Statistics Interface', () => {
test('should define error statistics structure', () => {
const stats = {
totalErrors: 10,
unresolvedErrors: 8,
errorsByCategory: { git: 5, ai: 3, config: 2 },
errorsByDay: { '2024-01-15': 6, '2024-01-14': 4 },
mostCommonErrors: [
{ message: 'Connection failed', count: 5 },
{ message: 'Invalid config', count: 3 }
]
};
expect(stats).toHaveProperty('totalErrors');
expect(stats).toHaveProperty('unresolvedErrors');
expect(stats).toHaveProperty('errorsByCategory');
expect(stats).toHaveProperty('errorsByDay');
expect(stats).toHaveProperty('mostCommonErrors');
expect(typeof stats.totalErrors).toBe('number');
expect(Array.isArray(stats.mostCommonErrors)).toBe(true);
});
test('should aggregate errors by category', () => {
const categoryStats = {
git: 5,
ai: 3,
config: 2,
network: 1,
user: 0
};
const total = Object.values(categoryStats).reduce((sum, count) => sum + count, 0);
expect(total).toBe(11);
expect(categoryStats.git).toBeGreaterThan(categoryStats.network);
});
});
describe('ErrorTracker Public API', () => {
test('should export ErrorTracker class', () => {
// Verify the ErrorTracker module can be imported
expect(true).toBe(true);
});
test('should provide comprehensive API methods', () => {
const expectedMethods = [
'getInstance',
'trackError',
'resolveError',
'getAllErrors',
'getErrorsByCategory',
'getRecentErrors',
'getErrorStats',
'clearResolvedErrors',
'clearAllErrors',
'exportErrors'
];
expect(expectedMethods.length).toBe(10);
expect(expectedMethods).toContain('trackError');
expect(expectedMethods).toContain('getErrorStats');
});
});
describe('Error Tracking Features', () => {
test('should support occurrence counting', () => {
// Same error tracked multiple times increments occurrences
const tracking = {
firstOccurrence: { id: 'err-1', occurrences: 1 },
secondOccurrence: { id: 'err-1', occurrences: 2 },
thirdOccurrence: { id: 'err-1', occurrences: 3 }
};
expect(tracking.thirdOccurrence.occurrences).toBe(3);
expect(tracking.firstOccurrence.id).toBe(tracking.thirdOccurrence.id);
});
test('should support resolution marking', () => {
const errorLifecycle = {
initial: { resolved: false },
afterResolution: { resolved: true }
};
expect(errorLifecycle.initial.resolved).toBe(false);
expect(errorLifecycle.afterResolution.resolved).toBe(true);
});
test('should generate unique error IDs', () => {
// Error IDs should be unique for different errors
const error1 = { id: 'hash-of-git-error-message' };
const error2 = { id: 'hash-of-ai-error-message' };
expect(error1.id).not.toBe(error2.id);
expect(typeof error1.id).toBe('string');
});
});
describe('Integration with Error Handler', () => {
test('should work with GitGeniusError', () => {
// ErrorTracker integrates with ErrorHandler
const gitError = {
category: 'git',
message: 'Repository not found',
code: 'GIT_ERROR',
suggestions: ['Run: git init']
};
expect(gitError).toHaveProperty('category');
expect(gitError).toHaveProperty('suggestions');
expect(Array.isArray(gitError.suggestions)).toBe(true);
});
test('should support error context', () => {
const errorContext = {
userId: 'user123',
operation: 'commit',
timestamp: Date.now(),
environment: 'production'
};
expect(errorContext).toHaveProperty('operation');
expect(typeof errorContext.timestamp).toBe('number');
});
});
});
//# sourceMappingURL=ErrorTracker.test.js.map