mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add unit testing requirement to have data serializable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2c48be3ec0
commit
91d336518a
@ -16,6 +16,7 @@ import type { UpdateChannel, UpdateChannelId } from "../../common/application-up
|
|||||||
import { updateChannels } from "../../common/application-update/update-channels";
|
import { updateChannels } from "../../common/application-update/update-channels";
|
||||||
import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
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 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 selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable";
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable";
|
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', () => {
|
describe('given update channel "alpha" is selected, when checking for updates', () => {
|
||||||
let selectedUpdateChannel: {
|
let selectedUpdateChannel: SelectedUpdateChannel;
|
||||||
value: IComputedValue<UpdateChannel>;
|
|
||||||
setValue: (channelId: UpdateChannelId) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
selectedUpdateChannel = applicationBuilder.dis.mainDi.inject(
|
selectedUpdateChannel = applicationBuilder.dis.mainDi.inject(
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { BrowserWindow } from "electron";
|
import type { BrowserWindow } from "electron";
|
||||||
|
import { toJS } from "../../../../common/utils";
|
||||||
import type { SendToViewArgs } from "./lens-window-injection-token";
|
import type { SendToViewArgs } from "./lens-window-injection-token";
|
||||||
|
|
||||||
const sendToChannelInElectronBrowserWindowInjectable = getInjectable({
|
const sendToChannelInElectronBrowserWindowInjectable = getInjectable({
|
||||||
@ -19,10 +20,10 @@ const sendToChannelInElectronBrowserWindowInjectable = getInjectable({
|
|||||||
browserWindow.webContents.sendToFrame(
|
browserWindow.webContents.sendToFrame(
|
||||||
[frameInfo.processId, frameInfo.frameId],
|
[frameInfo.processId, frameInfo.frameId],
|
||||||
channel,
|
channel,
|
||||||
data,
|
toJS(data),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
browserWindow.webContents.send(channel, data);
|
browserWindow.webContents.send(channel, toJS(data));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -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 enlistMessageChannelListenerInjectableInRenderer from "../../renderer/utils/channel/channel-listeners/enlist-message-channel-listener.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import { serialize } from "v8";
|
import { serialize } from "v8";
|
||||||
import { getOrInsertSet } from "../../renderer/utils";
|
import { getOrInsertSet, toJS } from "../../common/utils";
|
||||||
|
import { inspect } from "util";
|
||||||
|
|
||||||
export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => {
|
export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => {
|
||||||
const messageChannelListenerFakesForRenderer = new Map<
|
const messageChannelListenerFakesForRenderer = new Map<
|
||||||
@ -23,7 +24,7 @@ export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => {
|
|||||||
() =>
|
() =>
|
||||||
(
|
(
|
||||||
browserWindow,
|
browserWindow,
|
||||||
{ channel: channelId, frameInfo, data }: SendToViewArgs,
|
{ channel: channelId, frameInfo, data: rawData }: SendToViewArgs,
|
||||||
) => {
|
) => {
|
||||||
const listeners =
|
const listeners =
|
||||||
messageChannelListenerFakesForRenderer.get(channelId) || new Set();
|
messageChannelListenerFakesForRenderer.get(channelId) || new Set();
|
||||||
@ -42,10 +43,15 @@ export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const data = toJS(rawData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
serialize(data);
|
serialize(data);
|
||||||
} catch {
|
} catch (error) {
|
||||||
throw new Error(`Tried to send message to channel "${channelId}" but the value cannot be serialized.`);
|
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));
|
listeners.forEach((listener) => listener.handler(data));
|
||||||
|
|||||||
@ -3,11 +3,12 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
|
import { inspect } from "util";
|
||||||
import { serialize } from "v8";
|
import { serialize } from "v8";
|
||||||
import type { MessageChannel } from "../../common/utils/channel/message-channel-injection-token";
|
import type { MessageChannel } from "../../common/utils/channel/message-channel-injection-token";
|
||||||
import type { MessageChannelListener } from "../../common/utils/channel/message-channel-listener-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 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";
|
import sendToMainInjectable from "../../renderer/utils/channel/send-to-main.injectable";
|
||||||
|
|
||||||
export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => {
|
export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => {
|
||||||
@ -32,11 +33,10 @@ export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (windowDi: DiContainer) => {
|
return (windowDi: DiContainer) => {
|
||||||
windowDi.override(sendToMainInjectable, () => (channelId, message) => {
|
windowDi.override(sendToMainInjectable, () => (channelId, rawMessage) => {
|
||||||
const listeners =
|
const listeners = messageChannelListenerFakesForMain.get(channelId);
|
||||||
messageChannelListenerFakesForMain.get(channelId) || new Set();
|
|
||||||
|
|
||||||
if (listeners.size === 0) {
|
if (!listeners || listeners.size === 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Tried to send message to channel "${channelId}" but there where no listeners. Current channels with listeners: "${[
|
`Tried to send message to channel "${channelId}" but there where no listeners. Current channels with listeners: "${[
|
||||||
...messageChannelListenerFakesForMain.keys(),
|
...messageChannelListenerFakesForMain.keys(),
|
||||||
@ -44,10 +44,15 @@ export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const message = toJS(rawMessage);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
serialize(message);
|
serialize(message);
|
||||||
} catch {
|
} catch (error) {
|
||||||
throw new Error(`Tried to send message to main channel "${channelId}" but the value cannot be serialized.`);
|
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));
|
listeners.forEach((listener) => listener.handler(message));
|
||||||
|
|||||||
@ -3,7 +3,9 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
|
import { inspect } from "util";
|
||||||
import { serialize } from "v8";
|
import { serialize } from "v8";
|
||||||
|
import { toJS } from "../../common/utils";
|
||||||
import type { RequestChannel } from "../../common/utils/channel/request-channel-injection-token";
|
import type { RequestChannel } from "../../common/utils/channel/request-channel-injection-token";
|
||||||
import type { RequestChannelHandler } from "../../common/utils/channel/request-channel-listener-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";
|
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 {
|
try {
|
||||||
serialize(result);
|
serialize(result);
|
||||||
} catch {
|
} catch (error) {
|
||||||
throw new Error(`Tried to request value from channel "${id}" but the value cannot be serialized.`);
|
throw new Error(`Tried to request value from channel "${id}" but the value cannot be serialized: ${inspect(result, {
|
||||||
|
colors: true,
|
||||||
|
depth: Infinity,
|
||||||
|
})}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user