mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
import { createContainer, getInjectable } from "@ogre-tools/injectable";
|
|
import { registerFeature } from "@k8slens/feature-core";
|
|
import { loggerFeature } from "./feature";
|
|
import { winstonLoggerInjectable } from "./winston-logger.injectable";
|
|
|
|
import {
|
|
logDebugInjectionToken,
|
|
logErrorInjectionToken,
|
|
logInfoInjectionToken,
|
|
logSillyInjectionToken,
|
|
logWarningInjectionToken,
|
|
} from "./logger.injectable";
|
|
|
|
import { getFeature } from "@k8slens/feature-core/src/feature";
|
|
|
|
describe("logger", () => {
|
|
[
|
|
{ scenario: "debug", injectionToken: logDebugInjectionToken },
|
|
{ scenario: "info", injectionToken: logInfoInjectionToken },
|
|
{ scenario: "warn", injectionToken: logWarningInjectionToken },
|
|
{ scenario: "error", injectionToken: logErrorInjectionToken },
|
|
{ scenario: "silly", injectionToken: logSillyInjectionToken },
|
|
].forEach(({ scenario, injectionToken }) => {
|
|
it(`given not inside a Feature, when logging "${scenario}", does so without a prefix`, () => {
|
|
const di = createContainer("irrelevant");
|
|
|
|
registerFeature(di, loggerFeature);
|
|
|
|
const winstonLoggerStub = { [scenario]: jest.fn() } as any;
|
|
|
|
di.override(winstonLoggerInjectable, () => winstonLoggerStub);
|
|
|
|
const logScenario = di.inject(injectionToken);
|
|
|
|
logScenario("some-message", "some-data");
|
|
|
|
expect(winstonLoggerStub[scenario]).toHaveBeenCalledWith(
|
|
"some-message",
|
|
"some-data"
|
|
);
|
|
});
|
|
|
|
it(`given inside a Feature, when logging "${scenario}", does so with Feature's id as prefix`, () => {
|
|
const di = createContainer("irrelevant");
|
|
|
|
const logScenarioInFeature = getInjectable({
|
|
id: "some-functionality",
|
|
instantiate: (di) => di.inject(injectionToken),
|
|
});
|
|
|
|
|
|
const someFeature = getFeature({
|
|
id: "some-feature",
|
|
|
|
register: (di) => {
|
|
di.register(logScenarioInFeature);
|
|
},
|
|
|
|
dependencies: [loggerFeature],
|
|
});
|
|
|
|
registerFeature(di, someFeature);
|
|
|
|
const winstonLoggerStub = { [scenario]: jest.fn() } as any;
|
|
|
|
di.override(winstonLoggerInjectable, () => winstonLoggerStub);
|
|
|
|
const logScenario = di.inject(logScenarioInFeature);
|
|
|
|
logScenario("some-message", "some-data");
|
|
|
|
expect(winstonLoggerStub[scenario]).toHaveBeenCalledWith(
|
|
"[SOME-FEATURE]: some-message",
|
|
"some-data"
|
|
);
|
|
});
|
|
});
|
|
});
|