mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Simplify test setup by removing option for global overrides (#7302)
* Remove option to doGeneralOverrides and do it always Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Override telemetry by default to optimize and simplify testing Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Simplify more usages of getDiForUnitTesting Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code style Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> --------- Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
8fa92c06ea
commit
0d480917cf
95 files changed
+165
-161
No files matched your search
@@ -31,7 +31,7 @@ describe("create clusters", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
const clusterServerUrl = "https://192.168.64.3:8443";
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
|
||||
@@ -53,7 +53,7 @@ describe("ContextHandler", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
di.override(createKubeAuthProxyInjectable, () => ({} as any));
|
||||
|
||||
createContextHandler = di.inject(createContextHandlerInjectable);
|
||||
|
||||
@@ -39,7 +39,7 @@ describe("kube auth proxy tests", () => {
|
||||
let getBasenameOfPath: GetBasenameOfPath;
|
||||
|
||||
beforeEach(async () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
di.override(directoryForTempInjectable, () => "/some-directory-for-temp");
|
||||
|
||||
@@ -46,7 +46,7 @@ describe("kubeconfig manager tests", () => {
|
||||
let ensureServerMock: AsyncFnMock<() => Promise<void>>;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForTempInjectable, () => "/some-directory-for-temp");
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
|
||||
@@ -11,7 +11,7 @@ describe("static-file-route", () => {
|
||||
let handleStaticFileRoute: Route<Buffer, "/{path*}">;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
handleStaticFileRoute = di.inject(staticFileRouteInjectable);
|
||||
});
|
||||
|
||||
+3
-1
@@ -11,7 +11,9 @@ describe("get-electron-app-path", () => {
|
||||
let getElectronAppPath: (name: string) => string;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: false });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.unoverride(getElectronAppPathInjectable);
|
||||
|
||||
const appStub = {
|
||||
name: "some-app-name",
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("kubeconfig-sync.source tests", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
di.override(directoryForTempInjectable, () => "/some-directory-for-temp");
|
||||
|
||||
@@ -65,7 +65,7 @@ describe("CatalogEntityRegistry", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
entityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("detect-cluster-metadata", () => {
|
||||
let cluster: Cluster;
|
||||
|
||||
beforeEach(async () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
const lastSeenDetectMock = jest.fn().mockReturnValue(Promise.resolve({ value: "some-time-stamp", accuracy: 100 }));
|
||||
const nodeCountDetectMock = jest.fn().mockReturnValue(Promise.resolve({ value: 42, accuracy: 100 }));
|
||||
|
||||
@@ -33,11 +33,7 @@ import {
|
||||
} from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
|
||||
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
||||
const {
|
||||
doGeneralOverrides = false,
|
||||
} = opts;
|
||||
|
||||
export function getDiForUnitTesting() {
|
||||
const di = createContainer("main");
|
||||
|
||||
registerMobX(di);
|
||||
@@ -56,34 +52,32 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
||||
}
|
||||
});
|
||||
|
||||
if (doGeneralOverrides) {
|
||||
for (const globalOverridePath of global.injectablePaths.main.globalOverridePaths) {
|
||||
const globalOverride = require(globalOverridePath).default as GlobalOverride;
|
||||
for (const globalOverridePath of global.injectablePaths.main.globalOverridePaths) {
|
||||
const globalOverride = require(globalOverridePath).default as GlobalOverride;
|
||||
|
||||
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
||||
}
|
||||
|
||||
di.override(electronInjectable, () => ({}));
|
||||
di.override(waitUntilBundledExtensionsAreLoadedInjectable, () => async () => {});
|
||||
|
||||
overrideRunnablesHavingSideEffects(di);
|
||||
overrideElectronFeatures(di);
|
||||
getOverrideFsWithFakes()(di);
|
||||
|
||||
di.override(clusterFramesInjectable, () => observable.map<string, ClusterFrameInfo>());
|
||||
|
||||
di.override(broadcastMessageInjectable, () => (channel) => {
|
||||
throw new Error(`Tried to broadcast message to channel "${channel}" over IPC without explicit override.`);
|
||||
});
|
||||
di.override(spawnInjectable, () => () => {
|
||||
return {
|
||||
stderr: { on: jest.fn(), removeAllListeners: jest.fn() },
|
||||
stdout: { on: jest.fn(), removeAllListeners: jest.fn() },
|
||||
on: jest.fn(),
|
||||
} as never;
|
||||
});
|
||||
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
||||
}
|
||||
|
||||
di.override(electronInjectable, () => ({}));
|
||||
di.override(waitUntilBundledExtensionsAreLoadedInjectable, () => async () => {});
|
||||
|
||||
overrideRunnablesHavingSideEffects(di);
|
||||
overrideElectronFeatures(di);
|
||||
getOverrideFsWithFakes()(di);
|
||||
|
||||
di.override(clusterFramesInjectable, () => observable.map<string, ClusterFrameInfo>());
|
||||
|
||||
di.override(broadcastMessageInjectable, () => (channel) => {
|
||||
throw new Error(`Tried to broadcast message to channel "${channel}" over IPC without explicit override.`);
|
||||
});
|
||||
di.override(spawnInjectable, () => () => {
|
||||
return {
|
||||
stderr: { on: jest.fn(), removeAllListeners: jest.fn() },
|
||||
stdout: { on: jest.fn(), removeAllListeners: jest.fn() },
|
||||
on: jest.fn(),
|
||||
} as never;
|
||||
});
|
||||
|
||||
return di;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ describe("Helm Service tests", () => {
|
||||
let getActiveHelmRepositoriesMock: jest.Mock<Promise<AsyncResult<HelmRepo[]>>>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
getActiveHelmRepositoriesMock = jest.fn();
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ describe("exec-file-with-input", () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.unoverride(execFileWithInputInjectable);
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ describe("get helm release resources", () => {
|
||||
let execFileWithStreamInputMock: AsyncFnMock<ExecFileWithInput>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
execHelmMock = asyncFn();
|
||||
execFileWithStreamInputMock = asyncFn();
|
||||
|
||||
@@ -37,7 +37,7 @@ describe("protocol router tests", () => {
|
||||
let broadcastMessageMock: jest.Mock;
|
||||
|
||||
beforeEach(async () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(pathExistsInjectable, () => () => { throw new Error("tried call pathExists without override"); });
|
||||
di.override(pathExistsSyncInjectable, () => () => { throw new Error("tried call pathExistsSync without override"); });
|
||||
|
||||
@@ -28,7 +28,7 @@ describe("router", () => {
|
||||
beforeEach(async () => {
|
||||
routeHandlerMock = asyncFn();
|
||||
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(parseRequestInjectable, () => () => Promise.resolve({
|
||||
payload: "some-payload",
|
||||
|
||||
@@ -26,9 +26,7 @@ describe("technical unit tests for local shell sessions", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({
|
||||
doGeneralOverrides: true,
|
||||
});
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
di.override(buildVersionInjectable, () => ({
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ describe("enlist message channel listener in main", () => {
|
||||
let offMock: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
onMock = jest.fn();
|
||||
offMock = jest.fn();
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ describe("enlist request channel listener in main", () => {
|
||||
let offMock: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
handleMock = jest.fn();
|
||||
offMock = jest.fn();
|
||||
|
||||
@@ -15,7 +15,7 @@ describe("message-to-channel", () => {
|
||||
let sendToWindowMock: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
sendToWindowMock = jest.fn();
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ describe("technical: resolve-system-proxy-from-electron", () => {
|
||||
let actualPromise: Promise<string>;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
logErrorMock = jest.fn();
|
||||
di.override(logErrorInjectable, () => logErrorMock);
|
||||
|
||||
Reference in new issue
Block a user