UNPKG

claude-flow-depth

Version:

DEPTH Methodology Installer - Ousterhout-First Development for Claude Code

116 lines (99 loc) 4.72 kB
/** * Logger Utility Tests * * DEPTH Testing Strategy: * - Validate simple interface behavior * - Ensure information hiding works correctly * - Test that complexity is properly encapsulated */ import { test } from 'node:test'; import assert from 'node:assert'; import { logger } from '../src/utils/logger.js'; test('Logger Interface Simplicity', async (t) => { await t.test('should provide simple logging interface', () => { // Test that all expected methods are available assert.ok(typeof logger.debug === 'function', 'debug method should be available'); assert.ok(typeof logger.info === 'function', 'info method should be available'); assert.ok(typeof logger.warn === 'function', 'warn method should be available'); assert.ok(typeof logger.error === 'function', 'error method should be available'); }); await t.test('should hide implementation complexity', () => { // Test that internal implementation is not exposed const loggerProperties = Object.getOwnPropertyNames(logger); // Should not expose private implementation details assert.ok(!loggerProperties.includes('config'), 'config should be hidden'); assert.ok(!loggerProperties.includes('levels'), 'levels should be hidden'); assert.ok(!loggerProperties.includes('log'), 'internal log method should be hidden'); }); await t.test('should work without throwing errors', () => { // Test that the simple interface works without exposing complexity assert.doesNotThrow(() => { logger.debug('Test debug message'); logger.info('Test info message'); logger.warn('Test warn message'); logger.error('Test error message'); }, 'logging methods should work without errors'); }); }); test('Logger Information Hiding', async (t) => { await t.test('should encapsulate formatting complexity', () => { // Test that formatting logic is hidden // We can't directly test the formatting since it's hidden, // but we can ensure the interface works consistently assert.doesNotThrow(() => { logger.info('Simple message'); logger.info('Message with', 'multiple', 'arguments'); logger.info('Message with object', { key: 'value' }); }, 'should handle various message formats'); }); await t.test('should hide level management complexity', () => { // Test that level checking logic is hidden // The interface should work regardless of level configuration const originalEnv = process.env.LOG_LEVEL; try { // Test with different log levels process.env.LOG_LEVEL = 'debug'; assert.doesNotThrow(() => logger.debug('Debug message'), 'should work with debug level'); process.env.LOG_LEVEL = 'error'; assert.doesNotThrow(() => logger.info('Info message'), 'should work with error level'); } finally { // Restore original environment if (originalEnv !== undefined) { process.env.LOG_LEVEL = originalEnv; } else { delete process.env.LOG_LEVEL; } } }); }); test('DEPTH Principles in Logger', async (t) => { await t.test('should demonstrate deep module pattern', () => { // Simple interface with rich functionality // The logger provides comprehensive logging capabilities // through a very simple interface const interfaceMethods = ['debug', 'info', 'warn', 'error']; interfaceMethods.forEach(method => { assert.ok(typeof logger[method] === 'function', `${method} should provide rich functionality`); }); // Test that methods handle various input types (rich functionality) assert.doesNotThrow(() => { logger.info('String message'); logger.info('Number:', 42); logger.info('Object:', { test: true }); logger.info('Array:', [1, 2, 3]); logger.info('Multiple args:', 'arg1', 'arg2', { arg3: 'value' }); }, 'simple interface should handle complex inputs'); }); await t.test('should push complexity downward', () => { // All complexity should be hidden in private methods // Public interface should be minimal and simple const publicMethods = Object.getOwnPropertyNames(Object.getPrototypeOf(logger)) .filter(name => name !== 'constructor' && typeof logger[name] === 'function'); // Should only expose the 4 main logging methods assert.ok(publicMethods.length <= 4, 'should have minimal public interface'); assert.ok(publicMethods.includes('debug'), 'should include debug'); assert.ok(publicMethods.includes('info'), 'should include info'); assert.ok(publicMethods.includes('warn'), 'should include warn'); assert.ok(publicMethods.includes('error'), 'should include error'); }); });