mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 05:23:08 +00:00
test: implement comprehensive testing improvements from PR #104 review
Major improvements based on comprehensive test suite review: Test Fixes: - Fix all 78 failing tests across logger, MSW, and validator tests - Fix console spy management in logger tests with proper DEBUG env handling - Fix MSW test environment restoration in session-management.test.ts - Fix workflow validator tests by adding proper node connections - Fix mock setup issues in edge case tests Test Organization: - Split large config-validator.test.ts (1,075 lines) into 4 focused files - Rename 63+ tests to follow "should X when Y" naming convention - Add comprehensive edge case test files for all major validators - Create tests/README.md with testing guidelines and best practices New Features: - Add ConfigValidator.validateBatch() method for bulk validation - Add edge case coverage for null/undefined, boundaries, invalid data - Add CI-aware performance test timeouts - Add JSDoc comments to test utilities and factories - Add workflow duplicate node name validation tests Results: - All tests passing: 1,356 passed, 19 skipped - Test coverage: 85.34% statements, 85.3% branches - From 78 failures to 0 failures 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,16 +6,38 @@ describe('Logger', () => {
|
||||
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
||||
let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
|
||||
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
||||
let originalDebug: string | undefined;
|
||||
|
||||
beforeEach(() => {
|
||||
logger = new Logger({ timestamp: false, prefix: 'test' });
|
||||
// Save original DEBUG value and enable debug for logger tests
|
||||
originalDebug = process.env.DEBUG;
|
||||
process.env.DEBUG = 'true';
|
||||
|
||||
// Create spies before creating logger
|
||||
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
|
||||
// Create logger after spies and env setup
|
||||
logger = new Logger({ timestamp: false, prefix: 'test' });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Restore all mocks first
|
||||
vi.restoreAllMocks();
|
||||
|
||||
// Restore original DEBUG value with more robust handling
|
||||
try {
|
||||
if (originalDebug === undefined) {
|
||||
// Use Reflect.deleteProperty for safer deletion
|
||||
Reflect.deleteProperty(process.env, 'DEBUG');
|
||||
} else {
|
||||
process.env.DEBUG = originalDebug;
|
||||
}
|
||||
} catch (error) {
|
||||
// If deletion fails, set to empty string as fallback
|
||||
process.env.DEBUG = '';
|
||||
}
|
||||
});
|
||||
|
||||
describe('log levels', () => {
|
||||
@@ -80,6 +102,7 @@ describe('Logger', () => {
|
||||
});
|
||||
|
||||
it('should include timestamp when enabled', () => {
|
||||
// Need to create a new logger instance, but ensure DEBUG is set first
|
||||
const timestampLogger = new Logger({ timestamp: true, prefix: 'test' });
|
||||
const dateSpy = vi.spyOn(Date.prototype, 'toISOString').mockReturnValue('2024-01-01T00:00:00.000Z');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user