From d3b8ea929d8d002b458d78f05ed21c670d870faf Mon Sep 17 00:00:00 2001 From: Claude Code Date: Mon, 6 Oct 2025 22:23:32 +0000 Subject: [PATCH 1/2] Suppress debug output during test runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clean up test output by preventing debug logging from cluttering test results while maintaining full debug functionality in production. Changes: - WebSocketConnection: Only call printOutput() in non-test environments - test/shared/setup.mjs: Disable debug module by default during tests - test/unit/core/utils.test.mjs: Properly cleanup debug state in afterEach - test/unit/core/utils-enhanced.test.mjs: Fix test assertions and cleanup - vitest.config.mjs: Add reporter configuration Benefits: - Clean, readable test output without debug noise - Maintains full debug functionality in production - Tests that specifically need debug can enable it explicitly - All 632 tests passing with zero debug output Before: Tests showed verbose socket events, errors, and debug messages After: Clean test output showing only test results 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/WebSocketConnection.js | 5 ++++- test/shared/setup.mjs | 17 ++++++++++++++++- test/unit/core/utils-enhanced.test.mjs | 15 ++++++++++++++- test/unit/core/utils.test.mjs | 5 +++++ vitest.config.mjs | 3 +++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/WebSocketConnection.js b/lib/WebSocketConnection.js index 377118f0..62f42bb0 100644 --- a/lib/WebSocketConnection.js +++ b/lib/WebSocketConnection.js @@ -313,7 +313,10 @@ class WebSocketConnection extends EventEmitter { this.emit('error', error); } this.socket.destroy(); - this._debug.printOutput(); + // Only print debug output in non-test environments to avoid cluttering test output + if (process.env.NODE_ENV !== 'test') { + this._debug.printOutput(); + } } handleSocketEnd() { diff --git a/test/shared/setup.mjs b/test/shared/setup.mjs index f00a742c..0e919204 100644 --- a/test/shared/setup.mjs +++ b/test/shared/setup.mjs @@ -5,19 +5,34 @@ import { stopAllServers } from '../helpers/test-server.mjs'; // Vitest adds exit/beforeExit listeners for each test file with spawned processes process.setMaxListeners(30); +// Disable debug output during tests unless explicitly enabled +if (!process.env.DEBUG) { + const debug = require('debug'); + debug.disable(); +} + // Global test setup for each test file beforeEach(() => { // Clear all mocks and timers vi.clearAllTimers(); vi.clearAllMocks(); + + // Note: We don't disable debug in beforeEach as some tests need to enable it + // Tests that enable DEBUG should clean up properly in their own afterEach }); afterEach(async () => { // Restore all mocks vi.restoreAllMocks(); - + // Clean up any test servers await stopAllServers(); + + // Re-disable debug after each test to prevent leakage + if (!process.env.DEBUG) { + const debug = require('debug'); + debug.disable(); + } }); // Set up global test configuration diff --git a/test/unit/core/utils-enhanced.test.mjs b/test/unit/core/utils-enhanced.test.mjs index fbcbae37..3ab662c6 100644 --- a/test/unit/core/utils-enhanced.test.mjs +++ b/test/unit/core/utils-enhanced.test.mjs @@ -20,8 +20,13 @@ describe('Utils Module - Enhanced Coverage', () => { }); afterEach(() => { + const debug = require('debug'); + debug.disable(); if (originalDebugEnv !== undefined) { process.env.DEBUG = originalDebugEnv; + if (originalDebugEnv) { + debug.enable(originalDebugEnv); + } } else { delete process.env.DEBUG; } @@ -62,8 +67,13 @@ describe('Utils Module - Enhanced Coverage', () => { }); afterEach(() => { + const debug = require('debug'); + debug.disable(); if (originalDebugEnv !== undefined) { process.env.DEBUG = originalDebugEnv; + if (originalDebugEnv) { + debug.enable(originalDebugEnv); + } } else { delete process.env.DEBUG; } @@ -81,9 +91,12 @@ describe('Utils Module - Enhanced Coverage', () => { expect(mockLog).toHaveBeenCalled(); // Verify the format includes timestamp and uniqueID + // printOutput calls logFunction.apply(global, args) where args includes: + // [formatString, date, uniqueID, ...originalArgs] const firstCall = mockLog.mock.calls[0]; expect(firstCall).toBeDefined(); - expect(firstCall[0]).toContain('test-id'); + // The uniqueID should be in args[2] (after formatString and date) + expect(firstCall[2]).toBe('test-id'); } }); diff --git a/test/unit/core/utils.test.mjs b/test/unit/core/utils.test.mjs index 91271ce2..b3fc0747 100644 --- a/test/unit/core/utils.test.mjs +++ b/test/unit/core/utils.test.mjs @@ -251,8 +251,13 @@ describe('Utils Module', () => { }); afterEach(() => { + const debug = require('debug'); + debug.disable(); if (originalDebugEnv !== undefined) { process.env.DEBUG = originalDebugEnv; + if (originalDebugEnv) { + debug.enable(originalDebugEnv); + } } else { delete process.env.DEBUG; } diff --git a/vitest.config.mjs b/vitest.config.mjs index 3097e75f..0f3c2f14 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -11,6 +11,9 @@ export default defineConfig({ singleThread: true } }, + // Silence debug output during tests + silent: false, + reporters: ['default'], // Timeouts for WebSocket operations testTimeout: 15000, hookTimeout: 15000, From 89fecc3c30c6fd8f2a8de90a180e173a6c49abcb Mon Sep 17 00:00:00 2001 From: Claude Code Date: Mon, 6 Oct 2025 22:27:25 +0000 Subject: [PATCH 2/2] Address Gemini code review comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improvements based on Gemini's medium-priority feedback: 1. Centralize debug module imports: - test/shared/setup.mjs: Use import at top instead of require in hooks - test/unit/core/utils.test.mjs: Add import debug at top, reuse in hooks - test/unit/core/utils-enhanced.test.mjs: Add import debug at top, reuse in hooks 2. Clean up redundant configuration: - vitest.config.mjs: Remove redundant silent and reporters defaults Benefits: - Consistent ES module import style across all test files - DRY principle - import once, reuse throughout the file - Cleaner vitest configuration without unnecessary defaults All 632 tests still passing with zero debug output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- test/shared/setup.mjs | 3 +-- test/unit/core/utils-enhanced.test.mjs | 3 +-- test/unit/core/utils.test.mjs | 2 +- vitest.config.mjs | 3 --- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/test/shared/setup.mjs b/test/shared/setup.mjs index 0e919204..e316427d 100644 --- a/test/shared/setup.mjs +++ b/test/shared/setup.mjs @@ -1,5 +1,6 @@ import { beforeEach, afterEach, vi } from 'vitest'; import { stopAllServers } from '../helpers/test-server.mjs'; +import debug from 'debug'; // Increase max listeners to avoid warnings when running many tests with child processes // Vitest adds exit/beforeExit listeners for each test file with spawned processes @@ -7,7 +8,6 @@ process.setMaxListeners(30); // Disable debug output during tests unless explicitly enabled if (!process.env.DEBUG) { - const debug = require('debug'); debug.disable(); } @@ -30,7 +30,6 @@ afterEach(async () => { // Re-disable debug after each test to prevent leakage if (!process.env.DEBUG) { - const debug = require('debug'); debug.disable(); } }); diff --git a/test/unit/core/utils-enhanced.test.mjs b/test/unit/core/utils-enhanced.test.mjs index 3ab662c6..f2ec89a9 100644 --- a/test/unit/core/utils-enhanced.test.mjs +++ b/test/unit/core/utils-enhanced.test.mjs @@ -9,6 +9,7 @@ */ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import * as utils from '../../../lib/utils.js'; +import debug from 'debug'; describe('Utils Module - Enhanced Coverage', () => { describe('BufferingLogger.printOutput() behavior', () => { @@ -20,7 +21,6 @@ describe('Utils Module - Enhanced Coverage', () => { }); afterEach(() => { - const debug = require('debug'); debug.disable(); if (originalDebugEnv !== undefined) { process.env.DEBUG = originalDebugEnv; @@ -67,7 +67,6 @@ describe('Utils Module - Enhanced Coverage', () => { }); afterEach(() => { - const debug = require('debug'); debug.disable(); if (originalDebugEnv !== undefined) { process.env.DEBUG = originalDebugEnv; diff --git a/test/unit/core/utils.test.mjs b/test/unit/core/utils.test.mjs index b3fc0747..79175d10 100644 --- a/test/unit/core/utils.test.mjs +++ b/test/unit/core/utils.test.mjs @@ -11,6 +11,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import { EventEmitter } from 'events'; import * as utils from '../../../lib/utils.js'; +import debug from 'debug'; describe('Utils Module', () => { describe('noop()', () => { @@ -251,7 +252,6 @@ describe('Utils Module', () => { }); afterEach(() => { - const debug = require('debug'); debug.disable(); if (originalDebugEnv !== undefined) { process.env.DEBUG = originalDebugEnv; diff --git a/vitest.config.mjs b/vitest.config.mjs index 0f3c2f14..3097e75f 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -11,9 +11,6 @@ export default defineConfig({ singleThread: true } }, - // Silence debug output during tests - silent: false, - reporters: ['default'], // Timeouts for WebSocket operations testTimeout: 15000, hookTimeout: 15000,