mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix request bases tests as serialization is now down via electron, add general override in applicationBuilder for randomBytes
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ea8c262d3c
commit
299bc475a2
@ -89,7 +89,7 @@ describe("enlist message channel listener in main", () => {
|
||||
});
|
||||
|
||||
it("given stringified object as message, when message arrives, calls the handler with the message", () => {
|
||||
onMock.mock.calls[0][1]({} as IpcMainEvent, JSON.stringify({ some: "object" }));
|
||||
onMock.mock.calls[0][1]({} as IpcMainEvent, { some: "object" });
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith({ some: "object" });
|
||||
});
|
||||
|
||||
@ -91,7 +91,7 @@ describe("enlist request channel listener in main", () => {
|
||||
it("resolves with the response", async () => {
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe('"some-response"');
|
||||
expect(actual).toBe("some-response");
|
||||
});
|
||||
|
||||
it("when disposing the listener, de-registers the listener", () => {
|
||||
@ -101,28 +101,36 @@ describe("enlist request channel listener in main", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("given number as response, when handler resolves with response, listener resolves with stringified response", async () => {
|
||||
it("given number as response, when handler resolves with response, listener resolves with response", async () => {
|
||||
await handlerMock.resolve(42);
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe("42");
|
||||
expect(actual).toBe(42);
|
||||
});
|
||||
|
||||
it("given boolean as response, when handler resolves with response, listener resolves with stringified response", async () => {
|
||||
it("given boolean as response, when handler resolves with response, listener resolves with response", async () => {
|
||||
await handlerMock.resolve(true);
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe("true");
|
||||
expect(actual).toBe(true);
|
||||
});
|
||||
|
||||
it("given object as response, when handler resolves with response, listener resolves with stringified response", async () => {
|
||||
it("given false as response, when handler resolves with response, listener resolves with response", async () => {
|
||||
await handlerMock.resolve(false);
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe(false);
|
||||
});
|
||||
|
||||
it("given object as response, when handler resolves with response, listener resolves with response", async () => {
|
||||
await handlerMock.resolve({ some: "object" });
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe(JSON.stringify({ some: "object" }));
|
||||
expect(actual).toEqual({ some: "object" });
|
||||
});
|
||||
});
|
||||
|
||||
@ -138,8 +146,8 @@ describe("enlist request channel listener in main", () => {
|
||||
expect(handlerMock).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it("given stringified object as request, when request arrives, calls the handler with the request", () => {
|
||||
handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, JSON.stringify({ some: "object" }));
|
||||
it("given object as request, when request arrives, calls the handler with the request", () => {
|
||||
handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, { some: "object" });
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith({ some: "object" });
|
||||
});
|
||||
|
||||
@ -57,13 +57,13 @@ describe("message to channel from main", () => {
|
||||
|
||||
{
|
||||
channel: "some-channel",
|
||||
data: ['"some-message"'],
|
||||
data: ["some-message"],
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it("given boolean as message, when messaging to channel, messages to window with stringified message", () => {
|
||||
it("given boolean as message, when messaging to channel, messages to window with message", () => {
|
||||
messageToChannel(someChannel, true);
|
||||
|
||||
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
|
||||
@ -72,13 +72,13 @@ describe("message to channel from main", () => {
|
||||
|
||||
{
|
||||
channel: "some-channel",
|
||||
data: ["true"],
|
||||
data: [true],
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it("given number as message, when messaging to channel, messages to window with stringified message", () => {
|
||||
it("given number as message, when messaging to channel, messages to window with message", () => {
|
||||
messageToChannel(someChannel, 42);
|
||||
|
||||
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
|
||||
@ -87,13 +87,13 @@ describe("message to channel from main", () => {
|
||||
|
||||
{
|
||||
channel: "some-channel",
|
||||
data: ["42"],
|
||||
data: [42],
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it("given object as message, when messaging to channel, messages to window with stringified message", () => {
|
||||
it("given object as message, when messaging to channel, messages to window with message", () => {
|
||||
messageToChannel(someChannel, { some: "object" });
|
||||
|
||||
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
|
||||
@ -102,7 +102,7 @@ describe("message to channel from main", () => {
|
||||
|
||||
{
|
||||
channel: "some-channel",
|
||||
data: [JSON.stringify({ some: "object" })],
|
||||
data: [{ some: "object" }],
|
||||
},
|
||||
],
|
||||
]);
|
||||
@ -121,7 +121,7 @@ describe("message to channel from main", () => {
|
||||
|
||||
{
|
||||
channel: "some-channel",
|
||||
data: ['"some-message"'],
|
||||
data: ["some-message"],
|
||||
},
|
||||
],
|
||||
|
||||
@ -130,7 +130,7 @@ describe("message to channel from main", () => {
|
||||
|
||||
{
|
||||
channel: "some-channel",
|
||||
data: ['"some-message"'],
|
||||
data: ["some-message"],
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
@ -50,6 +50,7 @@ import lensProxyPortInjectable from "../../../main/lens-proxy/lens-proxy-port.in
|
||||
import type { Route } from "../../../common/front-end-routing/front-end-route-injection-token";
|
||||
import type { NavigateToRouteOptions } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import randomBytesInjectable from "../../../main/utils/random-bytes.injectable";
|
||||
import type { LensMainExtension } from "../../../extensions/lens-main-extension";
|
||||
import type { LensExtension } from "../../../extensions/lens-extension";
|
||||
|
||||
@ -151,6 +152,21 @@ export const getApplicationBuilder = () => {
|
||||
rendererDi.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
mainDi.override(clusterStoreInjectable, () => clusterStoreStub);
|
||||
|
||||
mainDi.override(randomBytesInjectable, () => {
|
||||
let callId = 0;
|
||||
|
||||
return async (count) => {
|
||||
const currentCallId = callId += 1;
|
||||
const values = new Array(count);
|
||||
|
||||
for (let i = 0; i < count; i += 1) {
|
||||
values[i] = ((i + currentCallId) << 2) ^ currentCallId;
|
||||
}
|
||||
|
||||
return Buffer.from(values);
|
||||
};
|
||||
});
|
||||
|
||||
const beforeApplicationStartCallbacks: Callback[] = [];
|
||||
const beforeRenderCallbacks: Callback[] = [];
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ describe("enlist message channel listener in renderer", () => {
|
||||
});
|
||||
|
||||
it("given stringified object as message, when message arrives, calls the handler with the message", () => {
|
||||
onMock.mock.calls[0][1]({} as IpcRendererEvent, JSON.stringify({ some: "object" }));
|
||||
onMock.mock.calls[0][1]({} as IpcRendererEvent, { some: "object" });
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith({ some: "object" });
|
||||
});
|
||||
|
||||
@ -26,30 +26,30 @@ describe("message to channel from renderer", () => {
|
||||
messageToChannel = di.inject(messageToChannelInjectionToken);
|
||||
});
|
||||
|
||||
it("given string as message, when messaging to channel, sends stringified message", () => {
|
||||
it("given string as message, when messaging to channel, sends message", () => {
|
||||
messageToChannel(someChannel, "some-message");
|
||||
|
||||
expect(sendMock).toHaveBeenCalledWith("some-channel-id", '"some-message"');
|
||||
expect(sendMock).toHaveBeenCalledWith("some-channel-id", "some-message");
|
||||
});
|
||||
|
||||
it("given boolean as message, when messaging to channel, sends stringified message", () => {
|
||||
it("given boolean as message, when messaging to channel, sends message", () => {
|
||||
messageToChannel(someChannel, true);
|
||||
|
||||
expect(sendMock).toHaveBeenCalledWith("some-channel-id", "true");
|
||||
expect(sendMock).toHaveBeenCalledWith("some-channel-id", true);
|
||||
});
|
||||
|
||||
it("given number as message, when messaging to channel, sends stringified message", () => {
|
||||
it("given number as message, when messaging to channel, sends message", () => {
|
||||
messageToChannel(someChannel, 42);
|
||||
|
||||
expect(sendMock).toHaveBeenCalledWith("some-channel-id", "42");
|
||||
expect(sendMock).toHaveBeenCalledWith("some-channel-id", 42);
|
||||
});
|
||||
|
||||
it("given object as message, when messaging to channel, sends stringified message", () => {
|
||||
it("given object as message, when messaging to channel, sends message", () => {
|
||||
messageToChannel(someChannel, { some: "object" });
|
||||
|
||||
expect(sendMock).toHaveBeenCalledWith(
|
||||
"some-channel-id",
|
||||
JSON.stringify({ some: "object" }),
|
||||
{ some: "object" },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -39,10 +39,6 @@ describe("request from channel in renderer", () => {
|
||||
actualPromise = requestFromChannel(someChannel, "some-message");
|
||||
});
|
||||
|
||||
it("sends stringified message", () => {
|
||||
expect(invokeMock).toHaveBeenCalledWith("some-channel-id", '"some-message"');
|
||||
});
|
||||
|
||||
it("does not resolve yet", async () => {
|
||||
const promiseStatus = await getPromiseStatus(actualPromise);
|
||||
|
||||
@ -57,65 +53,46 @@ describe("request from channel in renderer", () => {
|
||||
expect(actual).toBe("some-response");
|
||||
});
|
||||
|
||||
it("when invoking resolves with stringified string, resolves with string", async () => {
|
||||
await invokeMock.resolve('"some-response"');
|
||||
it("when resolving with number, resolves with number", async () => {
|
||||
await invokeMock.resolve(10);
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe("some-response");
|
||||
expect(actual).toBe(10);
|
||||
});
|
||||
|
||||
it("when invoking resolves with stringified boolean, resolves with boolean", async () => {
|
||||
await invokeMock.resolve("true");
|
||||
it("when resolving with number 0, resolves with number 0", async () => {
|
||||
await invokeMock.resolve(0);
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe(0);
|
||||
});
|
||||
|
||||
it("when resolving with true, resolves with true", async () => {
|
||||
await invokeMock.resolve(true);
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe(true);
|
||||
});
|
||||
|
||||
it("when invoking resolves with stringified number, resolves with number", async () => {
|
||||
await invokeMock.resolve("42");
|
||||
it("when resolving with false, resolves with false", async () => {
|
||||
await invokeMock.resolve(false);
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe(42);
|
||||
expect(actual).toBe(false);
|
||||
});
|
||||
|
||||
it("when invoking resolves with stringified object, resolves with object", async () => {
|
||||
await invokeMock.resolve(JSON.stringify({ some: "object" }));
|
||||
it("when resolving with object, resolves with object", async () => {
|
||||
await invokeMock.resolve({ myField: true });
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toEqual({ some: "object" });
|
||||
expect(actual).toEqual({ myField: true });
|
||||
});
|
||||
});
|
||||
|
||||
it("given string as message, when messaging to channel, sends stringified message", () => {
|
||||
requestFromChannel(someChannel, "some-message");
|
||||
|
||||
expect(invokeMock).toHaveBeenCalledWith("some-channel-id", '"some-message"');
|
||||
});
|
||||
|
||||
it("given boolean as message, when messaging to channel, sends stringified message", () => {
|
||||
requestFromChannel(someChannel, true);
|
||||
|
||||
expect(invokeMock).toHaveBeenCalledWith("some-channel-id", "true");
|
||||
});
|
||||
|
||||
it("given number as message, when messaging to channel, sends stringified message", () => {
|
||||
requestFromChannel(someChannel, 42);
|
||||
|
||||
expect(invokeMock).toHaveBeenCalledWith("some-channel-id", "42");
|
||||
});
|
||||
|
||||
it("given object as message, when messaging to channel, sends stringified message", () => {
|
||||
requestFromChannel(someChannel, { some: "object" });
|
||||
|
||||
expect(invokeMock).toHaveBeenCalledWith(
|
||||
"some-channel-id",
|
||||
JSON.stringify({ some: "object" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const someChannel: MessageChannel<any> = { id: "some-channel-id" };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user