mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00

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.
41 lines
1.2 KiB
TypeScript
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);
|
|
});
|
|
});
|