fixed logger tests
This commit is contained in:
parent
d836e766d5
commit
38b523d2c0
4 changed files with 21 additions and 19 deletions
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import { Logger } from '../src';
|
||||
import { Logger, shutdownLoggers } from '../src';
|
||||
import { loggerTestHelpers } from './setup';
|
||||
|
||||
describe('Advanced Logger Features', () => {
|
||||
|
|
@ -16,14 +16,10 @@ describe('Advanced Logger Features', () => {
|
|||
beforeEach(() => {
|
||||
testLoggerInstance = loggerTestHelpers.createTestLogger('advanced-features');
|
||||
logger = testLoggerInstance.logger;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
}); afterEach(async () => {
|
||||
testLoggerInstance.clearCapturedLogs();
|
||||
// Force garbage collection to clean up any potential circular references
|
||||
if (global.gc) {
|
||||
global.gc();
|
||||
}
|
||||
// Clear any global logger cache
|
||||
await shutdownLoggers();
|
||||
});
|
||||
|
||||
describe('Complex Metadata Handling', () => {
|
||||
|
|
@ -148,8 +144,7 @@ describe('Advanced Logger Features', () => {
|
|||
expect(logs.length).toBe(1);
|
||||
expect(logs[0].context).toBe('batch processing');
|
||||
});
|
||||
|
||||
it('should handle error objects with circular references', () => {
|
||||
it('should handle error objects with circular references', () => {
|
||||
const errorWithCircular: any = { name: 'CircularError', message: 'Circular reference error' };
|
||||
// Create a simple circular reference
|
||||
errorWithCircular.self = errorWithCircular;
|
||||
|
|
@ -162,6 +157,9 @@ describe('Advanced Logger Features', () => {
|
|||
const logs = testLoggerInstance.getCapturedLogs();
|
||||
expect(logs.length).toBe(1);
|
||||
expect(logs[0].level).toBe('error');
|
||||
|
||||
// Clean up circular reference to prevent memory issues
|
||||
delete errorWithCircular.self;
|
||||
});
|
||||
});
|
||||
describe('Performance and Edge Cases', () => {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import { Logger, getLogger, createLogger } from '../src';
|
||||
import { Logger, getLogger, createLogger, shutdownLoggers } from '../src';
|
||||
import { loggerTestHelpers } from './setup';
|
||||
|
||||
describe('Basic Logger Tests', () => {
|
||||
|
|
@ -16,9 +16,10 @@ describe('Basic Logger Tests', () => {
|
|||
testLoggerInstance = loggerTestHelpers.createTestLogger('utils-test');
|
||||
logger = testLoggerInstance.logger;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
afterEach(async () => {
|
||||
testLoggerInstance.clearCapturedLogs();
|
||||
// Clear any global logger cache
|
||||
await shutdownLoggers();
|
||||
});
|
||||
|
||||
describe('Logger Factory Functions', () => {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
|||
import {
|
||||
Logger,
|
||||
createLogger,
|
||||
getLogger
|
||||
getLogger,
|
||||
shutdownLoggers
|
||||
} from '../src';
|
||||
import { loggerTestHelpers } from './setup';
|
||||
|
||||
|
|
@ -20,9 +21,10 @@ describe('Logger Integration Tests', () => {
|
|||
testLoggerInstance = loggerTestHelpers.createTestLogger('integration-test');
|
||||
logger = testLoggerInstance.logger;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
afterEach(async () => {
|
||||
testLoggerInstance.clearCapturedLogs();
|
||||
// Clear any global logger cache
|
||||
await shutdownLoggers();
|
||||
});
|
||||
|
||||
describe('Core Logger Functionality', () => {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* Provides utilities and mocks for testing logging operations.
|
||||
*/
|
||||
|
||||
import { Logger, LogMetadata } from '../src';
|
||||
import { Logger, LogMetadata, shutdownLoggers } from '../src';
|
||||
import { afterAll, afterEach, beforeAll, beforeEach } from 'bun:test';
|
||||
|
||||
// Store original console methods
|
||||
|
|
@ -178,8 +178,9 @@ beforeAll(() => {
|
|||
});
|
||||
|
||||
// Clean up after each test
|
||||
afterEach(() => {
|
||||
// loggerTestHelpers.clearCapturedLogs(); // REMOVE this if it targeted a global array
|
||||
afterEach(async () => {
|
||||
// Clear logger cache to prevent state pollution between tests
|
||||
await shutdownLoggers();
|
||||
});
|
||||
|
||||
// Restore everything after tests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue