diff --git a/src/behaviours/application-update/selection-of-update-stability.test.ts b/src/behaviours/application-update/selection-of-update-stability.test.ts index c934e7fc43..fcef3c0bbb 100644 --- a/src/behaviours/application-update/selection-of-update-stability.test.ts +++ b/src/behaviours/application-update/selection-of-update-stability.test.ts @@ -16,6 +16,7 @@ import type { UpdateChannel, UpdateChannelId } from "../../common/application-up import { updateChannels } from "../../common/application-update/update-channels"; import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable"; import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable"; +import type { SelectedUpdateChannel } from "../../common/application-update/selected-update-channel/selected-update-channel.injectable"; import selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable"; import type { IComputedValue } from "mobx"; import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable"; @@ -80,10 +81,7 @@ describe("selection of update stability", () => { }); describe('given update channel "alpha" is selected, when checking for updates', () => { - let selectedUpdateChannel: { - value: IComputedValue; - setValue: (channelId: UpdateChannelId) => void; - }; + let selectedUpdateChannel: SelectedUpdateChannel; beforeEach(() => { selectedUpdateChannel = applicationBuilder.dis.mainDi.inject( diff --git a/src/main/start-main-application/lens-window/application-window/send-to-channel-in-electron-browser-window.injectable.ts b/src/main/start-main-application/lens-window/application-window/send-to-channel-in-electron-browser-window.injectable.ts index 7147837fe0..a2f149a561 100644 --- a/src/main/start-main-application/lens-window/application-window/send-to-channel-in-electron-browser-window.injectable.ts +++ b/src/main/start-main-application/lens-window/application-window/send-to-channel-in-electron-browser-window.injectable.ts @@ -4,6 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { BrowserWindow } from "electron"; +import { toJS } from "../../../../common/utils"; import type { SendToViewArgs } from "./lens-window-injection-token"; const sendToChannelInElectronBrowserWindowInjectable = getInjectable({ @@ -19,10 +20,10 @@ const sendToChannelInElectronBrowserWindowInjectable = getInjectable({ browserWindow.webContents.sendToFrame( [frameInfo.processId, frameInfo.frameId], channel, - data, + toJS(data), ); } else { - browserWindow.webContents.send(channel, data); + browserWindow.webContents.send(channel, toJS(data)); } }, diff --git a/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts b/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts index 7f31b9d480..eb3a1656dc 100644 --- a/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts +++ b/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts @@ -9,7 +9,8 @@ import type { SendToViewArgs } from "../../main/start-main-application/lens-wind import enlistMessageChannelListenerInjectableInRenderer from "../../renderer/utils/channel/channel-listeners/enlist-message-channel-listener.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; import { serialize } from "v8"; -import { getOrInsertSet } from "../../renderer/utils"; +import { getOrInsertSet, toJS } from "../../common/utils"; +import { inspect } from "util"; export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => { const messageChannelListenerFakesForRenderer = new Map< @@ -23,7 +24,7 @@ export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => { () => ( browserWindow, - { channel: channelId, frameInfo, data }: SendToViewArgs, + { channel: channelId, frameInfo, data: rawData }: SendToViewArgs, ) => { const listeners = messageChannelListenerFakesForRenderer.get(channelId) || new Set(); @@ -42,10 +43,15 @@ export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => { ); } + const data = toJS(rawData); + try { serialize(data); - } catch { - throw new Error(`Tried to send message to channel "${channelId}" but the value cannot be serialized.`); + } catch (error) { + throw new Error(`Tried to send message to channel "${channelId}" but the value cannot be serialized: ${inspect(data, { + colors: true, + depth: Infinity, + })}`); } listeners.forEach((listener) => listener.handler(data)); diff --git a/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts b/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts index 995d476b67..b23b3b4170 100644 --- a/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts +++ b/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts @@ -3,11 +3,12 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { DiContainer } from "@ogre-tools/injectable"; +import { inspect } from "util"; import { serialize } from "v8"; import type { MessageChannel } from "../../common/utils/channel/message-channel-injection-token"; import type { MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token"; import enlistMessageChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable"; -import { getOrInsertSet } from "../../renderer/utils"; +import { getOrInsertSet, toJS } from "../../common/utils"; import sendToMainInjectable from "../../renderer/utils/channel/send-to-main.injectable"; export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => { @@ -32,11 +33,10 @@ export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => { ); return (windowDi: DiContainer) => { - windowDi.override(sendToMainInjectable, () => (channelId, message) => { - const listeners = - messageChannelListenerFakesForMain.get(channelId) || new Set(); + windowDi.override(sendToMainInjectable, () => (channelId, rawMessage) => { + const listeners = messageChannelListenerFakesForMain.get(channelId); - if (listeners.size === 0) { + if (!listeners || listeners.size === 0) { throw new Error( `Tried to send message to channel "${channelId}" but there where no listeners. Current channels with listeners: "${[ ...messageChannelListenerFakesForMain.keys(), @@ -44,10 +44,15 @@ export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => { ); } + const message = toJS(rawMessage); + try { serialize(message); - } catch { - throw new Error(`Tried to send message to main channel "${channelId}" but the value cannot be serialized.`); + } catch (error) { + throw new Error(`Tried to send message to main channel "${channelId}" but the value cannot be serialized: ${inspect(message, { + colors: true, + depth: Infinity, + })}`); } listeners.forEach((listener) => listener.handler(message)); diff --git a/src/test-utils/channel-fakes/override-requesting-from-window-to-main.ts b/src/test-utils/channel-fakes/override-requesting-from-window-to-main.ts index f170b5600f..4acfb08b22 100644 --- a/src/test-utils/channel-fakes/override-requesting-from-window-to-main.ts +++ b/src/test-utils/channel-fakes/override-requesting-from-window-to-main.ts @@ -3,7 +3,9 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { DiContainer } from "@ogre-tools/injectable"; +import { inspect } from "util"; import { serialize } from "v8"; +import { toJS } from "../../common/utils"; import type { RequestChannel } from "../../common/utils/channel/request-channel-injection-token"; import type { RequestChannelHandler } from "../../common/utils/channel/request-channel-listener-injection-token"; import enlistRequestChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable"; @@ -47,12 +49,16 @@ export const overrideRequestingFromWindowToMain = (mainDi: DiContainer) => { ); } - const result = requestListener.handler(request); + const rawResult = await requestListener.handler(request); + const result = toJS(rawResult); try { serialize(result); - } catch { - throw new Error(`Tried to request value from channel "${id}" but the value cannot be serialized.`); + } catch (error) { + throw new Error(`Tried to request value from channel "${id}" but the value cannot be serialized: ${inspect(result, { + colors: true, + depth: Infinity, + })}`); } return result;