mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Fix lint for non @k8slens/core packages
- Update eslint config to be tighter in control Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
fcef072859
commit
6184c2f03b
29 files changed
+291
-292
No files matched your search
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { IpcMainEvent } from "electron";
|
||||
import ipcMainInjectable from "../ipc-main/ipc-main.injectable";
|
||||
import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging";
|
||||
import { enlistMessageChannelListenerInjectionToken, MessageChannel, MessageChannelListener } from "@k8slens/messaging";
|
||||
|
||||
const enlistMessageChannelListenerInjectable = getInjectable({
|
||||
id: "enlist-message-channel-listener",
|
||||
@@ -9,8 +9,8 @@ const enlistMessageChannelListenerInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const ipcMain = di.inject(ipcMainInjectable);
|
||||
|
||||
return ({ channel, handler }) => {
|
||||
const nativeOnCallback = (nativeEvent: IpcMainEvent, message: any) => {
|
||||
return <T>({ channel, handler }: MessageChannelListener<MessageChannel<T>>) => {
|
||||
const nativeOnCallback = (nativeEvent: IpcMainEvent, message: T) => {
|
||||
handler(message, { frameId: nativeEvent.frameId, processId: nativeEvent.processId });
|
||||
};
|
||||
|
||||
|
||||
+4
@@ -57,6 +57,7 @@ describe("enlist message channel listener in main", () => {
|
||||
|
||||
describe("when message arrives", () => {
|
||||
beforeEach(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
onMock.mock.calls[0][1]({ frameId: 42, processId: 84 } as IpcMainEvent, "some-message");
|
||||
});
|
||||
|
||||
@@ -72,18 +73,21 @@ describe("enlist message channel listener in main", () => {
|
||||
});
|
||||
|
||||
it("given number as message, when message arrives, calls the handler with the message", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
onMock.mock.calls[0][1]({ frameId: 42, processId: 84 } as IpcMainEvent, 42);
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith(42, { frameId: 42, processId: 84 });
|
||||
});
|
||||
|
||||
it("given boolean as message, when message arrives, calls the handler with the message", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
onMock.mock.calls[0][1]({ frameId: 42, processId: 84 } as IpcMainEvent, true);
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith(true, { frameId: 42, processId: 84 });
|
||||
});
|
||||
|
||||
it("given object as message, when message arrives, calls the handler with the message", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
onMock.mock.calls[0][1]({ frameId: 42, processId: 84 } as IpcMainEvent, { some: "object" });
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith({ some: "object" }, { frameId: 42, processId: 84 });
|
||||
|
||||
+6
-2
@@ -48,7 +48,6 @@ describe("enlist request channel listener in main", () => {
|
||||
handlerMock = asyncFn();
|
||||
|
||||
disposer = enlistRequestChannelListener({
|
||||
id: "some-listener",
|
||||
channel: testRequestChannel,
|
||||
handler: handlerMock,
|
||||
});
|
||||
@@ -67,9 +66,11 @@ describe("enlist request channel listener in main", () => {
|
||||
});
|
||||
|
||||
describe("when request arrives", () => {
|
||||
let actualPromise: Promise<any>;
|
||||
let actualPromise: Promise<unknown>;
|
||||
|
||||
beforeEach(() => {
|
||||
// eslint-disable-next-line max-len
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
actualPromise = handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, "some-request");
|
||||
});
|
||||
|
||||
@@ -127,18 +128,21 @@ describe("enlist request channel listener in main", () => {
|
||||
});
|
||||
|
||||
it("given number as request, when request arrives, calls the handler with the request", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, 42);
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith(42);
|
||||
});
|
||||
|
||||
it("given boolean as request, when request arrives, calls the handler with the request", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, true);
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it("given object as request, when request arrives, calls the handler with the request", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, { some: "object" });
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith({ some: "object" });
|
||||
|
||||
+3
-6
@@ -1,4 +1,3 @@
|
||||
/* c8 ignore start */
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { RequestChannel, RequestFromChannel, requestFromChannelInjectionToken } from "@k8slens/messaging";
|
||||
|
||||
@@ -6,12 +5,10 @@ const requestFromChannelInjectable = getInjectable({
|
||||
id: "request-from-channel",
|
||||
|
||||
instantiate: () =>
|
||||
((channel: RequestChannel<any, any>) => {
|
||||
throw new Error(`Tried to request from channel "${channel.id}" but requesting in "main" it's not supported yet`);
|
||||
}) as unknown as RequestFromChannel,
|
||||
|
||||
(async <Request, Response>(channel: RequestChannel<Request, Response>) => {
|
||||
throw new Error(`Tried to request from channel "${channel.id}" from main, which is not supported.`);
|
||||
}) as RequestFromChannel,
|
||||
injectionToken: requestFromChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default requestFromChannelInjectable;
|
||||
/* c8 ignore stop */
|
||||
+4
-2
@@ -10,8 +10,10 @@ const allowCommunicationListenerInjectable = getMessageChannelListenerInjectable
|
||||
getHandler: (di) => {
|
||||
const frameIds = di.inject(frameIdsInjectable);
|
||||
|
||||
return (_, { frameId, processId }) => {
|
||||
frameIds.add({ frameId, processId });
|
||||
return (_, info) => {
|
||||
if (info) {
|
||||
frameIds.add(info);
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
+7
-7
@@ -17,7 +17,7 @@ describe("send-message-to-channel", () => {
|
||||
registerFeature(di, messagingFeatureForMain);
|
||||
});
|
||||
|
||||
it("given no web contents, when sending a message, does not do anything", () => {
|
||||
it("given no web contents, when sending a message, does not do an unknown thing", () => {
|
||||
di.override(getWebContentsInjectable, () => () => []);
|
||||
|
||||
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
|
||||
@@ -26,8 +26,8 @@ describe("send-message-to-channel", () => {
|
||||
});
|
||||
|
||||
describe("given web content that is alive", () => {
|
||||
let sendToFrameMock: jest.Mock;
|
||||
let sendMessageMock: jest.Mock;
|
||||
let sendToFrameMock: jest.MockedFunction<(...args: unknown[]) => void>;
|
||||
let sendMessageMock: jest.MockedFunction<(...args: unknown[]) => void>;
|
||||
|
||||
beforeEach(() => {
|
||||
sendToFrameMock = jest.fn();
|
||||
@@ -35,14 +35,14 @@ describe("send-message-to-channel", () => {
|
||||
|
||||
di.override(getWebContentsInjectable, () => () => [
|
||||
{
|
||||
send: (...args: any[]) => sendMessageMock("first", ...args),
|
||||
sendToFrame: (...args: any[]) => sendToFrameMock("first", ...args),
|
||||
send: (...args: unknown[]) => sendMessageMock("first", ...args),
|
||||
sendToFrame: (...args: unknown[]) => sendToFrameMock("first", ...args),
|
||||
isDestroyed: () => false,
|
||||
isCrashed: () => false,
|
||||
} as unknown as WebContents,
|
||||
{
|
||||
send: (...args: any[]) => sendMessageMock("second", ...args),
|
||||
sendToFrame: (...args: any[]) => sendToFrameMock("second", ...args),
|
||||
send: (...args: unknown[]) => sendMessageMock("second", ...args),
|
||||
sendToFrame: (...args: unknown[]) => sendToFrameMock("second", ...args),
|
||||
isDestroyed: () => false,
|
||||
isCrashed: () => false,
|
||||
} as unknown as WebContents,
|
||||
|
||||
+13
-20
@@ -1,18 +1,15 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { SendMessageToChannel, sendMessageToChannelInjectionToken } from "@k8slens/messaging";
|
||||
import getWebContentsInjectable from "./get-web-contents.injectable";
|
||||
import { flatMap, reject } from "lodash/fp";
|
||||
import type { WebContents } from "electron";
|
||||
import frameIdsInjectable from "./frameIds.injectable";
|
||||
|
||||
const isDestroyed = (webContent: WebContents) => webContent.isDestroyed();
|
||||
const isCrashed = (webContent: WebContents) => webContent.isCrashed();
|
||||
|
||||
const forEach =
|
||||
<T>(predicate: (item: T) => void) =>
|
||||
(items: T[]) =>
|
||||
items.forEach(predicate);
|
||||
const not =
|
||||
<T>(fn: (val: T) => boolean) =>
|
||||
(val: T) =>
|
||||
!fn(val);
|
||||
|
||||
const sendMessageToChannelInjectable = getInjectable({
|
||||
id: "send-message-to-channel",
|
||||
@@ -22,23 +19,19 @@ const sendMessageToChannelInjectable = getInjectable({
|
||||
const frameIds = di.inject(frameIdsInjectable);
|
||||
|
||||
return ((channel, message) => {
|
||||
pipeline(
|
||||
getWebContents(),
|
||||
reject(isDestroyed),
|
||||
reject(isCrashed),
|
||||
getWebContents()
|
||||
.filter(not(isDestroyed))
|
||||
.filter(not(isCrashed))
|
||||
.flatMap((webContent) => [
|
||||
(channelId: string, ...args: unknown[]) => webContent.send(channelId, ...args),
|
||||
|
||||
flatMap((webContent) => [
|
||||
(channelId: string, ...args: any[]) => webContent.send(channelId, ...args),
|
||||
|
||||
...[...frameIds].map(({ frameId, processId }) => (channelId: string, ...args: any[]) => {
|
||||
...[...frameIds].map(({ frameId, processId }) => (channelId: string, ...args: unknown[]) => {
|
||||
webContent.sendToFrame([processId, frameId], channelId, ...args);
|
||||
}),
|
||||
]),
|
||||
|
||||
forEach((send) => {
|
||||
])
|
||||
.forEach((send) => {
|
||||
send(channel.id, message);
|
||||
}),
|
||||
);
|
||||
});
|
||||
}) as SendMessageToChannel;
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user