Joachim Van Herwegen 6248ed0938 refactor: Replace linting configurations
The previous package was outdated, preventing us from updating TS.
This one also lints YAML and JSON,
and applies many more rules to the test files,
explaining all the changes in this PR.
2023-11-02 09:49:17 +01:00

41 lines
1.2 KiB
TypeScript

import { getLoggerFor, resetInternalLoggerFactory, setGlobalLoggerFactory } from '../../../src/logging/LogUtil';
let currentFactory: any;
class Dummy {
private readonly label = 'dummy';
}
describe('LogUtil', (): void => {
beforeAll((): void => {
resetInternalLoggerFactory();
resetInternalLoggerFactory({
get loggerFactory(): any {
return currentFactory;
},
set loggerFactory(value: any) {
currentFactory = value;
},
createLogger: jest.fn((label: string): any => ({ label })),
} as any);
});
it('allows creating a lazy logger for a string label.', async(): Promise<void> => {
expect(getLoggerFor('MyLabel')).toEqual({ label: 'MyLabel' });
});
it('allows creating a lazy logger for a class instance.', async(): Promise<void> => {
expect(getLoggerFor(new Dummy())).toEqual({ label: 'Dummy' });
});
it('reuses loggers for instances of the same class.', async(): Promise<void> => {
expect(getLoggerFor(new Dummy())).toBe(getLoggerFor(new Dummy()));
});
it('allows setting the global logger factory.', async(): Promise<void> => {
const factory = {} as any;
setGlobalLoggerFactory(factory);
expect(currentFactory).toBe(factory);
});
});