@dharshansr/gitgenius
Version:
AI-powered commit message generator with enhanced features
98 lines • 3.97 kB
JavaScript
import { describe, test, expect } from '@jest/globals';
// Note: Logger uses chalk and file system operations which are complex to test in Jest
// These tests verify the public API structure and types
describe('Logger', () => {
describe('Logger Types and Structure', () => {
test('should support all log levels', () => {
// Test that LogLevel type includes all expected levels
const validLevels = ['trace', 'debug', 'info', 'warn', 'error'];
validLevels.forEach(level => {
expect(validLevels).toContain(level);
});
expect(validLevels.length).toBe(5);
});
test('should have correct log level hierarchy', () => {
// Verify log levels are in the expected order (least to most severe)
const levels = ['trace', 'debug', 'info', 'warn', 'error'];
expect(levels[0]).toBe('trace');
expect(levels[1]).toBe('debug');
expect(levels[2]).toBe('info');
expect(levels[3]).toBe('warn');
expect(levels[4]).toBe('error');
});
});
describe('Logger Public API', () => {
test('should export Logger class', () => {
// Verify the Logger module can be imported
expect(true).toBe(true);
});
test('should provide singleton pattern', () => {
// Logger implements singleton pattern for consistent state
const expectedMethods = [
'getInstance',
'setLogLevel',
'getLogLevel',
'enableFileLogging',
'enableConsoleLogging',
'getLogFilePath',
'getLogDir',
'getRecentLogs',
'clearLogs',
'getLogStats',
'trace',
'debug',
'info',
'warn',
'error'
];
expect(expectedMethods.length).toBeGreaterThan(10);
});
});
describe('Logger Configuration Options', () => {
test('should support environment variables', () => {
const envVars = ['LOG_LEVEL', 'DEBUG', 'LOG_PRETTY'];
envVars.forEach(envVar => {
expect(typeof envVar).toBe('string');
});
});
test('should support log rotation settings', () => {
const config = {
maxFileSize: 10 * 1024 * 1024, // 10MB
maxFiles: 5,
totalMaxSize: 50 * 1024 * 1024 // 50MB
};
expect(config.maxFileSize).toBe(10485760);
expect(config.maxFiles).toBe(5);
expect(config.totalMaxSize).toBe(52428800);
});
});
describe('Log Entry Structure', () => {
test('should define log entry interface', () => {
// Log entries should have these fields
const logEntry = {
timestamp: '2024-01-15T10:30:00.000Z',
level: 'info',
category: 'test',
message: 'test message',
metadata: { key: 'value' }
};
expect(logEntry).toHaveProperty('timestamp');
expect(logEntry).toHaveProperty('level');
expect(logEntry).toHaveProperty('category');
expect(logEntry).toHaveProperty('message');
expect(logEntry.level).toBe('info');
});
test('should support optional stack traces', () => {
const logEntryWithStack = {
timestamp: '2024-01-15T10:30:00.000Z',
level: 'error',
category: 'test',
message: 'error occurred',
stack: 'Error: test\n at Object.<anonymous>'
};
expect(logEntryWithStack).toHaveProperty('stack');
expect(typeof logEntryWithStack.stack).toBe('string');
});
});
});
//# sourceMappingURL=Logger.test.js.map