Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions apps/desktop/src/main/lib/host-service-coordinator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
import {
afterAll,
afterEach,
beforeEach,
describe,
expect,
mock,
test,
} from "bun:test";
import * as fs from "node:fs";
import * as os from "node:os";
import path from "node:path";
Expand Down Expand Up @@ -27,7 +35,9 @@ const removeManifestMock = mock(() => {
});
const isProcessAliveMock = mock(() => true);

const realHostServiceManifest = await import("./host-service-manifest");
mock.module("./host-service-manifest", () => ({
...realHostServiceManifest,
readManifest: readManifestMock,
removeManifest: removeManifestMock,
isProcessAlive: isProcessAliveMock,
Expand All @@ -37,7 +47,9 @@ mock.module("./host-service-manifest", () => ({

const pollHealthCheckMock = mock(() => Promise.resolve(true));

const realHostServiceUtils = await import("./host-service-utils");
mock.module("./host-service-utils", () => ({
...realHostServiceUtils,
HEALTH_POLL_TIMEOUT_MS: 10_000,
MAX_HOST_LOG_BYTES: 1024,
findFreePort: mock(() => Promise.resolve(40000)),
Expand All @@ -61,29 +73,17 @@ mock.module("electron-log/main", () => ({
},
}));

mock.module("@superset/local-db", () => ({ settings: {} }));
const realHostInfo = await import("@superset/shared/host-info");
mock.module("@superset/shared/host-info", () => ({
...realHostInfo,
getHostId: () => "host-1",
getHostName: () => "host",
}));
mock.module("main/env.main", () => ({
env: { NEXT_PUBLIC_API_URL: "", RELAY_URL: "" },
}));
mock.module("shared/env.shared", () => ({
env: { DESKTOP_VITE_PORT: 3000, DESKTOP_NOTIFICATIONS_PORT: 4000 },
}));
mock.module("./app-environment", () => ({
SUPERSET_HOME_DIR: "/tmp/superset",
}));
mock.module("./local-db", () => ({
localDb: {
select: () => ({ from: () => ({ get: () => null }) }),
},
}));
mock.module("./terminal/env", () => ({ HOOK_PROTOCOL_VERSION: "1" }));
mock.module("../../lib/trpc/routers/workspaces/utils/shell-env", () => ({
getProcessEnvWithShellPath: async (e: Record<string, string>) => e,
}));

const { HostServiceCoordinator } = await import("./host-service-coordinator");

Expand Down Expand Up @@ -290,3 +290,7 @@ describe("HostServiceCoordinator.reset", () => {
expect(conn.port).toBe(60000);
});
});

afterAll(() => {
mock.restore();
});
Loading