1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Introduce a centralised way to emit telemetry from calls of injectable functions (#6164)

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
Co-authored-by: Juho Heikka <juho.heikka@gmail.com>
This commit is contained in:
Iku-turso 2022-09-02 16:33:22 +03:00 committed by GitHub
parent 60b538eec1
commit fc3512daf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 527 additions and 163 deletions

View File

@ -218,11 +218,11 @@
"@hapi/subtext": "^7.0.4", "@hapi/subtext": "^7.0.4",
"@kubernetes/client-node": "^0.17.0", "@kubernetes/client-node": "^0.17.0",
"@material-ui/styles": "^4.11.5", "@material-ui/styles": "^4.11.5",
"@ogre-tools/fp": "9.0.3", "@ogre-tools/fp": "10.1.0",
"@ogre-tools/injectable": "9.0.3", "@ogre-tools/injectable": "10.1.0",
"@ogre-tools/injectable-extension-for-auto-registration": "9.0.3", "@ogre-tools/injectable-extension-for-auto-registration": "10.1.0",
"@ogre-tools/injectable-extension-for-mobx": "9.0.3", "@ogre-tools/injectable-extension-for-mobx": "10.1.0",
"@ogre-tools/injectable-react": "9.0.3", "@ogre-tools/injectable-react": "10.1.0",
"@sentry/electron": "^3.0.7", "@sentry/electron": "^3.0.7",
"@sentry/integrations": "^6.19.3", "@sentry/integrations": "^6.19.3",
"@side/jest-runtime": "^1.0.1", "@side/jest-runtime": "^1.0.1",

View File

@ -0,0 +1,8 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../test-utils/get-global-override";
import emitEventInjectable from "./emit-event.injectable";
export default getGlobalOverride(emitEventInjectable, () => () => {});

View File

@ -9,6 +9,7 @@ const appEventBusInjectable = getInjectable({
id: "app-event-bus", id: "app-event-bus",
instantiate: () => appEventBus, instantiate: () => appEventBus,
causesSideEffects: true, causesSideEffects: true,
decorable: false,
}); });
export default appEventBusInjectable; export default appEventBusInjectable;

View File

@ -8,6 +8,7 @@ import appEventBusInjectable from "./app-event-bus.injectable";
const emitEventInjectable = getInjectable({ const emitEventInjectable = getInjectable({
id: "emit-event", id: "emit-event",
instantiate: (di) => di.inject(appEventBusInjectable).emit, instantiate: (di) => di.inject(appEventBusInjectable).emit,
decorable: false,
}); });
export default emitEventInjectable; export default emitEventInjectable;

View File

@ -12,7 +12,7 @@ describe("kubernetesClusterCategory", () => {
let kubernetesClusterCategory: KubernetesClusterCategory; let kubernetesClusterCategory: KubernetesClusterCategory;
beforeEach(() => { beforeEach(() => {
const di = getDiForUnitTesting(); const di = getDiForUnitTesting({ doGeneralOverrides: true });
kubernetesClusterCategory = di.inject(kubernetesClusterCategoryInjectable); kubernetesClusterCategory = di.inject(kubernetesClusterCategoryInjectable);
}); });

View File

@ -18,6 +18,7 @@ import { requestChannelListenerInjectionToken } from "./request-channel-listener
import type { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest"; import asyncFn from "@async-fn/jest";
import { getPromiseStatus } from "../../test-utils/get-promise-status"; import { getPromiseStatus } from "../../test-utils/get-promise-status";
import { runInAction } from "mobx";
type TestMessageChannel = MessageChannel<string>; type TestMessageChannel = MessageChannel<string>;
type TestRequestChannel = RequestChannel<string, string>; type TestRequestChannel = RequestChannel<string, string>;
@ -47,12 +48,16 @@ describe("channel", () => {
}); });
builder.beforeApplicationStart((mainDi) => { builder.beforeApplicationStart((mainDi) => {
mainDi.register(testMessageChannelInjectable); runInAction(() => {
mainDi.register(testMessageChannelInjectable);
});
}); });
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(testChannelListenerInTestWindowInjectable); runInAction(() => {
windowDi.register(testMessageChannelInjectable); windowDi.register(testChannelListenerInTestWindowInjectable);
windowDi.register(testMessageChannelInjectable);
});
}); });
mainDi = builder.mainDi; mainDi = builder.mainDi;
@ -126,12 +131,16 @@ describe("channel", () => {
}); });
applicationBuilder.beforeApplicationStart((mainDi) => { applicationBuilder.beforeApplicationStart((mainDi) => {
mainDi.register(testChannelListenerInMainInjectable); runInAction(() => {
mainDi.register(testMessageChannelInjectable); mainDi.register(testChannelListenerInMainInjectable);
mainDi.register(testMessageChannelInjectable);
});
}); });
applicationBuilder.beforeWindowStart((windowDi) => { applicationBuilder.beforeWindowStart((windowDi) => {
windowDi.register(testMessageChannelInjectable); runInAction(() => {
windowDi.register(testMessageChannelInjectable);
});
}); });
await applicationBuilder.render(); await applicationBuilder.render();
@ -172,12 +181,16 @@ describe("channel", () => {
}); });
applicationBuilder.beforeApplicationStart((mainDi) => { applicationBuilder.beforeApplicationStart((mainDi) => {
mainDi.register(testChannelListenerInMainInjectable); runInAction(() => {
mainDi.register(testRequestChannelInjectable); mainDi.register(testChannelListenerInMainInjectable);
mainDi.register(testRequestChannelInjectable);
});
}); });
applicationBuilder.beforeWindowStart((windowDi) => { applicationBuilder.beforeWindowStart((windowDi) => {
windowDi.register(testRequestChannelInjectable); runInAction(() => {
windowDi.register(testRequestChannelInjectable);
});
}); });
await applicationBuilder.render(); await applicationBuilder.render();

View File

@ -18,11 +18,15 @@ describe("sync-box", () => {
applicationBuilder = getApplicationBuilder(); applicationBuilder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(mainDi => { applicationBuilder.beforeApplicationStart(mainDi => {
mainDi.register(someInjectable); runInAction(() => {
mainDi.register(someInjectable);
});
}); });
applicationBuilder.beforeWindowStart((windowDi) => { applicationBuilder.beforeWindowStart((windowDi) => {
windowDi.register(someInjectable); runInAction(() => {
windowDi.register(someInjectable);
});
}); });
}); });

View File

@ -19,7 +19,7 @@ describe("with-error-logging", () => {
let decorated: (a: string, b: string) => number | undefined; let decorated: (a: string, b: string) => number | undefined;
beforeEach(() => { beforeEach(() => {
const di = getDiForUnitTesting(); const di = getDiForUnitTesting({ doGeneralOverrides: true });
loggerStub = { loggerStub = {
error: jest.fn(), error: jest.fn(),
@ -119,7 +119,7 @@ describe("with-error-logging", () => {
let toBeDecorated: AsyncFnMock<typeof decorated>; let toBeDecorated: AsyncFnMock<typeof decorated>;
beforeEach(() => { beforeEach(() => {
const di = getDiForUnitTesting(); const di = getDiForUnitTesting({ doGeneralOverrides: true });
loggerStub = { loggerStub = {
error: jest.fn(), error: jest.fn(),

View File

@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { runInAction } from "mobx";
import type { LensExtension } from "../../lens-extension"; import type { LensExtension } from "../../lens-extension";
import { extensionRegistratorInjectionToken } from "../extension-registrator-injection-token"; import { extensionRegistratorInjectionToken } from "../extension-registrator-injection-token";
@ -27,17 +28,23 @@ const extensionInjectable = getInjectable({
getInjectablesOfExtension(instance), getInjectablesOfExtension(instance),
); );
childDi.register(...injectables); runInAction(() => {
childDi.register(...injectables);
});
}, },
deregister: () => { deregister: () => {
parentDi.deregister(extensionInjectable); runInAction(() => {
parentDi.deregister(extensionInjectable);
});
}, },
}; };
}, },
}); });
parentDi.register(extensionInjectable); runInAction(() => {
parentDi.register(extensionInjectable);
});
return parentDi.inject(extensionInjectable); return parentDi.inject(extensionInjectable);
}, },

View File

@ -19,6 +19,7 @@ import quitAndInstallUpdateInjectable from "../../main/application-update/quit-a
import appVersionInjectable from "../../common/vars/app-version.injectable"; import appVersionInjectable from "../../common/vars/app-version.injectable";
import periodicalCheckForUpdatesInjectable from "../../main/application-update/periodical-check-for-updates/periodical-check-for-updates.injectable"; import periodicalCheckForUpdatesInjectable from "../../main/application-update/periodical-check-for-updates/periodical-check-for-updates.injectable";
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
describe("analytics for installing update", () => { describe("analytics for installing update", () => {
let builder: ApplicationBuilder; let builder: ApplicationBuilder;
@ -51,6 +52,8 @@ describe("analytics for installing update", () => {
mainDi.override(publishIsConfiguredInjectable, () => true); mainDi.override(publishIsConfiguredInjectable, () => true);
mainDi.unoverride(emitEventInjectable);
const eventBus = mainDi.inject(appEventBusInjectable); const eventBus = mainDi.inject(appEventBusInjectable);
eventBus.addListener(analyticsListenerMock); eventBus.addListener(analyticsListenerMock);
@ -65,7 +68,6 @@ describe("analytics for installing update", () => {
mainDi.permitSideEffects(periodicalCheckForUpdatesInjectable); mainDi.permitSideEffects(periodicalCheckForUpdatesInjectable);
await builder.render(); await builder.render();
}); });
it("sends event to analytics for being checked periodically", () => { it("sends event to analytics for being checked periodically", () => {

View File

@ -10,7 +10,7 @@ import type { KubernetesCluster } from "../../../../common/catalog-entities";
import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token"; import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import React from "react"; import React from "react";
import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token";
import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token";
@ -45,7 +45,9 @@ describe("disable kube object detail items when cluster is not relevant", () =>
windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable); windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable);
windowDi.register(testRouteInjectable, testRouteComponentInjectable); runInAction(() => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
});
}); });
isEnabledForClusterMock = asyncFn(); isEnabledForClusterMock = asyncFn();

View File

@ -39,7 +39,9 @@ describe("reactively hide kube object detail item", () => {
} as unknown as ApiManager), } as unknown as ApiManager),
); );
windowDi.register(testRouteInjectable, testRouteComponentInjectable); runInAction(() => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
});
}); });
someObservable = observable.box(false); someObservable = observable.box(false);

View File

@ -10,7 +10,7 @@ import type { KubernetesCluster } from "../../../../common/catalog-entities";
import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token"; import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import React from "react"; import React from "react";
import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token";
import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token";
@ -32,7 +32,10 @@ describe("disable kube object menu items when cluster is not relevant", () => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable); windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable);
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
runInAction(() => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
});
}); });
isEnabledForClusterMock = asyncFn(); isEnabledForClusterMock = asyncFn();

View File

@ -26,7 +26,9 @@ describe("reactively hide kube object menu item", () => {
builder.setEnvironmentToClusterFrame(); builder.setEnvironmentToClusterFrame();
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable); runInAction(() => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
});
}); });
someObservable = observable.box(false); someObservable = observable.box(false);

View File

@ -10,7 +10,7 @@ import type { KubernetesCluster } from "../../../../common/catalog-entities";
import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token"; import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import React from "react"; import React from "react";
import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token";
import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token";
@ -33,7 +33,10 @@ describe("disable kube object statuses when cluster is not relevant", () => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable); windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable);
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
runInAction(() => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
});
}); });
isEnabledForClusterMock = asyncFn(); isEnabledForClusterMock = asyncFn();

View File

@ -29,7 +29,10 @@ describe("reactively hide kube object status", () => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable); windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable);
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
runInAction(() => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
});
}); });
someObservable = observable.box(false); someObservable = observable.box(false);

View File

@ -9,7 +9,7 @@ import { useFakeTime } from "../../../common/test-utils/use-fake-time";
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { IAtom } from "mobx"; import type { IAtom } from "mobx";
import { createAtom, computed } from "mobx"; import { runInAction, createAtom, computed } from "mobx";
import { frontEndRouteInjectionToken } from "../../../common/front-end-routing/front-end-route-injection-token"; import { frontEndRouteInjectionToken } from "../../../common/front-end-routing/front-end-route-injection-token";
import { routeSpecificComponentInjectionToken } from "../../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../../renderer/routes/route-specific-component-injection-token";
import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
@ -94,14 +94,17 @@ describe("show status for a kube object", () => {
}); });
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register( runInAction(() => {
testRouteInjectable, windowDi.register(
testRouteComponentInjectable, testRouteInjectable,
infoStatusInjectable, testRouteComponentInjectable,
warningStatusInjectable, infoStatusInjectable,
criticalStatusInjectable, warningStatusInjectable,
someAtomInjectable, criticalStatusInjectable,
); someAtomInjectable,
);
});
}); });
builder.setEnvironmentToClusterFrame(); builder.setEnvironmentToClusterFrame();
@ -141,7 +144,9 @@ describe("show status for a kube object", () => {
describe("when status for irrelevant kube object kind emerges", () => { describe("when status for irrelevant kube object kind emerges", () => {
beforeEach(() => { beforeEach(() => {
windowDi.register(statusForIrrelevantKubeObjectKindInjectable); runInAction(() => {
windowDi.register(statusForIrrelevantKubeObjectKindInjectable);
});
rerenderParent(); rerenderParent();
}); });
@ -161,7 +166,9 @@ describe("show status for a kube object", () => {
describe("when status for irrelevant kube object api version emerges", () => { describe("when status for irrelevant kube object api version emerges", () => {
beforeEach(() => { beforeEach(() => {
windowDi.register(statusForIrrelevantKubeObjectApiVersionInjectable); runInAction(() => {
windowDi.register(statusForIrrelevantKubeObjectApiVersionInjectable);
});
rerenderParent(); rerenderParent();
}); });

View File

@ -7,7 +7,7 @@ import type { RenderResult } from "@testing-library/react";
import { fireEvent } from "@testing-library/react"; import { fireEvent } from "@testing-library/react";
import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable"; import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable";
import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable"; import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import { noop } from "lodash/fp"; import { noop } from "lodash/fp";
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
@ -22,7 +22,9 @@ describe("cluster - order of sidebar items", () => {
builder.setEnvironmentToClusterFrame(); builder.setEnvironmentToClusterFrame();
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(testSidebarItemsInjectable); runInAction(() => {
windowDi.register(testSidebarItemsInjectable);
});
}); });
}); });

View File

@ -11,7 +11,7 @@ import directoryForLensLocalStorageInjectable from "../../common/directory-for-l
import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token";
import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable"; import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable";
import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable"; import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import { noop } from "lodash/fp"; import { noop } from "lodash/fp";
import routeIsActiveInjectable from "../../renderer/routes/route-is-active.injectable"; import routeIsActiveInjectable from "../../renderer/routes/route-is-active.injectable";
import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token"; import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token";
@ -51,9 +51,11 @@ describe("cluster - sidebar and tab navigation for core", () => {
describe("given core registrations", () => { describe("given core registrations", () => {
beforeEach(() => { beforeEach(() => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(testRouteInjectable); runInAction(() => {
windowDi.register(testRouteComponentInjectable); windowDi.register(testRouteInjectable);
windowDi.register(testSidebarItemsInjectable); windowDi.register(testRouteComponentInjectable);
windowDi.register(testSidebarItemsInjectable);
});
}); });
}); });

View File

@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { RenderResult } from "@testing-library/react"; import type { RenderResult } from "@testing-library/react";
import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable"; import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable";
import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable"; import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token";
import React from "react"; import React from "react";
import isAllowedResourceInjectable from "../../common/utils/is-allowed-resource.injectable"; import isAllowedResourceInjectable from "../../common/utils/is-allowed-resource.injectable";
@ -25,9 +25,11 @@ describe("cluster - visibility of sidebar items", () => {
builder.setEnvironmentToClusterFrame(); builder.setEnvironmentToClusterFrame();
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(testRouteInjectable); runInAction(() => {
windowDi.register(testRouteComponentInjectable); windowDi.register(testRouteInjectable);
windowDi.register(testSidebarItemsInjectable); windowDi.register(testRouteComponentInjectable);
windowDi.register(testSidebarItemsInjectable);
});
}); });
}); });

View File

@ -8,7 +8,7 @@ import React from "react";
import getRandomIdInjectable from "../../../../../common/utils/get-random-id.injectable"; import getRandomIdInjectable from "../../../../../common/utils/get-random-id.injectable";
import { workloadOverviewDetailInjectionToken } from "../../../../../renderer/components/+workloads-overview/workload-overview-details/workload-overview-detail-injection-token"; import { workloadOverviewDetailInjectionToken } from "../../../../../renderer/components/+workloads-overview/workload-overview-details/workload-overview-detail-injection-token";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
describe("order of workload overview details", () => { describe("order of workload overview details", () => {
let rendered: RenderResult; let rendered: RenderResult;
@ -20,11 +20,13 @@ describe("order of workload overview details", () => {
windowDi.unoverride(getRandomIdInjectable); windowDi.unoverride(getRandomIdInjectable);
windowDi.permitSideEffects(getRandomIdInjectable); windowDi.permitSideEffects(getRandomIdInjectable);
windowDi.register( runInAction(() => {
someCoreItemWithLowOrderNumberInjectable, windowDi.register(
someCoreItemWithHighOrderNumberInjectable, someCoreItemWithLowOrderNumberInjectable,
someCoreItemWithDefaultOrderNumberInjectable, someCoreItemWithHighOrderNumberInjectable,
); someCoreItemWithDefaultOrderNumberInjectable,
);
});
}); });
builder.setEnvironmentToClusterFrame(); builder.setEnvironmentToClusterFrame();

View File

@ -5,7 +5,7 @@
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import React from "react"; import React from "react";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import type { RenderResult } from "@testing-library/react"; import type { RenderResult } from "@testing-library/react";
import { routeSpecificComponentInjectionToken } from "../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../renderer/routes/route-specific-component-injection-token";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
@ -32,8 +32,10 @@ describe("navigating between routes", () => {
beforeEach(async () => { beforeEach(async () => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(testRouteWithoutPathParametersInjectable); runInAction(() => {
windowDi.register(testRouteWithoutPathParametersComponentInjectable); windowDi.register(testRouteWithoutPathParametersInjectable);
windowDi.register(testRouteWithoutPathParametersComponentInjectable);
});
}); });
rendered = await builder.render(); rendered = await builder.render();
@ -106,8 +108,10 @@ describe("navigating between routes", () => {
beforeEach(async () => { beforeEach(async () => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(routeWithOptionalPathParametersInjectable); runInAction(() => {
windowDi.register(routeWithOptionalPathParametersComponentInjectable); windowDi.register(routeWithOptionalPathParametersInjectable);
windowDi.register(routeWithOptionalPathParametersComponentInjectable);
});
}); });
rendered = await builder.render(); rendered = await builder.render();

View File

@ -9,7 +9,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import currentPathInjectable from "../../renderer/routes/current-path.injectable"; import currentPathInjectable from "../../renderer/routes/current-path.injectable";
import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token"; import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import { preferenceNavigationItemInjectionToken } from "../../renderer/components/+preferences/preferences-navigation/preference-navigation-items.injectable"; import { preferenceNavigationItemInjectionToken } from "../../renderer/components/+preferences/preferences-navigation/preference-navigation-items.injectable";
import routeIsActiveInjectable from "../../renderer/routes/route-is-active.injectable"; import routeIsActiveInjectable from "../../renderer/routes/route-is-active.injectable";
import { Preferences } from "../../renderer/components/+preferences"; import { Preferences } from "../../renderer/components/+preferences";
@ -30,11 +30,13 @@ describe("preferences - closing-preferences", () => {
builder = getApplicationBuilder(); builder = getApplicationBuilder();
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.register(testPreferencesRouteInjectable); runInAction(() => {
windowDi.register(testPreferencesRouteComponentInjectable); windowDi.register(testPreferencesRouteInjectable);
windowDi.register(testFrontPageRouteInjectable); windowDi.register(testPreferencesRouteComponentInjectable);
windowDi.register(testFrontPageRouteComponentInjectable); windowDi.register(testFrontPageRouteInjectable);
windowDi.register(testNavigationItemInjectable); windowDi.register(testFrontPageRouteComponentInjectable);
windowDi.register(testNavigationItemInjectable);
});
windowDi.override(navigateToFrontPageInjectable, (di) => { windowDi.override(navigateToFrontPageInjectable, (di) => {
const navigateToRoute = di.inject(navigateToRouteInjectionToken); const navigateToRoute = di.inject(navigateToRouteInjectionToken);

View File

@ -13,6 +13,7 @@ import focusApplicationInjectable from "../../main/electron-app/features/focus-a
import type { CreateElectronWindow } from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable"; import type { CreateElectronWindow } from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable";
import createElectronWindowInjectable from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable"; import createElectronWindowInjectable from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable";
import splashWindowInjectable from "../../main/start-main-application/lens-window/splash-window/splash-window.injectable"; import splashWindowInjectable from "../../main/start-main-application/lens-window/splash-window/splash-window.injectable";
import { runInAction } from "mobx";
describe("opening application window using tray", () => { describe("opening application window using tray", () => {
describe("given application has started", () => { describe("given application has started", () => {
@ -61,10 +62,12 @@ describe("opening application window using tray", () => {
return browserWindow; return browserWindow;
}); });
(mainDi as any).decorateFunction( runInAction(() => {
createElectronWindowInjectable, (mainDi as any).decorateFunction(
createElectronWindowMock, createElectronWindowInjectable,
); createElectronWindowMock,
);
});
expectWindowsToBeOpen = expectWindowsToBeOpenFor(builder); expectWindowsToBeOpen = expectWindowsToBeOpenFor(builder);
}); });

View File

@ -0,0 +1,146 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { computed, runInAction } from "mobx";
import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import { getDiForUnitTesting } from "../../renderer/getDiForUnitTesting";
import telemetryWhiteListForFunctionsInjectable from "./renderer/telemetry-white-list-for-functions.injectable";
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
describe("emit-telemetry-from-specific-function-calls", () => {
let di: DiContainer;
beforeEach(() => {
di = getDiForUnitTesting({ doGeneralOverrides: true });
});
describe("given a telemetry white-list for injectables which instantiate a function", () => {
let emitEventMock: jest.Mock;
beforeEach(() => {
di.override(telemetryWhiteListForFunctionsInjectable, () => [
"some-white-listed-function",
]);
emitEventMock = jest.fn();
di.override(emitEventInjectable, () => emitEventMock);
});
describe("given instances of white-listed, non-white-listed and tagged functions", () => {
let whiteListedFunctionMock: jest.Mock;
let nonWhiteListedFunctionMock: jest.Mock;
let taggedFunctionMock: jest.Mock;
let injectedWhiteListedFunction: jest.Mock;
let injectedNonWhiteListedFunction: jest.Mock;
let injectedTaggedFunction: jest.Mock;
beforeEach(() => {
whiteListedFunctionMock = jest.fn();
nonWhiteListedFunctionMock = jest.fn();
taggedFunctionMock = jest.fn();
const whiteListedInjectable = getInjectable({
id: "some-white-listed-function",
instantiate: () => whiteListedFunctionMock,
});
const nonWhiteListedInjectable = getInjectable({
id: "some-non-white-listed-function",
instantiate: () => nonWhiteListedFunctionMock,
});
const taggedInjectable = getInjectable({
id: "some-tagged-function",
instantiate: () => taggedFunctionMock,
tags: ["emit-telemetry"],
});
runInAction(() => {
di.register(whiteListedInjectable);
di.register(nonWhiteListedInjectable);
di.register(taggedInjectable);
});
injectedWhiteListedFunction = di.inject(whiteListedInjectable);
injectedNonWhiteListedFunction = di.inject(nonWhiteListedInjectable);
injectedTaggedFunction = di.inject(taggedInjectable);
});
it("telemetry is not emitted yet", () => {
expect(emitEventMock).not.toHaveBeenCalled();
});
describe("when the white-listed function is called", () => {
beforeEach(() => {
injectedWhiteListedFunction("some-arg", "some-other-arg");
});
it("telemetry is emitted in event bus", () => {
expect(emitEventMock).toHaveBeenCalledWith({
destination: "auto-capture",
action: "telemetry-from-business-action",
name: "some-white-listed-function",
params: { args: ["some-arg", "some-other-arg"] },
});
});
});
describe("when the white-listed function is called with MobX reactive content", () => {
beforeEach(() => {
const someComputedProperty = computed(() => "some-computed-value");
const someObservable = {
someStaticProperty: "some-static-value",
someComputedProperty,
};
injectedWhiteListedFunction(someObservable);
});
it("telemetry is emitted in event bus without MobX internals or computeds", () => {
expect(emitEventMock).toHaveBeenCalledWith({
destination: "auto-capture",
action: "telemetry-from-business-action",
name: "some-white-listed-function",
params: {
args: [
{
someStaticProperty: "some-static-value",
someComputedProperty: "some-computed-value",
},
],
},
});
});
});
describe("when the non-white-listed function is called", () => {
beforeEach(() => {
injectedNonWhiteListedFunction();
});
it("telemetry is not emitted", () => {
expect(emitEventMock).not.toHaveBeenCalled();
});
});
describe("when the tagged, but not white-listed function is called", () => {
beforeEach(() => {
injectedTaggedFunction("some-arg", "some-other-arg");
});
it("telemetry is emitted in event bus", () => {
expect(emitEventMock).toHaveBeenCalledWith({
destination: "auto-capture",
action: "telemetry-from-business-action",
name: "some-tagged-function",
params: { args: ["some-arg", "some-other-arg"] },
});
});
});
});
});
});

View File

@ -0,0 +1,28 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import emitEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
import { toJS, observable } from "mobx";
const emitTelemetryInjectable = getInjectable({
id: "emit-telemetry",
instantiate: (di) => {
const emitEvent = di.inject(emitEventInjectable);
return ({ action, args }: { action: string; args: any[] }) => {
emitEvent({
destination: "auto-capture",
action: "telemetry-from-business-action",
name: action,
params: { args: toJS(observable(args)) },
});
};
},
decorable: false,
});
export default emitTelemetryInjectable;

View File

@ -0,0 +1,69 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type {
DiContainerForInjection,
Injectable,
} from "@ogre-tools/injectable";
import {
lifecycleEnum,
getInjectable,
instantiationDecoratorToken,
} from "@ogre-tools/injectable";
import assert from "assert";
import { isFunction } from "lodash/fp";
import emitTelemetryInjectable from "./emit-telemetry.injectable";
import telemetryWhiteListForFunctionsInjectable from "./telemetry-white-list-for-functions.injectable";
const telemetryDecoratorInjectable = getInjectable({
id: "telemetry-decorator",
instantiate: (diForDecorator) => {
const emitTelemetry = diForDecorator.inject(emitTelemetryInjectable);
const whiteList = diForDecorator.inject(
telemetryWhiteListForFunctionsInjectable,
);
const shouldEmitTelemetry = shouldEmitTelemetryFor(whiteList);
return {
decorate:
(instantiateToBeDecorated: any) =>
(di: DiContainerForInjection, instantiationParameter: any) => {
const instance = instantiateToBeDecorated(di, instantiationParameter);
if (isFunction(instance)) {
return (...args: any[]) => {
const currentContext = di.context.at(-1);
assert(currentContext);
if (shouldEmitTelemetry(currentContext.injectable)) {
emitTelemetry({ action: currentContext.injectable.id, args });
}
return instance(...args);
};
}
return instance;
},
};
},
decorable: false,
// Todo: this is required because of imperfect typing in injectable.
lifecycle: lifecycleEnum.singleton,
injectionToken: instantiationDecoratorToken,
});
const shouldEmitTelemetryFor =
(whiteList: string[]) => (injectable: Injectable<any, any, any>) =>
injectable.tags?.includes("emit-telemetry") ||
whiteList.includes(injectable.id);
export default telemetryDecoratorInjectable;

View File

@ -0,0 +1,13 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
const telemetryWhiteListForFunctionsInjectable = getInjectable({
id: "telemetry-white-list-for-functions",
instantiate: () => ["some-placeholder-injectable-id"],
decorable: false,
});
export default telemetryWhiteListForFunctionsInjectable;

View File

@ -5,24 +5,27 @@
import { createContainer } from "@ogre-tools/injectable"; import { createContainer } from "@ogre-tools/injectable";
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration"; import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { runInAction } from "mobx";
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
export const getDi = () => { export const getDi = () => {
const di = createContainer("main"); const di = createContainer("main");
registerMobX(di);
autoRegister({
di,
requireContexts: [
require.context("./", true, /\.injectable\.(ts|tsx)$/),
require.context("../extensions", true, /\.injectable\.(ts|tsx)$/),
require.context("../common", true, /\.injectable\.(ts|tsx)$/),
require.context("../features", true, /.*\/(main|common)\/.*\.injectable\.(ts|tsx)$/),
],
});
setLegacyGlobalDiForExtensionApi(di, Environments.main); setLegacyGlobalDiForExtensionApi(di, Environments.main);
runInAction(() => {
registerMobX(di);
autoRegister({
di,
requireContexts: [
require.context("./", true, /\.injectable\.(ts|tsx)$/),
require.context("../extensions", true, /\.injectable\.(ts|tsx)$/),
require.context("../common", true, /\.injectable\.(ts|tsx)$/),
require.context("../features", true, /.*\/(main|common)\/.*\.injectable\.(ts|tsx)$/),
],
});
});
return di; return di;
}; };

View File

@ -55,7 +55,7 @@ import setupRunnablesBeforeClosingOfApplicationInjectable from "./electron-app/r
import showMessagePopupInjectable from "./electron-app/features/show-message-popup.injectable"; import showMessagePopupInjectable from "./electron-app/features/show-message-popup.injectable";
import clusterFramesInjectable from "../common/cluster-frames.injectable"; import clusterFramesInjectable from "../common/cluster-frames.injectable";
import type { ClusterFrameInfo } from "../common/cluster-frames"; import type { ClusterFrameInfo } from "../common/cluster-frames";
import { observable } from "mobx"; import { observable, runInAction } from "mobx";
import waitForElectronToBeReadyInjectable from "./electron-app/features/wait-for-electron-to-be-ready.injectable"; import waitForElectronToBeReadyInjectable from "./electron-app/features/wait-for-electron-to-be-ready.injectable";
import setupListenerForCurrentClusterFrameInjectable from "./start-main-application/lens-window/current-cluster-frame/setup-listener-for-current-cluster-frame.injectable"; import setupListenerForCurrentClusterFrameInjectable from "./start-main-application/lens-window/current-cluster-frame/setup-listener-for-current-cluster-frame.injectable";
import setupRunnablesAfterWindowIsOpenedInjectable from "./electron-app/runnables/setup-runnables-after-window-is-opened.injectable"; import setupRunnablesAfterWindowIsOpenedInjectable from "./electron-app/runnables/setup-runnables-after-window-is-opened.injectable";
@ -103,19 +103,21 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
const di = createContainer("main"); const di = createContainer("main");
registerMobX(di);
setLegacyGlobalDiForExtensionApi(di, Environments.main); setLegacyGlobalDiForExtensionApi(di, Environments.main);
di.preventSideEffects();
const injectables: Injectable<any, any, any>[] = (global as any).mainInjectablePaths.map( const injectables: Injectable<any, any, any>[] = (global as any).mainInjectablePaths.map(
(filePath: string) => require(filePath).default, (filePath: string) => require(filePath).default,
); );
chunk(100)(injectables).forEach(chunkInjectables => { runInAction(() => {
di.register(...chunkInjectables); registerMobX(di);
});
di.preventSideEffects(); chunk(100)(injectables).forEach(chunkInjectables => {
di.register(...chunkInjectables);
});
});
if (doGeneralOverrides) { if (doGeneralOverrides) {
const globalOverrides: GlobalOverride[] = (global as any).mainGlobalOverridePaths.map( const globalOverrides: GlobalOverride[] = (global as any).mainGlobalOverridePaths.map(

View File

@ -20,6 +20,7 @@ import type { SetRequired } from "type-fest";
import normalizedPlatformInjectable from "../../common/vars/normalized-platform.injectable"; import normalizedPlatformInjectable from "../../common/vars/normalized-platform.injectable";
import kubectlBinaryNameInjectable from "../kubectl/binary-name.injectable"; import kubectlBinaryNameInjectable from "../kubectl/binary-name.injectable";
import kubectlDownloadingNormalizedArchInjectable from "../kubectl/normalized-arch.injectable"; import kubectlDownloadingNormalizedArchInjectable from "../kubectl/normalized-arch.injectable";
import { runInAction } from "mobx";
describe("router", () => { describe("router", () => {
let router: Router; let router: Router;
@ -53,7 +54,9 @@ describe("router", () => {
injectionToken: routeInjectionToken, injectionToken: routeInjectionToken,
}); });
di.register(injectable); runInAction(() => {
di.register(injectable);
});
router = di.inject(routerInjectable); router = di.inject(routerInjectable);
}); });

View File

@ -10,6 +10,7 @@ import appNameInjectable from "../../../app-paths/app-name/app-name.injectable";
import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable"; import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
import waitUntilBundledExtensionsAreLoadedInjectable from "./wait-until-bundled-extensions-are-loaded.injectable"; import waitUntilBundledExtensionsAreLoadedInjectable from "./wait-until-bundled-extensions-are-loaded.injectable";
import { applicationWindowInjectionToken } from "./application-window-injection-token"; import { applicationWindowInjectionToken } from "./application-window-injection-token";
import { runInAction } from "mobx";
const createApplicationWindowInjectable = getInjectable({ const createApplicationWindowInjectable = getInjectable({
id: "create-application-window", id: "create-application-window",
@ -49,7 +50,9 @@ const createApplicationWindowInjectable = getInjectable({
}, },
onClose: () => { onClose: () => {
parentDi.deregister(windowInjectable); runInAction(() => {
parentDi.deregister(windowInjectable);
});
}, },
beforeOpen: waitUntilBundledExtensionsAreLoaded, beforeOpen: waitUntilBundledExtensionsAreLoaded,
@ -59,7 +62,9 @@ const createApplicationWindowInjectable = getInjectable({
injectionToken: applicationWindowInjectionToken, injectionToken: applicationWindowInjectionToken,
}); });
parentDi.register(windowInjectable); runInAction(() => {
parentDi.register(windowInjectable);
});
return parentDi.inject(windowInjectable); return parentDi.inject(windowInjectable);
}, },

View File

@ -20,7 +20,7 @@ describe("technical: resolve-system-proxy-from-electron", () => {
let actualPromise: Promise<string>; let actualPromise: Promise<string>;
beforeEach(() => { beforeEach(() => {
di = getDiForUnitTesting(); di = getDiForUnitTesting({ doGeneralOverrides: true });
logErrorMock = jest.fn(); logErrorMock = jest.fn();
di.override(logErrorInjectable, () => logErrorMock); di.override(logErrorInjectable, () => logErrorMock);

View File

@ -80,7 +80,7 @@ describe("CatalogEntityRegistry", () => {
let catalogCategoryRegistry: CatalogCategoryRegistry; let catalogCategoryRegistry: CatalogCategoryRegistry;
beforeEach(() => { beforeEach(() => {
const di = getDiForUnitTesting(); const di = getDiForUnitTesting({ doGeneralOverrides: true });
entityRegistry = di.inject(catalogEntityRegistryInjectable); entityRegistry = di.inject(catalogEntityRegistryInjectable);
catalogCategoryRegistry = di.inject(catalogCategoryRegistryInjectable); catalogCategoryRegistry = di.inject(catalogCategoryRegistryInjectable);

View File

@ -43,7 +43,7 @@ describe("Custom Category Columns", () => {
let di: DiContainer; let di: DiContainer;
beforeEach(() => { beforeEach(() => {
di = getDiForUnitTesting(); di = getDiForUnitTesting({ doGeneralOverrides: true });
di.override(hotbarStoreInjectable, () => ({})); di.override(hotbarStoreInjectable, () => ({}));
}); });

View File

@ -16,7 +16,7 @@ describe("Custom Category Views", () => {
let di: DiContainer; let di: DiContainer;
beforeEach(() => { beforeEach(() => {
di = getDiForUnitTesting(); di = getDiForUnitTesting({ doGeneralOverrides: true });
}); });
it("should order items correctly over all extensions", () => { it("should order items correctly over all extensions", () => {

View File

@ -14,7 +14,7 @@ import { ConfirmDialog } from "../confirm-dialog";
import type { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest"; import asyncFn from "@async-fn/jest";
import { getDiForUnitTesting } from "../../getDiForUnitTesting"; import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import { computed } from "mobx"; import { computed, runInAction } from "mobx";
import clusterInjectable from "./dependencies/cluster.injectable"; import clusterInjectable from "./dependencies/cluster.injectable";
import type { DiRender } from "../test-utils/renderFor"; import type { DiRender } from "../test-utils/renderFor";
import { renderFor } from "../test-utils/renderFor"; import { renderFor } from "../test-utils/renderFor";
@ -34,11 +34,13 @@ describe("kube-object-menu", () => {
beforeEach(() => { beforeEach(() => {
di = getDiForUnitTesting({ doGeneralOverrides: true }); di = getDiForUnitTesting({ doGeneralOverrides: true });
di.register( runInAction(() => {
someMenuItemInjectable, di.register(
someOtherMenuItemInjectable, someMenuItemInjectable,
someAnotherMenuItemInjectable, someOtherMenuItemInjectable,
); someAnotherMenuItemInjectable,
);
});
render = renderFor(di); render = renderFor(di);

View File

@ -143,7 +143,9 @@ export const getApplicationBuilder = () => {
doGeneralOverrides: true, doGeneralOverrides: true,
}); });
mainDi.register(mainExtensionsStateInjectable); runInAction(() => {
mainDi.register(mainExtensionsStateInjectable);
});
const overrideChannelsForWindow = overrideChannels(mainDi); const overrideChannelsForWindow = overrideChannels(mainDi);
@ -184,7 +186,9 @@ export const getApplicationBuilder = () => {
overrideChannelsForWindow(windowDi, windowId); overrideChannelsForWindow(windowDi, windowId);
windowDi.register(rendererExtensionsStateInjectable); runInAction(() => {
windowDi.register(rendererExtensionsStateInjectable);
});
windowDi.override( windowDi.override(
currentlyInClusterFrameInjectable, currentlyInClusterFrameInjectable,
@ -552,9 +556,11 @@ export const getApplicationBuilder = () => {
getExtensionFakeForMain(mainDi, extension.id, extension.name, extension.mainOptions || {}), getExtensionFakeForMain(mainDi, extension.id, extension.name, extension.mainOptions || {}),
); );
mainExtensionInstances.forEach( runInAction(() => {
enableExtensionFor(mainDi, mainExtensionsStateInjectable), mainExtensionInstances.forEach(
); enableExtensionFor(mainDi, mainExtensionsStateInjectable),
);
});
}); });
}, },

View File

@ -6,24 +6,27 @@
import { createContainer } from "@ogre-tools/injectable"; import { createContainer } from "@ogre-tools/injectable";
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration"; import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { runInAction } from "mobx";
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
export const getDi = () => { export const getDi = () => {
const di = createContainer("renderer"); const di = createContainer("renderer");
registerMobX(di);
autoRegister({
di,
requireContexts: [
require.context("./", true, /\.injectable\.(ts|tsx)$/),
require.context("../common", true, /\.injectable\.(ts|tsx)$/),
require.context("../extensions", true, /\.injectable\.(ts|tsx)$/),
require.context("../features", true, /.*\/(renderer|common)\/.*\.injectable\.(ts|tsx)$/),
],
});
setLegacyGlobalDiForExtensionApi(di, Environments.renderer); setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
runInAction(() => {
registerMobX(di);
autoRegister({
di,
requireContexts: [
require.context("./", true, /\.injectable\.(ts|tsx)$/),
require.context("../common", true, /\.injectable\.(ts|tsx)$/),
require.context("../extensions", true, /\.injectable\.(ts|tsx)$/),
require.context("../features", true, /.*\/(renderer|common)\/.*\.injectable\.(ts|tsx)$/),
],
});
});
return di; return di;
}; };

View File

@ -33,7 +33,7 @@ import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.inject
import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable"; import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable";
import apiManagerInjectable from "../common/k8s-api/api-manager/manager.injectable"; import apiManagerInjectable from "../common/k8s-api/api-manager/manager.injectable";
import setupOnApiErrorListenersInjectable from "./api/setup-on-api-errors.injectable"; import setupOnApiErrorListenersInjectable from "./api/setup-on-api-errors.injectable";
import { observable, computed } from "mobx"; import { observable, computed, runInAction } from "mobx";
import defaultShellInjectable from "./components/+preferences/default-shell.injectable"; import defaultShellInjectable from "./components/+preferences/default-shell.injectable";
import appVersionInjectable from "../common/vars/app-version.injectable"; import appVersionInjectable from "../common/vars/app-version.injectable";
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable"; import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
@ -68,26 +68,30 @@ import getEntitySettingCommandsInjectable from "./components/command-palette/reg
import storageSaveDelayInjectable from "./utils/create-storage/storage-save-delay.injectable"; import storageSaveDelayInjectable from "./utils/create-storage/storage-save-delay.injectable";
import type { GlobalOverride } from "../common/test-utils/get-global-override"; import type { GlobalOverride } from "../common/test-utils/get-global-override";
export const getDiForUnitTesting = (opts: { doGeneralOverrides?: boolean } = {}) => { export const getDiForUnitTesting = (
const { opts: { doGeneralOverrides?: boolean } = {},
doGeneralOverrides = false, ) => {
} = opts; const { doGeneralOverrides = false } = opts;
const di = createContainer("renderer"); const di = createContainer("renderer");
registerMobX(di); di.preventSideEffects();
setLegacyGlobalDiForExtensionApi(di, Environments.renderer); setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
const injectables: Injectable<any, any, any>[] = (global as any).rendererInjectablePaths.map( const injectables: Injectable<any, any, any>[] = (
global as any
).rendererInjectablePaths.map(
(filePath: string) => require(filePath).default, (filePath: string) => require(filePath).default,
); );
chunk(100)(injectables).forEach(chunkInjectables => { runInAction(() => {
di.register(...chunkInjectables); registerMobX(di);
});
di.preventSideEffects(); chunk(100)(injectables).forEach((chunkInjectables) => {
di.register(...chunkInjectables);
});
});
if (doGeneralOverrides) { if (doGeneralOverrides) {
const globalOverrides: GlobalOverride[] = (global as any).rendererGlobalOverridePaths.map( const globalOverrides: GlobalOverride[] = (global as any).rendererGlobalOverridePaths.map(

View File

@ -33,6 +33,8 @@ const navigateToRouteInjectable = getInjectable({
}; };
}, },
tags: ["emit-telemetry"],
injectionToken: navigateToRouteInjectionToken, injectionToken: navigateToRouteInjectionToken,
}); });

View File

@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import { runInAction } from "mobx";
import type { CreateStorage } from "./create-storage"; import type { CreateStorage } from "./create-storage";
import createStorageInjectable from "./create-storage.injectable"; import createStorageInjectable from "./create-storage.injectable";
@ -19,8 +20,10 @@ export const controlWhenStoragesAreReady = (di: DiContainer) => {
return storage; return storage;
}; };
// TODO: Remove when typing is added to the library runInAction(() => {
(di as any).decorateFunction(createStorageInjectable, decorated); // TODO: Remove when typing is added to the library
(di as any).decorateFunction(createStorageInjectable, decorated);
});
return async () => { return async () => {
await Promise.all(storagesAreReady); await Promise.all(storagesAreReady);

View File

@ -1240,46 +1240,46 @@
mkdirp "^1.0.4" mkdirp "^1.0.4"
rimraf "^3.0.2" rimraf "^3.0.2"
"@ogre-tools/fp@9.0.3", "@ogre-tools/fp@^9.0.3": "@ogre-tools/fp@10.1.0", "@ogre-tools/fp@^10.1.0":
version "9.0.3" version "10.1.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/fp/-/fp-9.0.3.tgz#f8c9a3316b688c4782309e050c86aa04bebfc293" resolved "https://registry.yarnpkg.com/@ogre-tools/fp/-/fp-10.1.0.tgz#e83c4dad97416c62d89913c0c0a34e734ae06b8b"
integrity sha512-j5TQAxiz6ncEfYFBcqnWXeLZY89Qd+dZ9UlfonBdw/C9okxjNeFL+2bmt+b/Vxscz1cOLGZ1F6nmlhQdTtHzPw== integrity sha512-ZqGQXytucSWbSoNjrdyHAiIWO0LotxBU+aI5hCcqedWg9TzNzf78YKD6ngHXxVEwT/JYsslxXMxzE4LNdo8Cbg==
dependencies: dependencies:
lodash "^4.17.21" lodash "^4.17.21"
"@ogre-tools/injectable-extension-for-auto-registration@9.0.3": "@ogre-tools/injectable-extension-for-auto-registration@10.1.0":
version "9.0.3" version "10.1.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-auto-registration/-/injectable-extension-for-auto-registration-9.0.3.tgz#a26d2a39e24ec3a0800fe21141c0f4f0e7d5504d" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-auto-registration/-/injectable-extension-for-auto-registration-10.1.0.tgz#a46d23cf5cf880e416a46238ecb54e7f933f9d89"
integrity sha512-0zjt4w1ACBX9a3FyhTD+/AAqk/xov2bw+Cnbte7NMOVWAbHDfQpmbdiKJlMnFcMUd8vdwOEMm1Z4ogT1VkUeqg== integrity sha512-G9UKcaYr4DHViXHIKigzy6jI2ZhQC+K6idc1M4W/l4IazaV26Gwj1MSI5nrJ6Z4aRAzILFKM4dzkvZNFjkyGrw==
dependencies: dependencies:
"@ogre-tools/fp" "^9.0.3" "@ogre-tools/fp" "^10.1.0"
"@ogre-tools/injectable" "^9.0.3" "@ogre-tools/injectable" "^10.1.0"
lodash "^4.17.21" lodash "^4.17.21"
"@ogre-tools/injectable-extension-for-mobx@9.0.3": "@ogre-tools/injectable-extension-for-mobx@10.1.0":
version "9.0.3" version "10.1.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-mobx/-/injectable-extension-for-mobx-9.0.3.tgz#24a14b940f51cae8b07645a2376d804b826c659e" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-mobx/-/injectable-extension-for-mobx-10.1.0.tgz#b1efaafb048f2ceb5588daad708dbeffbd2ec7d1"
integrity sha512-DgCbAIqMPKgeNETY/8nxz6llAk8fAihGcbs/fkKINe4N9zFgOBKsuk/w67Sx0rTE7l35L6HQenbo7nJhIqbCWA== integrity sha512-G5A6FSgBMTlD6Qdd6xzeuVzcyHGS+tTUW7DCBbYLJqZ3Y8/PprSomhunrNrrcuZdM0K16BpQT8o6OHw4Z/Kqiw==
dependencies: dependencies:
"@ogre-tools/fp" "^9.0.3" "@ogre-tools/fp" "^10.1.0"
"@ogre-tools/injectable" "^9.0.3" "@ogre-tools/injectable" "^10.1.0"
lodash "^4.17.21" lodash "^4.17.21"
"@ogre-tools/injectable-react@9.0.3": "@ogre-tools/injectable-react@10.1.0":
version "9.0.3" version "10.1.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-9.0.3.tgz#bc125ef906b171c8894f711f8b61f38d49e81dd0" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-10.1.0.tgz#5c9b4b5eb9e5843cc966629131104055180ba18c"
integrity sha512-6O9vr19Mcy0uUekZhRyjsM5nw8pgFXhbNvZ8JOnBQg6Lp1CqdasIFhJ0Hdxb8w8P9Zs+pd8pfevRVotq0ouV2Q== integrity sha512-4ReLJm8QcruCEm4KFhbsXLki3YiKRwlg3Mg7C2d8KyUfg+MUA5VdvgQSn3HthnyejiXlYCinqJLw83IryX/GNA==
dependencies: dependencies:
"@ogre-tools/fp" "^9.0.3" "@ogre-tools/fp" "^10.1.0"
"@ogre-tools/injectable" "^9.0.3" "@ogre-tools/injectable" "^10.1.0"
lodash "^4.17.21" lodash "^4.17.21"
"@ogre-tools/injectable@9.0.3", "@ogre-tools/injectable@^9.0.3": "@ogre-tools/injectable@10.1.0", "@ogre-tools/injectable@^10.1.0":
version "9.0.3" version "10.1.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-9.0.3.tgz#6d9e01a5be7e7c96e7bcbc727f928faad5e11884" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-10.1.0.tgz#5051cc6a673576028e00439fc3e3f053ecdda030"
integrity sha512-KCmqcMEl/1Jjwg6XzNve+JVaW/OtiJUOKBucTJx2ZKBlAQaKz1/VUP7IB4UoQ4RWVa0+mUKLTxBTQFBQfp05RA== integrity sha512-7h7P5nfAFqnSny341FFT6cbJCmXVlGqA4zwTOpwKsGyC1h90NWtQZ+PUxY5MKl7rFWW/wpXgAKQqtf27Vy41Qw==
dependencies: dependencies:
"@ogre-tools/fp" "^9.0.3" "@ogre-tools/fp" "^10.1.0"
lodash "^4.17.21" lodash "^4.17.21"
"@pmmmwh/react-refresh-webpack-plugin@^0.5.7": "@pmmmwh/react-refresh-webpack-plugin@^0.5.7":