mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove unnecessary overrides from getDiForUnitTesting
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4cca41b32b
commit
46b141e1e2
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function";
|
||||
import broadcastMessageInjectable from "./broadcast-message.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(broadcastMessageInjectable);
|
||||
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../../../../../../../common/test-utils/get-global-override-for-function";
|
||||
import requestPublicHelmRepositoriesInjectable from "./request-public-helm-repositories.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(requestPublicHelmRepositoriesInjectable);
|
||||
@ -7,9 +7,6 @@ import { kebabCase, noop, chunk } from "lodash/fp";
|
||||
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
|
||||
import { createContainer, isInjectable, getInjectable } from "@ogre-tools/injectable";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import writeJsonFileInjectable from "../common/fs/write-json-file.injectable";
|
||||
import readJsonFileInjectable from "../common/fs/read-json-file.injectable";
|
||||
import readFileInjectable from "../common/fs/read-file.injectable";
|
||||
import loggerInjectable from "../common/logger.injectable";
|
||||
import spawnInjectable from "./child-process/spawn.injectable";
|
||||
import commandLineArgumentsInjectable from "./utils/command-line-arguments.injectable";
|
||||
@ -21,7 +18,6 @@ import setupLensProxyInjectable from "./start-main-application/runnables/setup-l
|
||||
import setupShellInjectable from "../features/shell-sync/main/setup-shell.injectable";
|
||||
import setupSyncingOfWeblinksInjectable from "./start-main-application/runnables/setup-syncing-of-weblinks.injectable";
|
||||
import stopServicesAndExitAppInjectable from "./stop-services-and-exit-app.injectable";
|
||||
import isDevelopmentInjectable from "../common/vars/is-development.injectable";
|
||||
import setupSystemCaInjectable from "./start-main-application/runnables/setup-system-ca.injectable";
|
||||
import setupDeepLinkingInjectable from "./electron-app/runnables/setup-deep-linking.injectable";
|
||||
import exitAppInjectable from "./electron-app/features/exit-app.injectable";
|
||||
@ -52,11 +48,7 @@ import setUpdateOnQuitInjectable from "./electron-app/features/set-update-on-qui
|
||||
import startCatalogSyncInjectable from "./catalog-sync-to-renderer/start-catalog-sync.injectable";
|
||||
import startKubeConfigSyncInjectable from "./start-main-application/runnables/kube-config-sync/start-kube-config-sync.injectable";
|
||||
import getRandomIdInjectable from "../common/utils/get-random-id.injectable";
|
||||
import execFileInjectable from "../common/fs/exec-file.injectable";
|
||||
import normalizedPlatformArchitectureInjectable from "../common/vars/normalized-platform-architecture.injectable";
|
||||
import getHelmChartVersionsInjectable from "./helm/helm-service/get-helm-chart-versions.injectable";
|
||||
import getHelmChartValuesInjectable from "./helm/helm-service/get-helm-chart-values.injectable";
|
||||
import listHelmChartsInjectable from "./helm/helm-service/list-helm-charts.injectable";
|
||||
import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
|
||||
@ -67,6 +59,7 @@ import addKubeconfigSyncAsEntitySourceInjectable from "./start-main-application/
|
||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||
import applicationInformationInjectable from "../common/vars/application-information-injectable";
|
||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
||||
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
||||
|
||||
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
||||
const {
|
||||
@ -119,8 +112,8 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
||||
overrideOperatingSystem(di);
|
||||
overrideRunnablesHavingSideEffects(di);
|
||||
overrideElectronFeatures(di);
|
||||
getOverrideFsWithFakes()(di);
|
||||
|
||||
di.override(isDevelopmentInjectable, () => false);
|
||||
di.override(environmentVariablesInjectable, () => ({}));
|
||||
di.override(commandLineArgumentsInjectable, () => []);
|
||||
|
||||
@ -129,16 +122,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
||||
di.override(stopServicesAndExitAppInjectable, () => () => {});
|
||||
di.override(lensResourcesDirInjectable, () => "/irrelevant");
|
||||
|
||||
overrideFunctionalInjectables(di, [
|
||||
getHelmChartVersionsInjectable,
|
||||
getHelmChartValuesInjectable,
|
||||
listHelmChartsInjectable,
|
||||
writeJsonFileInjectable,
|
||||
readJsonFileInjectable,
|
||||
readFileInjectable,
|
||||
execFileInjectable,
|
||||
]);
|
||||
|
||||
di.override(broadcastMessageInjectable, () => (channel) => {
|
||||
throw new Error(`Tried to broadcast message to channel "${channel}" over IPC without explicit override.`);
|
||||
});
|
||||
@ -225,11 +208,3 @@ const overrideElectronFeatures = (di: DiContainer) => {
|
||||
di.override(setElectronAppPathInjectable, () => () => {});
|
||||
di.override(electronUpdaterIsActiveInjectable, () => false);
|
||||
};
|
||||
|
||||
const overrideFunctionalInjectables = (di: DiContainer, injectables: Injectable<any, any, any>[]) => {
|
||||
injectables.forEach(injectable => {
|
||||
di.override(injectable, () => () => {
|
||||
throw new Error(`Tried to run "${injectable.id}" without explicit override.`);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -24,8 +24,6 @@ const getHelmChartValuesInjectable = getInjectable({
|
||||
return getChartManager(repo).getValues(chartName, version);
|
||||
};
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default getHelmChartValuesInjectable;
|
||||
|
||||
@ -24,8 +24,6 @@ const getHelmChartVersionsInjectable = getInjectable({
|
||||
return getChartManager(repo).chartVersions(chartName);
|
||||
};
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default getHelmChartVersionsInjectable;
|
||||
|
||||
@ -36,8 +36,6 @@ const listHelmChartsInjectable = getInjectable({
|
||||
);
|
||||
};
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default listHelmChartsInjectable;
|
||||
|
||||
@ -17,8 +17,6 @@ const cronJobTriggerDialogClusterFrameChildComponentInjectable = getInjectable({
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default cronJobTriggerDialogClusterFrameChildComponentInjectable;
|
||||
|
||||
@ -17,8 +17,6 @@ const deploymentScaleDialogClusterFrameChildComponentInjectable = getInjectable(
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default deploymentScaleDialogClusterFrameChildComponentInjectable;
|
||||
|
||||
@ -17,8 +17,6 @@ const replicasetScaleDialogClusterFrameChildComponentInjectable = getInjectable(
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default replicasetScaleDialogClusterFrameChildComponentInjectable;
|
||||
|
||||
@ -17,8 +17,6 @@ const statefulsetScaleDialogClusterFrameChildComponentInjectable = getInjectable
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default statefulsetScaleDialogClusterFrameChildComponentInjectable;
|
||||
|
||||
@ -17,8 +17,6 @@ const kubeObjectDetailsClusterFrameChildComponentInjectable = getInjectable({
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default kubeObjectDetailsClusterFrameChildComponentInjectable;
|
||||
|
||||
@ -17,8 +17,6 @@ const kubeconfigDialogClusterFrameChildComponentInjectable = getInjectable({
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default kubeconfigDialogClusterFrameChildComponentInjectable;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { noop, chunk } from "lodash/fp";
|
||||
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { createContainer, isInjectable, getInjectable } from "@ogre-tools/injectable";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import requestFromChannelInjectable from "./utils/channel/request-from-channel.injectable";
|
||||
@ -16,22 +16,13 @@ import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-
|
||||
import hostedClusterIdInjectable from "./cluster-frame-context/hosted-cluster-id.injectable";
|
||||
import historyInjectable from "./navigation/history.injectable";
|
||||
import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.injectable";
|
||||
import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable";
|
||||
import { computed, runInAction } from "mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
|
||||
import getRandomIdInjectable from "../common/utils/get-random-id.injectable";
|
||||
import requestPublicHelmRepositoriesInjectable from "../features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/public-helm-repositories/request-public-helm-repositories.injectable";
|
||||
import platformInjectable from "../common/vars/platform.injectable";
|
||||
import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-state-sync.injectable";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
|
||||
import cronJobTriggerDialogClusterFrameChildComponentInjectable from "./components/+workloads-cronjobs/cron-job-trigger-dialog-cluster-frame-child-component.injectable";
|
||||
import deploymentScaleDialogClusterFrameChildComponentInjectable from "./components/+workloads-deployments/scale/deployment-scale-dialog-cluster-frame-child-component.injectable";
|
||||
import replicasetScaleDialogClusterFrameChildComponentInjectable from "./components/+workloads-replicasets/scale-dialog/replicaset-scale-dialog-cluster-frame-child-component.injectable";
|
||||
import statefulsetScaleDialogClusterFrameChildComponentInjectable from "./components/+workloads-statefulsets/scale/statefulset-scale-dialog-cluster-frame-child-component.injectable";
|
||||
import kubeObjectDetailsClusterFrameChildComponentInjectable from "./components/kube-object-details/kube-object-details-cluster-frame-child-component.injectable";
|
||||
import kubeconfigDialogClusterFrameChildComponentInjectable from "./components/kubeconfig-dialog/kubeconfig-dialog-cluster-frame-child-component.injectable";
|
||||
import portForwardDialogClusterFrameChildComponentInjectable from "./port-forward/port-forward-dialog-cluster-frame-child-component.injectable";
|
||||
import setupSystemCaInjectable from "./frames/root-frame/setup-system-ca.injectable";
|
||||
import extensionShouldBeEnabledForClusterFrameInjectable from "./extension-loader/extension-should-be-enabled-for-cluster-frame.injectable";
|
||||
import { asyncComputed } from "@ogre-tools/injectable-react";
|
||||
@ -114,33 +105,9 @@ export const getDiForUnitTesting = (
|
||||
asyncComputed({ getValueFromObservedPromise: async () => true, valueWhenPending: true }),
|
||||
);
|
||||
|
||||
// TODO: Remove side-effects and shared global state
|
||||
const clusterFrameChildComponentInjectables: Injectable<any, any, any>[] = [
|
||||
cronJobTriggerDialogClusterFrameChildComponentInjectable,
|
||||
deploymentScaleDialogClusterFrameChildComponentInjectable,
|
||||
replicasetScaleDialogClusterFrameChildComponentInjectable,
|
||||
statefulsetScaleDialogClusterFrameChildComponentInjectable,
|
||||
kubeObjectDetailsClusterFrameChildComponentInjectable,
|
||||
kubeconfigDialogClusterFrameChildComponentInjectable,
|
||||
portForwardDialogClusterFrameChildComponentInjectable,
|
||||
];
|
||||
|
||||
clusterFrameChildComponentInjectables.forEach((injectable) => {
|
||||
di.override(injectable, () => ({
|
||||
Component: () => null,
|
||||
id: injectable.id,
|
||||
shouldRender: computed(() => false),
|
||||
}));
|
||||
});
|
||||
|
||||
di.override(environmentVariablesInjectable, () => ({}));
|
||||
di.override(watchHistoryStateInjectable, () => () => () => {});
|
||||
|
||||
overrideFunctionalInjectables(di, [
|
||||
broadcastMessageInjectable,
|
||||
requestPublicHelmRepositoriesInjectable,
|
||||
]);
|
||||
|
||||
di.override(requestFromChannelInjectable, () => () => Promise.resolve(undefined as never));
|
||||
|
||||
getOverrideFsWithFakes()(di);
|
||||
@ -158,11 +125,3 @@ export const getDiForUnitTesting = (
|
||||
|
||||
return di;
|
||||
};
|
||||
|
||||
const overrideFunctionalInjectables = (di: DiContainer, injectables: Injectable<any, any, any>[]) => {
|
||||
injectables.forEach(injectable => {
|
||||
di.override(injectable, () => () => {
|
||||
throw new Error(`Tried to run "${injectable.id}" without explicit override.`);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -17,8 +17,6 @@ const portForwardDialogClusterFrameChildComponentInjectable = getInjectable({
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default portForwardDialogClusterFrameChildComponentInjectable;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user