Revert "Release 0.13.0"
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import chalk from 'chalk';
|
||||
|
||||
// Import the actual module to test
|
||||
import {
|
||||
@@ -18,14 +19,21 @@ import {
|
||||
taskExists,
|
||||
formatTaskId,
|
||||
findCycles,
|
||||
CONFIG,
|
||||
LOG_LEVELS,
|
||||
findTaskById,
|
||||
toKebabCase
|
||||
} from '../../scripts/modules/utils.js';
|
||||
|
||||
// Mock config-manager to provide config values
|
||||
const mockGetLogLevel = jest.fn(() => 'info'); // Default log level for tests
|
||||
jest.mock('../../scripts/modules/config-manager.js', () => ({
|
||||
getLogLevel: mockGetLogLevel
|
||||
// Mock other getters if needed by utils.js functions under test
|
||||
// Skip the import of detectCamelCaseFlags as we'll implement our own version for testing
|
||||
|
||||
// Mock chalk functions
|
||||
jest.mock('chalk', () => ({
|
||||
gray: jest.fn((text) => `gray:${text}`),
|
||||
blue: jest.fn((text) => `blue:${text}`),
|
||||
yellow: jest.fn((text) => `yellow:${text}`),
|
||||
red: jest.fn((text) => `red:${text}`),
|
||||
green: jest.fn((text) => `green:${text}`)
|
||||
}));
|
||||
|
||||
// Test implementation of detectCamelCaseFlags
|
||||
@@ -121,27 +129,23 @@ describe('Utils Module', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('log function', () => {
|
||||
// const originalConsoleLog = console.log; // Keep original for potential restore if needed
|
||||
describe('log function', () => {
|
||||
// Save original console.log
|
||||
const originalConsoleLog = console.log;
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock console.log for each test
|
||||
// console.log = jest.fn(); // REMOVE console.log spy
|
||||
mockGetLogLevel.mockClear(); // Clear mock calls
|
||||
console.log = jest.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Restore original console.log after each test
|
||||
// console.log = originalConsoleLog; // REMOVE console.log restore
|
||||
console.log = originalConsoleLog;
|
||||
});
|
||||
|
||||
test('should log messages according to log level from config-manager', () => {
|
||||
// Test with info level (default from mock)
|
||||
mockGetLogLevel.mockReturnValue('info');
|
||||
|
||||
// Spy on console.log JUST for this test to verify calls
|
||||
const consoleSpy = jest
|
||||
.spyOn(console, 'log')
|
||||
.mockImplementation(() => {});
|
||||
test('should log messages according to log level', () => {
|
||||
// Test with info level (1)
|
||||
CONFIG.logLevel = 'info';
|
||||
|
||||
log('debug', 'Debug message');
|
||||
log('info', 'Info message');
|
||||
@@ -149,47 +153,36 @@ describe('Utils Module', () => {
|
||||
log('error', 'Error message');
|
||||
|
||||
// Debug should not be logged (level 0 < 1)
|
||||
expect(consoleSpy).not.toHaveBeenCalledWith(
|
||||
expect(console.log).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining('Debug message')
|
||||
);
|
||||
|
||||
// Info and above should be logged
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Info message')
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Warning message')
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Error message')
|
||||
);
|
||||
|
||||
// Verify the formatting includes text prefixes
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('[INFO]')
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('[WARN]')
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('[ERROR]')
|
||||
);
|
||||
|
||||
// Verify getLogLevel was called by log function
|
||||
expect(mockGetLogLevel).toHaveBeenCalled();
|
||||
|
||||
// Restore spy for this test
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('should not log messages below the configured log level', () => {
|
||||
// Set log level to error via mock
|
||||
mockGetLogLevel.mockReturnValue('error');
|
||||
|
||||
// Spy on console.log JUST for this test
|
||||
const consoleSpy = jest
|
||||
.spyOn(console, 'log')
|
||||
.mockImplementation(() => {});
|
||||
// Set log level to error (3)
|
||||
CONFIG.logLevel = 'error';
|
||||
|
||||
log('debug', 'Debug message');
|
||||
log('info', 'Info message');
|
||||
@@ -197,44 +190,30 @@ describe('Utils Module', () => {
|
||||
log('error', 'Error message');
|
||||
|
||||
// Only error should be logged
|
||||
expect(consoleSpy).not.toHaveBeenCalledWith(
|
||||
expect(console.log).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining('Debug message')
|
||||
);
|
||||
expect(consoleSpy).not.toHaveBeenCalledWith(
|
||||
expect(console.log).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining('Info message')
|
||||
);
|
||||
expect(consoleSpy).not.toHaveBeenCalledWith(
|
||||
expect(console.log).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining('Warning message')
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Error message')
|
||||
);
|
||||
|
||||
// Verify getLogLevel was called
|
||||
expect(mockGetLogLevel).toHaveBeenCalled();
|
||||
|
||||
// Restore spy for this test
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('should join multiple arguments into a single message', () => {
|
||||
mockGetLogLevel.mockReturnValue('info');
|
||||
// Spy on console.log JUST for this test
|
||||
const consoleSpy = jest
|
||||
.spyOn(console, 'log')
|
||||
.mockImplementation(() => {});
|
||||
|
||||
CONFIG.logLevel = 'info';
|
||||
log('info', 'Message', 'with', 'multiple', 'parts');
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Message with multiple parts')
|
||||
);
|
||||
|
||||
// Restore spy for this test
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('readJSON function', () => {
|
||||
describe('readJSON function', () => {
|
||||
test('should read and parse a valid JSON file', () => {
|
||||
const testData = { key: 'value', nested: { prop: true } };
|
||||
fsReadFileSyncSpy.mockReturnValue(JSON.stringify(testData));
|
||||
@@ -280,7 +259,7 @@ describe('Utils Module', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('writeJSON function', () => {
|
||||
describe('writeJSON function', () => {
|
||||
test('should write JSON data to a file', () => {
|
||||
const testData = { key: 'value', nested: { prop: true } };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user