Add better type safety around Channels (#6133)

* Add better type safety around Channels

- Reallow non-JSON serializable complex types

- Remove unnecessary JSON serialization step to IPC

- Remove unnecesary injectable-ization of MessageChannel and
  RequestChannel declarations

- Add channel listener injectable getter function to remove general need
  for type casting and improve type safety

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add check to verify data in IPC related tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix implementation in light of new safety check in tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix listener ID clash potential

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Switch to not forcing split of request channel handlers being seperate from the listener decl

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move message channels to changed signature too

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix not registering listener

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix test imports

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Refactor listening of different channel kinds

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add test covering new checking code for request channel handlers

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-10-13 07:50:19 -04:00
1 parent d96918c966
commit 5a5eda935b
115 files changed
+949 -1568

No files matched your search

@@ -222,7 +222,7 @@ describe("selection of update stability", () => {
it('given user changes update channel to "alpha", when user would close the application, installs the update for being stable enough', () => {
selectedUpdateChannel.setValue(updateChannels.alpha.id);
expect(setUpdateOnQuitMock).toHaveBeenLastCalledWith(false);
expect(setUpdateOnQuitMock).toHaveBeenLastCalledWith(true);
});
});
});
@@ -1,20 +0,0 @@
/**
* 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 type { ClusterId } from "../../../../common/cluster-types";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-injection-token";
import { requestChannelInjectionToken } from "../../../../common/utils/channel/request-channel-injection-token";
export type ClearClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
const clearClusterAsDeletingChannelInjectable = getInjectable({
id: "clear-cluster-as-deleting-channel",
instantiate: (): ClearClusterAsDeletingChannel => ({
id: "clear-cluster-as-deleting",
}),
injectionToken: requestChannelInjectionToken,
});
export default clearClusterAsDeletingChannelInjectable;
@@ -0,0 +1,12 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ClusterId } from "../../../../common/cluster-types";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
export type ClearClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
export const clearClusterAsDeletingChannel: ClearClusterAsDeletingChannel = {
id: "clear-cluster-as-deleting",
};
@@ -1,20 +0,0 @@
/**
* 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 type { ClusterId } from "../../../../common/cluster-types";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-injection-token";
import { requestChannelInjectionToken } from "../../../../common/utils/channel/request-channel-injection-token";
export type DeleteClusterChannel = RequestChannel<ClusterId, void>;
const deleteClusterChannelInjectable = getInjectable({
id: "delete-cluster-channel",
instantiate: (): DeleteClusterChannel => ({
id: "delete-cluster",
}),
injectionToken: requestChannelInjectionToken,
});
export default deleteClusterChannelInjectable;
@@ -0,0 +1,12 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ClusterId } from "../../../../common/cluster-types";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
export type DeleteClusterChannel = RequestChannel<ClusterId, void>;
export const deleteClusterChannel: DeleteClusterChannel = {
id: "delete-cluster",
};
@@ -1,20 +0,0 @@
/**
* 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 type { ClusterId } from "../../../../common/cluster-types";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-injection-token";
import { requestChannelInjectionToken } from "../../../../common/utils/channel/request-channel-injection-token";
export type SetClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
const setClusterAsDeletingChannelInjectable = getInjectable({
id: "set-cluster-as-deleting-channel",
instantiate: (): SetClusterAsDeletingChannel => ({
id: "set-cluster-as-deleting",
}),
injectionToken: requestChannelInjectionToken,
});
export default setClusterAsDeletingChannelInjectable;
@@ -0,0 +1,12 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ClusterId } from "../../../../common/cluster-types";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
export type SetClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
export const setClusterAsDeletingChannel: SetClusterAsDeletingChannel = {
id: "set-cluster-as-deleting",
};
@@ -1,23 +0,0 @@
/**
* 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 { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
import clearClusterAsDeletingChannelInjectable from "../common/clear-as-deleting-channel.injectable";
const clearClusterAsDeletingChannelHandlerInjectable = getInjectable({
id: "clear-cluster-as-deleting-channel-handler",
instantiate: (di) => {
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
return {
channel: di.inject(clearClusterAsDeletingChannelInjectable),
handler: (clusterId) => clustersThatAreBeingDeleted.delete(clusterId),
};
},
injectionToken: requestChannelListenerInjectionToken,
});
export default clearClusterAsDeletingChannelHandlerInjectable;
@@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel";
const clearClusterAsDeletingChannelListenerInjectable = getRequestChannelListenerInjectable({
channel: clearClusterAsDeletingChannel,
handler: (di) => {
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
return (clusterId) => {
clustersThatAreBeingDeleted.delete(clusterId);
};
},
});
export default clearClusterAsDeletingChannelListenerInjectable;
@@ -1,56 +0,0 @@
/**
* 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 appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
import directoryForLensLocalStorageInjectable from "../../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
import deleteFileInjectable from "../../../../common/fs/delete-file.injectable";
import joinPathsInjectable from "../../../../common/path/join-paths.injectable";
import { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
import deleteClusterChannelInjectable from "../common/delete-channel.injectable";
const deleteClusterChannelHandlerInjectable = getInjectable({
id: "delete-cluster-channel-handler",
instantiate: (di) => {
const appEventBus = di.inject(appEventBusInjectable);
const clusterStore = di.inject(clusterStoreInjectable);
const clusterFrames = di.inject(clusterFramesInjectable);
const joinPaths = di.inject(joinPathsInjectable);
const directoryForLensLocalStorage = di.inject(directoryForLensLocalStorageInjectable);
const deleteFile = di.inject(deleteFileInjectable);
return {
channel: di.inject(deleteClusterChannelInjectable),
handler: async (clusterId) =>{
appEventBus.emit({ name: "cluster", action: "remove" });
const cluster = clusterStore.getById(clusterId);
if (!cluster) {
return;
}
cluster.disconnect();
clusterFrames.delete(cluster.id);
// Remove from the cluster store as well, this should clear any old settings
clusterStore.clusters.delete(cluster.id);
try {
// remove the local storage file
const localStorageFilePath = joinPaths(directoryForLensLocalStorage, `${cluster.id}.json`);
await deleteFile(localStorageFilePath);
} catch {
// ignore error
}
},
};
},
injectionToken: requestChannelListenerInjectionToken,
});
export default deleteClusterChannelHandlerInjectable;
@@ -0,0 +1,51 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
import directoryForLensLocalStorageInjectable from "../../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
import deleteFileInjectable from "../../../../common/fs/delete-file.injectable";
import joinPathsInjectable from "../../../../common/path/join-paths.injectable";
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
import { deleteClusterChannel } from "../common/delete-channel";
const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectable({
channel: deleteClusterChannel,
handler: (di) => {
const appEventBus = di.inject(appEventBusInjectable);
const clusterStore = di.inject(clusterStoreInjectable);
const clusterFrames = di.inject(clusterFramesInjectable);
const joinPaths = di.inject(joinPathsInjectable);
const directoryForLensLocalStorage = di.inject(directoryForLensLocalStorageInjectable);
const deleteFile = di.inject(deleteFileInjectable);
return async (clusterId) => {
appEventBus.emit({ name: "cluster", action: "remove" });
const cluster = clusterStore.getById(clusterId);
if (!cluster) {
return;
}
cluster.disconnect();
clusterFrames.delete(cluster.id);
// Remove from the cluster store as well, this should clear any old settings
clusterStore.clusters.delete(cluster.id);
try {
// remove the local storage file
const localStorageFilePath = joinPaths(directoryForLensLocalStorage, `${cluster.id}.json`);
await deleteFile(localStorageFilePath);
} catch {
// ignore error
}
};
},
});
export default deleteClusterChannelListenerInjectable;
@@ -1,23 +0,0 @@
/**
* 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 { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
import setClusterAsDeletingChannelInjectable from "../common/set-as-deleting-channel.injectable";
const setClusterAsDeletingChannelHandlerInjectable = getInjectable({
id: "set-cluster-as-deleting-channel-handler",
instantiate: (di) => {
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
return {
channel: di.inject(setClusterAsDeletingChannelInjectable),
handler: (clusterId) => clustersThatAreBeingDeleted.add(clusterId),
};
},
injectionToken: requestChannelListenerInjectionToken,
});
export default setClusterAsDeletingChannelHandlerInjectable;
@@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel";
const setClusterAsDeletingChannelHandlerInjectable = getRequestChannelListenerInjectable({
channel: setClusterAsDeletingChannel,
handler: (di) => {
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
return (clusterId) => {
clustersThatAreBeingDeleted.add(clusterId);
};
},
});
export default setClusterAsDeletingChannelHandlerInjectable;
@@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterId } from "../../../../common/cluster-types";
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
import clearClusterAsDeletingChannelInjectable from "../common/clear-as-deleting-channel.injectable";
import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel";
export type RequestClearClusterAsDeleting = (clusterId: ClusterId) => Promise<void>;
@@ -13,7 +13,6 @@ const requestClearClusterAsDeletingInjectable = getInjectable({
id: "request-clear-cluster-as-deleting",
instantiate: (di): RequestClearClusterAsDeleting => {
const requestChannel = di.inject(requestFromChannelInjectable);
const clearClusterAsDeletingChannel = di.inject(clearClusterAsDeletingChannelInjectable);
return (clusterId) => requestChannel(clearClusterAsDeletingChannel, clusterId);
},
@@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterId } from "../../../../common/cluster-types";
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
import deleteClusterChannelInjectable from "../common/delete-channel.injectable";
import { deleteClusterChannel } from "../common/delete-channel";
export type RequestDeleteCluster = (clusterId: ClusterId) => Promise<void>;
@@ -13,7 +13,6 @@ const requestDeleteClusterInjectable = getInjectable({
id: "request-delete-cluster",
instantiate: (di): RequestDeleteCluster => {
const requestChannel = di.inject(requestFromChannelInjectable);
const deleteClusterChannel = di.inject(deleteClusterChannelInjectable);
return (clusterId) => requestChannel(deleteClusterChannel, clusterId);
},
@@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterId } from "../../../../common/cluster-types";
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
import setClusterAsDeletingChannelInjectable from "../common/set-as-deleting-channel.injectable";
import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel";
export type RequestSetClusterAsDeleting = (clusterId: ClusterId) => Promise<void>;
@@ -13,7 +13,6 @@ const requestSetClusterAsDeletingInjectable = getInjectable({
id: "request-set-cluster-as-deleting",
instantiate: (di): RequestSetClusterAsDeleting => {
const requestChannel = di.inject(requestFromChannelInjectable);
const setClusterAsDeletingChannel = di.inject(setClusterAsDeletingChannelInjectable);
return (clusterId) => requestChannel(setClusterAsDeletingChannel, clusterId);
},
@@ -8,6 +8,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { ExecFile } from "../../common/fs/exec-file.injectable";
import execFileInjectable from "../../common/fs/exec-file.injectable";
import helmBinaryPathInjectable from "../../main/helm/helm-binary-path.injectable";
import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
@@ -24,9 +25,7 @@ describe("add custom helm repository in preferences", () => {
let showSuccessNotificationMock: jest.Mock;
let showErrorNotificationMock: jest.Mock;
let rendered: RenderResult;
let execFileMock: AsyncFnMock<
ReturnType<typeof execFileInjectable["instantiate"]>
>;
let execFileMock: AsyncFnMock<ExecFile>;
let getActiveHelmRepositoriesMock: AsyncFnMock<() => Promise<AsyncResult<HelmRepo[]>>>;
beforeEach(async () => {
@@ -184,9 +183,13 @@ describe("add custom helm repository in preferences", () => {
describe("when activation rejects", () => {
beforeEach(async () => {
await execFileMock.reject(
"Some error",
);
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
stderr: "",
},
});
});
it("renders", () => {
@@ -219,8 +222,10 @@ describe("add custom helm repository in preferences", () => {
"some-helm-binary-path",
["repo", "add", "some-custom-repository", "http://some.url"],
],
"",
{
callWasSuccessful: true,
response: "",
},
);
});
@@ -7,6 +7,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { ExecFile } from "../../common/fs/exec-file.injectable";
import execFileInjectable from "../../common/fs/exec-file.injectable";
import helmBinaryPathInjectable from "../../main/helm/helm-binary-path.injectable";
import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
@@ -21,9 +22,7 @@ describe("add helm repository from list in preferences", () => {
let showSuccessNotificationMock: jest.Mock;
let showErrorNotificationMock: jest.Mock;
let rendered: RenderResult;
let execFileMock: AsyncFnMock<
ReturnType<typeof execFileInjectable["instantiate"]>
>;
let execFileMock: AsyncFnMock<ExecFile>;
let getActiveHelmRepositoriesMock: AsyncFnMock<() => Promise<AsyncResult<HelmRepo[]>>>;
let callForPublicHelmRepositoriesMock: AsyncFnMock<() => Promise<HelmRepo[]>>;
@@ -129,9 +128,13 @@ describe("add helm repository from list in preferences", () => {
describe("when adding rejects", () => {
beforeEach(async () => {
await execFileMock.reject(
"Some error",
);
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
stderr: "",
},
});
});
it("renders", () => {
@@ -164,8 +167,10 @@ describe("add helm repository from list in preferences", () => {
"some-helm-binary-path",
["repo", "add", "Some to be added repository", "some-other-url"],
],
"",
{
callWasSuccessful: true,
response: "",
},
);
});
@@ -243,8 +248,10 @@ describe("add helm repository from list in preferences", () => {
"some-helm-binary-path",
["repo", "remove", "Some already active repository"],
],
"",
{
callWasSuccessful: true,
response: "",
},
);
});
@@ -83,7 +83,13 @@ describe("listing active helm repositories in preferences", () => {
describe("when getting configuration rejects", () => {
beforeEach(async () => {
await execFileMock.reject("some-error");
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("some error"),
stderr: "some-error",
},
});
});
it("shows error notification", () => {
@@ -115,7 +121,10 @@ describe("listing active helm repositories in preferences", () => {
await execFileMock.resolveSpecific(
["some-helm-binary-path", ["env"]],
"HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
{
callWasSuccessful: true,
response: "HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
},
);
});
@@ -154,7 +163,10 @@ describe("listing active helm repositories in preferences", () => {
await execFileMock.resolveSpecific(
["some-helm-binary-path", ["env"]],
"HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
{
callWasSuccessful: true,
response: "HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
},
);
});
@@ -193,11 +205,13 @@ describe("listing active helm repositories in preferences", () => {
await execFileMock.resolveSpecific(
["some-helm-binary-path", ["env"]],
[
"HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
"HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
].join("\n"),
{
callWasSuccessful: true,
response: [
"HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
"HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
].join("\n"),
},
);
});
@@ -219,7 +233,13 @@ describe("listing active helm repositories in preferences", () => {
describe("when updating repositories reject with any other error", () => {
beforeEach(async () => {
await execFileMock.reject("Some error");
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
stderr: "Some error",
},
});
});
it("shows error notification", () => {
@@ -249,9 +269,13 @@ describe("listing active helm repositories in preferences", () => {
beforeEach(async () => {
execFileMock.mockClear();
await execFileMock.reject(
"Error: no repositories found. You must add one before updating",
);
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("no repositories found. You must add one before updating"),
stderr: "no repositories found. You must add one before updating",
},
});
});
it("renders", () => {
@@ -274,7 +298,13 @@ describe("listing active helm repositories in preferences", () => {
describe("when adding default repository reject", () => {
beforeEach(async () => {
await execFileMock.reject("Some error");
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
stderr: "Some error",
},
});
});
it("shows error notification", () => {
@@ -307,7 +337,6 @@ describe("listing active helm repositories in preferences", () => {
await execFileMock.resolveSpecific(
[
"some-helm-binary-path",
[
"repo",
"add",
@@ -315,8 +344,10 @@ describe("listing active helm repositories in preferences", () => {
"https://charts.bitnami.com/bitnami",
],
],
"",
{
callWasSuccessful: true,
response: "",
},
);
});
@@ -380,7 +411,10 @@ describe("listing active helm repositories in preferences", () => {
await execFileMock.resolveSpecific(
["some-helm-binary-path", ["repo", "update"]],
"",
{
callWasSuccessful: true,
response: "",
},
);
});
@@ -8,6 +8,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { ExecFile } from "../../common/fs/exec-file.injectable";
import execFileInjectable from "../../common/fs/exec-file.injectable";
import helmBinaryPathInjectable from "../../main/helm/helm-binary-path.injectable";
import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
@@ -19,9 +20,7 @@ describe("remove helm repository from list of active repositories in preferences
let builder: ApplicationBuilder;
let rendered: RenderResult;
let getActiveHelmRepositoriesMock: AsyncFnMock<() => Promise<AsyncResult<HelmRepo[]>>>;
let execFileMock: AsyncFnMock<
ReturnType<typeof execFileInjectable["instantiate"]>
>;
let execFileMock: AsyncFnMock<ExecFile>;
beforeEach(async () => {
builder = getApplicationBuilder();
@@ -101,8 +100,10 @@ describe("remove helm repository from list of active repositories in preferences
"some-helm-binary-path",
["repo", "remove", "some-active-repository"],
],
"",
{
callWasSuccessful: true,
response: "",
},
);
});
@@ -0,0 +1,12 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token";
export type ReloadPageChannel = MessageChannel<void>;
export const reloadPageChannel: ReloadPageChannel = {
id: "reload-page-channel",
};
@@ -0,0 +1,13 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
import { reloadPageChannel } from "../common/channel";
import reloadPageChannelListenerInjectable from "./register-listener.injectable";
export default getGlobalOverride(reloadPageChannelListenerInjectable, () => ({
channel: reloadPageChannel,
handler: () => {},
}));
@@ -0,0 +1,15 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
import { reloadPageChannel } from "../common/channel";
const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "handler",
channel: reloadPageChannel,
handler: () => () => location.reload(),
causesSideEffects: true,
});
export default reloadPageChannelListenerInjectable;