diff --git a/jest.config.js b/jest.config.js index e1602813d..75b84aaf7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -162,6 +162,10 @@ export default { // The test environment that will be used for testing testEnvironment: 'node', + // Force Jest to exit after all tests complete — prevents hanging on open MongoDB + // handles from integration tests whose afterAll disconnect races with Jest's exit + forceExit: true, + // Global timeout for tests and hooks (integration tests bootstrap MongoDB + Express) testTimeout: 15000, diff --git a/lib/services/logger.js b/lib/services/logger.js index 49bd92049..817e54fa1 100644 --- a/lib/services/logger.js +++ b/lib/services/logger.js @@ -28,7 +28,11 @@ const logger = new winston.createLogger({ new winston.transports.Console({ level: logLevel, format: consoleFormat, - handleExceptions: true, + // Disable exception handling in test env — each jest.resetModules() re-imports + // this module, and handleExceptions:true registers a new process.uncaughtException + // listener on every import without ever removing the old one, causing listener + // accumulation and heap growth across module reloads in beforeEach hooks. + handleExceptions: process.env.NODE_ENV !== 'test', }), ], exitOnError: false, @@ -71,7 +75,8 @@ const getLogOptions = () => { eol: '\n', tailable: true, showLevel: true, - handleExceptions: true, + // Same guard as the Console transport — see comment at top of createLogger call + handleExceptions: process.env.NODE_ENV !== 'test', humanReadableUnhandledException: true, }; };