Consolidate code for application window

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2022-05-11 08:28:08 +03:00
1 parent 5ac9b2aa87
commit 55d1471c10
68 files changed
+730 -387

No files matched your search

@@ -5,7 +5,6 @@
import { getDiForUnitTesting as getRendererDi } from "../renderer/getDiForUnitTesting";
import { getDiForUnitTesting as getMainDi } from "../main/getDiForUnitTesting";
import { overrideIpcBridge } from "./override-ipc-bridge";
import { runSetups } from "../common/setupable-injection-token/run-setups";
export const getDisForUnitTesting = (
{ doGeneralOverrides } = { doGeneralOverrides: false },
@@ -18,8 +17,5 @@ export const getDisForUnitTesting = (
return {
rendererDi,
mainDi,
runSetups: () =>
Promise.all([runSetups(rendererDi), runSetups(mainDi)]),
};
};
+9 -2
View File
@@ -10,6 +10,7 @@ import asyncFn from "@async-fn/jest";
import registerIpcChannelListenerInjectable from "../renderer/app-paths/get-value-from-registered-channel/register-ipc-channel-listener.injectable";
import type { SendToViewArgs } from "../main/start-main-application/lens-window/application-window/lens-window-injection-token";
import sendToChannelInElectronBrowserWindowInjectable from "../main/start-main-application/lens-window/application-window/send-to-channel-in-electron-browser-window.injectable";
import { isEmpty } from "lodash/fp";
export const overrideIpcBridge = ({
@@ -89,9 +90,15 @@ export const overrideIpcBridge = ({
(browserWindow, { channel: channelName, data }: SendToViewArgs) => {
const handles = rendererIpcFakeHandles.get(channelName);
handles.forEach((handle) => handle(...data));
if (isEmpty(handles)) {
throw new Error(
`Tried to send message to channel "${channelName}" but there where no listeners. Current channels with listeners: "${[
...rendererIpcFakeHandles.keys(),
].join('", "')}"`,
);
}
return Promise.resolve();
handles.forEach((handle) => handle(...data));
},
);
};