mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
fix: update logger tests to use console.log instead of console.warn
- Modified logger test cases to reflect that the warn method uses console.log in Node.js implementation. - Updated expectations in feature-loader tests to align with the new logging behavior. - Ensured consistent logging behavior across tests for improved clarity and accuracy.
This commit is contained in:
@@ -78,11 +78,12 @@ describe('logger.ts', () => {
|
|||||||
|
|
||||||
setLogLevel(LogLevel.ERROR);
|
setLogLevel(LogLevel.ERROR);
|
||||||
logger.warn('warn message 1');
|
logger.warn('warn message 1');
|
||||||
expect(consoleSpy.warn).not.toHaveBeenCalled();
|
expect(consoleSpy.log).not.toHaveBeenCalled();
|
||||||
|
|
||||||
setLogLevel(LogLevel.WARN);
|
setLogLevel(LogLevel.WARN);
|
||||||
logger.warn('warn message 2');
|
logger.warn('warn message 2');
|
||||||
expect(consoleSpy.warn).toHaveBeenCalledWith('WARN [Test]', 'warn message 2');
|
// Note: warn uses console.log in Node.js implementation
|
||||||
|
expect(consoleSpy.log).toHaveBeenCalledWith('WARN [Test]', 'warn message 2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should log info when level is INFO or higher', () => {
|
it('should log info when level is INFO or higher', () => {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ describe('feature-loader.ts', () => {
|
|||||||
{ name: 'feature-2', isDirectory: () => true } as any,
|
{ name: 'feature-2', isDirectory: () => true } as any,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||||
|
|
||||||
vi.mocked(fs.readFile)
|
vi.mocked(fs.readFile)
|
||||||
.mockResolvedValueOnce(
|
.mockResolvedValueOnce(
|
||||||
@@ -183,7 +183,7 @@ describe('feature-loader.ts', () => {
|
|||||||
{ name: 'feature-1', isDirectory: () => true } as any,
|
{ name: 'feature-1', isDirectory: () => true } as any,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||||
|
|
||||||
vi.mocked(fs.readFile).mockResolvedValue('invalid json{');
|
vi.mocked(fs.readFile).mockResolvedValue('invalid json{');
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||||
import { createLogger, LogLevel, getLogLevel, setLogLevel } from '../src/logger';
|
import { createLogger, LogLevel, getLogLevel, setLogLevel, setColorsEnabled } from '../src/logger';
|
||||||
|
|
||||||
describe('logger.ts', () => {
|
describe('logger.ts', () => {
|
||||||
let originalConsoleError: typeof console.error;
|
let originalConsoleError: typeof console.error;
|
||||||
@@ -14,6 +14,9 @@ describe('logger.ts', () => {
|
|||||||
originalConsoleLog = console.log;
|
originalConsoleLog = console.log;
|
||||||
originalLogLevel = getLogLevel();
|
originalLogLevel = getLogLevel();
|
||||||
|
|
||||||
|
// Disable colors for predictable test output
|
||||||
|
setColorsEnabled(false);
|
||||||
|
|
||||||
// Mock console methods
|
// Mock console methods
|
||||||
console.error = vi.fn();
|
console.error = vi.fn();
|
||||||
console.warn = vi.fn();
|
console.warn = vi.fn();
|
||||||
@@ -73,8 +76,8 @@ describe('logger.ts', () => {
|
|||||||
logger.debug('debug message');
|
logger.debug('debug message');
|
||||||
|
|
||||||
expect(console.error).toHaveBeenCalledTimes(1);
|
expect(console.error).toHaveBeenCalledTimes(1);
|
||||||
expect(console.warn).toHaveBeenCalledTimes(1);
|
// Note: warn uses console.log in Node.js implementation
|
||||||
expect(console.log).not.toHaveBeenCalled();
|
expect(console.log).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should log error, warn, and info at INFO level', () => {
|
it('should log error, warn, and info at INFO level', () => {
|
||||||
@@ -87,8 +90,8 @@ describe('logger.ts', () => {
|
|||||||
logger.debug('debug message');
|
logger.debug('debug message');
|
||||||
|
|
||||||
expect(console.error).toHaveBeenCalledTimes(1);
|
expect(console.error).toHaveBeenCalledTimes(1);
|
||||||
expect(console.warn).toHaveBeenCalledTimes(1);
|
// Note: warn and info both use console.log in Node.js implementation
|
||||||
expect(console.log).toHaveBeenCalledTimes(1); // Only info, not debug
|
expect(console.log).toHaveBeenCalledTimes(2); // warn + info, not debug
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should log all messages at DEBUG level', () => {
|
it('should log all messages at DEBUG level', () => {
|
||||||
@@ -101,8 +104,8 @@ describe('logger.ts', () => {
|
|||||||
logger.debug('debug message');
|
logger.debug('debug message');
|
||||||
|
|
||||||
expect(console.error).toHaveBeenCalledTimes(1);
|
expect(console.error).toHaveBeenCalledTimes(1);
|
||||||
expect(console.warn).toHaveBeenCalledTimes(1);
|
// Note: warn, info, debug all use console.log in Node.js implementation
|
||||||
expect(console.log).toHaveBeenCalledTimes(2); // info + debug
|
expect(console.log).toHaveBeenCalledTimes(3); // warn + info + debug
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -129,13 +132,14 @@ describe('logger.ts', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('warn method', () => {
|
describe('warn method', () => {
|
||||||
it('should use console.warn', () => {
|
it('should use console.log with WARN prefix', () => {
|
||||||
const logger = createLogger('WarnTest');
|
const logger = createLogger('WarnTest');
|
||||||
setLogLevel(LogLevel.WARN);
|
setLogLevel(LogLevel.WARN);
|
||||||
|
|
||||||
logger.warn('warning message');
|
logger.warn('warning message');
|
||||||
|
|
||||||
expect(console.warn).toHaveBeenCalledWith('WARN [WarnTest]', 'warning message');
|
// Note: warn uses console.log in Node.js implementation
|
||||||
|
expect(console.log).toHaveBeenCalledWith('WARN [WarnTest]', 'warning message');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not log when level is below WARN', () => {
|
it('should not log when level is below WARN', () => {
|
||||||
@@ -144,7 +148,7 @@ describe('logger.ts', () => {
|
|||||||
|
|
||||||
logger.warn('should not appear');
|
logger.warn('should not appear');
|
||||||
|
|
||||||
expect(console.warn).not.toHaveBeenCalled();
|
expect(console.log).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user