mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce and use ApplicationBuilder.quit in afterEach() hooks
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
8136e23ac6
commit
f11145045b
76 files changed
+497
-153
No files matched your search
@@ -56,6 +56,10 @@ describe("app-paths", () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
builder.quit();
|
||||
});
|
||||
|
||||
describe("normally", () => {
|
||||
let windowDi: DiContainer;
|
||||
let mainDi: DiContainer;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import createReadFileStreamInjectable from "./create-read-file-stream.injectable";
|
||||
|
||||
export default getGlobalOverride(createReadFileStreamInjectable, () => () => {
|
||||
throw new Error("tried to create read stream for a file without override");
|
||||
});
|
||||
@@ -60,6 +60,10 @@ describe("channel", () => {
|
||||
messageToChannel = mainDi.inject(sendMessageToChannelInjectionToken);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
builder.quit();
|
||||
});
|
||||
|
||||
describe("given window is started", () => {
|
||||
let someWindowFake: LensWindow;
|
||||
|
||||
@@ -103,10 +107,10 @@ describe("channel", () => {
|
||||
describe("messaging from renderer to main, given listener for channel in a main and application has started", () => {
|
||||
let messageListenerInMainMock: jest.Mock;
|
||||
let messageToChannel: SendMessageToChannel;
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
beforeEach(async () => {
|
||||
const applicationBuilder = getApplicationBuilder();
|
||||
|
||||
builder = getApplicationBuilder();
|
||||
messageListenerInMainMock = jest.fn();
|
||||
|
||||
const testChannelListenerInMainInjectable = getInjectable({
|
||||
@@ -120,19 +124,23 @@ describe("channel", () => {
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
applicationBuilder.beforeApplicationStart((mainDi) => {
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testChannelListenerInMainInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
await applicationBuilder.render();
|
||||
await builder.render();
|
||||
|
||||
const windowDi = applicationBuilder.applicationWindow.only.di;
|
||||
const windowDi = builder.applicationWindow.only.di;
|
||||
|
||||
messageToChannel = windowDi.inject(sendMessageToChannelInjectionToken);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
builder.quit();
|
||||
});
|
||||
|
||||
it("when sending message, triggers listener in main", () => {
|
||||
messageToChannel(testMessageChannel, "some-message");
|
||||
|
||||
@@ -143,10 +151,10 @@ describe("channel", () => {
|
||||
describe("requesting from main in renderer, given listener for channel in a main and application has started", () => {
|
||||
let requestListenerInMainMock: AsyncFnMock<RequestChannelHandler<TestRequestChannel>>;
|
||||
let requestFromChannel: RequestFromChannel;
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
beforeEach(async () => {
|
||||
const applicationBuilder = getApplicationBuilder();
|
||||
|
||||
builder = getApplicationBuilder();
|
||||
requestListenerInMainMock = asyncFn();
|
||||
|
||||
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
|
||||
@@ -154,19 +162,23 @@ describe("channel", () => {
|
||||
handler: () => requestListenerInMainMock,
|
||||
});
|
||||
|
||||
applicationBuilder.beforeApplicationStart((mainDi) => {
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testChannelListenerInMainInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
await applicationBuilder.render();
|
||||
await builder.render();
|
||||
|
||||
const windowDi = applicationBuilder.applicationWindow.only.di;
|
||||
const windowDi = builder.applicationWindow.only.di;
|
||||
|
||||
requestFromChannel = windowDi.inject(requestFromChannelInjectable);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
builder.quit();
|
||||
});
|
||||
|
||||
describe("when requesting from channel", () => {
|
||||
let actualPromise: Promise<string>;
|
||||
|
||||
@@ -194,28 +206,38 @@ describe("channel", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("when registering multiple handlers for the same channel, throws", async () => {
|
||||
const applicationBuilder = getApplicationBuilder();
|
||||
describe("when registering multiple handlers for the same channel", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
|
||||
channel: testRequestChannel,
|
||||
handler: () => () => "some-value",
|
||||
});
|
||||
const testChannelListenerInMain2Injectable = getRequestChannelListenerInjectable({
|
||||
channel: testRequestChannel,
|
||||
handler: () => () => "some-other-value",
|
||||
});
|
||||
beforeEach(() => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
testChannelListenerInMain2Injectable.id += "2";
|
||||
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
|
||||
channel: testRequestChannel,
|
||||
handler: () => () => "some-value",
|
||||
});
|
||||
const testChannelListenerInMain2Injectable = getRequestChannelListenerInjectable({
|
||||
channel: testRequestChannel,
|
||||
handler: () => () => "some-other-value",
|
||||
});
|
||||
|
||||
applicationBuilder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testChannelListenerInMainInjectable);
|
||||
mainDi.register(testChannelListenerInMain2Injectable);
|
||||
testChannelListenerInMain2Injectable.id += "2";
|
||||
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testChannelListenerInMainInjectable);
|
||||
mainDi.register(testChannelListenerInMain2Injectable);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await expect(applicationBuilder.render()).rejects.toThrow('Tried to register a multiple channel handlers for "some-request-channel-id", only one handler is supported for a request channel.');
|
||||
afterEach(() => {
|
||||
builder.quit();
|
||||
});
|
||||
|
||||
it("throws on startup", async () => {
|
||||
await expect(builder.render()).rejects.toThrow('Tried to register a multiple channel handlers for "some-request-channel-id", only one handler is supported for a request channel.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -12,32 +12,36 @@ import type { SyncBox } from "./sync-box-injection-token";
|
||||
import { syncBoxInjectionToken } from "./sync-box-injection-token";
|
||||
|
||||
describe("sync-box", () => {
|
||||
let applicationBuilder: ApplicationBuilder;
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
beforeEach(() => {
|
||||
applicationBuilder = getApplicationBuilder();
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
applicationBuilder.beforeApplicationStart(mainDi => {
|
||||
builder.beforeApplicationStart(mainDi => {
|
||||
runInAction(() => {
|
||||
mainDi.register(someInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
applicationBuilder.beforeWindowStart((windowDi) => {
|
||||
builder.beforeWindowStart((windowDi) => {
|
||||
runInAction(() => {
|
||||
windowDi.register(someInjectable);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
builder.quit();
|
||||
});
|
||||
|
||||
describe("given application is started, when value is set in main", () => {
|
||||
let valueInMain: string;
|
||||
let syncBoxInMain: SyncBox<string>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await applicationBuilder.startHidden();
|
||||
await builder.startHidden();
|
||||
|
||||
syncBoxInMain = applicationBuilder.mainDi.inject(someInjectable);
|
||||
syncBoxInMain = builder.mainDi.inject(someInjectable);
|
||||
|
||||
observe(syncBoxInMain.value, ({ newValue }) => {
|
||||
valueInMain = newValue as string;
|
||||
@@ -59,7 +63,7 @@ describe("sync-box", () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
const applicationWindow =
|
||||
applicationBuilder.applicationWindow.create("some-window-id");
|
||||
builder.applicationWindow.create("some-window-id");
|
||||
|
||||
await applicationWindow.start();
|
||||
|
||||
@@ -101,11 +105,11 @@ describe("sync-box", () => {
|
||||
let syncBoxInRenderer: SyncBox<string>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await applicationBuilder.render();
|
||||
await builder.render();
|
||||
|
||||
const applicationWindow = applicationBuilder.applicationWindow.only;
|
||||
const applicationWindow = builder.applicationWindow.only;
|
||||
|
||||
syncBoxInMain = applicationBuilder.mainDi.inject(someInjectable);
|
||||
syncBoxInMain = builder.mainDi.inject(someInjectable);
|
||||
syncBoxInRenderer = applicationWindow.di.inject(someInjectable);
|
||||
|
||||
observe(syncBoxInRenderer.value, ({ newValue }) => {
|
||||
|
||||
Reference in new issue
Block a user