Fix tests not stopping by forcing cleanup

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-01-10 15:18:11 -05:00
1 parent 8fd732b3fa
commit e9e248e32c
80 files changed
+1258 -1577

No files matched your search

+4 -8
View File
@@ -7,17 +7,17 @@ import getElectronAppPathInjectable from "../../main/app-paths/get-electron-app-
import type { PathName } from "./app-path-names";
import setElectronAppPathInjectable from "../../main/app-paths/set-electron-app-path/set-electron-app-path.injectable";
import directoryForIntegrationTestingInjectable from "../../main/app-paths/directory-for-integration-testing/directory-for-integration-testing.injectable";
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import type { ApplicationBuilder } from "../../features/test-utils/application-builder";
import { setupInitializingApplicationBuilder } from "../../features/test-utils/application-builder";
import type { DiContainer } from "@ogre-tools/injectable";
import appPathsInjectable from "./app-paths.injectable";
describe("app-paths", () => {
let builder: ApplicationBuilder;
beforeEach(() => {
builder = getApplicationBuilder();
setupInitializingApplicationBuilder(b => builder = b);
beforeEach(() => {
const defaultAppPathsStub: AppPaths = {
currentApp: "/some-current-app",
appData: "/some-app-data",
@@ -56,10 +56,6 @@ describe("app-paths", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("normally", () => {
let windowDi: DiContainer;
let mainDi: DiContainer;
+6 -29
View File
@@ -6,8 +6,8 @@ import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { SendMessageToChannel } from "./message-to-channel-injection-token";
import { sendMessageToChannelInjectionToken } from "./message-to-channel-injection-token";
import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import type { ApplicationBuilder } from "../../../features/test-utils/application-builder";
import { setupInitializingApplicationBuilder } from "../../../features/test-utils/application-builder";
import type { LensWindow } from "../../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
import type { MessageChannel } from "./message-channel-listener-injection-token";
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
@@ -25,15 +25,16 @@ type TestMessageChannel = MessageChannel<string>;
type TestRequestChannel = RequestChannel<string, string>;
describe("channel", () => {
let builder: ApplicationBuilder;
setupInitializingApplicationBuilder(b => builder = b);
describe("messaging from main to renderer, given listener for channel in a window and application has started", () => {
let messageListenerInWindowMock: jest.Mock;
let mainDi: DiContainer;
let messageToChannel: SendMessageToChannel;
let builder: ApplicationBuilder;
beforeEach(async () => {
builder = getApplicationBuilder();
messageListenerInWindowMock = jest.fn();
const testChannelListenerInTestWindowInjectable = getInjectable({
@@ -60,10 +61,6 @@ describe("channel", () => {
messageToChannel = mainDi.inject(sendMessageToChannelInjectionToken);
});
afterEach(() => {
builder.quit();
});
describe("given window is started", () => {
let someWindowFake: LensWindow;
@@ -107,10 +104,8 @@ 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 () => {
builder = getApplicationBuilder();
messageListenerInMainMock = jest.fn();
const testChannelListenerInMainInjectable = getInjectable({
@@ -137,10 +132,6 @@ describe("channel", () => {
messageToChannel = windowDi.inject(sendMessageToChannelInjectionToken);
});
afterEach(() => {
builder.quit();
});
it("when sending message, triggers listener in main", () => {
messageToChannel(testMessageChannel, "some-message");
@@ -151,10 +142,8 @@ 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 () => {
builder = getApplicationBuilder();
requestListenerInMainMock = asyncFn();
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
@@ -175,10 +164,6 @@ describe("channel", () => {
requestFromChannel = windowDi.inject(requestFromChannelInjectable);
});
afterEach(() => {
builder.quit();
});
describe("when requesting from channel", () => {
let actualPromise: Promise<string>;
@@ -207,11 +192,7 @@ describe("channel", () => {
});
describe("when registering multiple handlers for the same channel", () => {
let builder: ApplicationBuilder;
beforeEach(() => {
builder = getApplicationBuilder();
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
channel: testRequestChannel,
handler: () => () => "some-value",
@@ -231,10 +212,6 @@ describe("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.');
});
+4 -8
View File
@@ -5,8 +5,8 @@
import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import { observe, runInAction } from "mobx";
import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import type { ApplicationBuilder } from "../../../features/test-utils/application-builder";
import { setupInitializingApplicationBuilder } from "../../../features/test-utils/application-builder";
import createSyncBoxInjectable from "./create-sync-box.injectable";
import type { SyncBox } from "./sync-box-injection-token";
import { syncBoxInjectionToken } from "./sync-box-injection-token";
@@ -14,9 +14,9 @@ import { syncBoxInjectionToken } from "./sync-box-injection-token";
describe("sync-box", () => {
let builder: ApplicationBuilder;
beforeEach(() => {
builder = getApplicationBuilder();
setupInitializingApplicationBuilder(b => builder = b);
beforeEach(() => {
builder.beforeApplicationStart(mainDi => {
runInAction(() => {
mainDi.register(someInjectable);
@@ -30,10 +30,6 @@ describe("sync-box", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("given application is started, when value is set in main", () => {
let valueInMain: string;
let syncBoxInMain: SyncBox<string>;