Files
Termix/src/ui/tests/lib/embedded-server-status.test.ts
T
62ac931468 v26.10.1 (#1599)
* feat: AI translations at release, 7 new languages and regional fallback

* fix: proper plural forms for count strings and full translations

* fix: plural forms for selected, hidden and active counts

* fix: synced plugin updates failing on desktop and server-only plugins shown as stopped

* fix: restore rounded corners on app icons and favicon

* feat: desktop app auto updates with automatic, ask first or never modes

* feat: community and custom plugin registries

* feat: plugin guide for AI tools in the SDK with a lint check

* fix: keep the terminal WebSocket open past nginx's 60s default (#1588)

* chore: update changelog

* feat: show plugin download counts only and stop CI builds inflating them

* feat: hide installed plugins in the browse tab by default

* chore: pin bundled plugins to latest releases

* chore: update translations

* fix: focusing a saved password field and saving no longer erases it

* fix: tell desktop users when their 2.8 data needs 2.9 first

* fix: point windows update info at the x64 installer

* fix: keep desktop client tunnel sockets alive behind proxies

* chore: pin bundled plugins to latest releases

* fix: cover client tunnel keepalive in the c2s runtime tests

* fix: typing after opening a host no longer goes to the host search

* fix: accept tab and = separators in SSH config import (#1598)

* chore: update changelog

* chore: drop plugin versions from core changelog

* chore: update translations

* chore: lint, format, and bump version to 26.10.1

---------

Co-authored-by: Darnel Hunter <68697450+innotelinc@users.noreply.github.com>
Co-authored-by: Iain <Iain1970@protonmail.com>
2026-10-12 11:35:48 -05:00

96 lines
2.9 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { getEmbeddedServerFailure } from "@/lib/embedded-server-status";
function setElectronAPI(api: unknown) {
(window as unknown as { electronAPI?: unknown }).electronAPI = api;
}
afterEach(() => {
delete (window as unknown as { electronAPI?: unknown }).electronAPI;
});
describe("getEmbeddedServerFailure", () => {
it("returns null outside Electron, where there is no embedded backend", async () => {
await expect(getEmbeddedServerFailure()).resolves.toBeNull();
});
it("returns null while the backend is merely still booting", async () => {
setElectronAPI({
isElectron: true,
getEmbeddedServerStatus: vi
.fn()
.mockResolvedValue({ running: false, failure: null }),
});
await expect(getEmbeddedServerFailure()).resolves.toBeNull();
});
it("surfaces a port conflict with the port that was taken", async () => {
setElectronAPI({
isElectron: true,
getEmbeddedServerStatus: vi.fn().mockResolvedValue({
running: false,
failure: { reason: "port-in-use", port: 30001 },
}),
});
await expect(getEmbeddedServerFailure()).resolves.toEqual({
reason: "port-in-use",
port: 30001,
});
});
it("surfaces a database too old to open", async () => {
setElectronAPI({
isElectron: true,
getEmbeddedServerStatus: vi.fn().mockResolvedValue({
running: false,
failure: { reason: "old-database", port: null },
}),
});
await expect(getEmbeddedServerFailure()).resolves.toEqual({
reason: "old-database",
port: null,
});
});
it("surfaces a generic crash", async () => {
setElectronAPI({
isElectron: true,
getEmbeddedServerStatus: vi.fn().mockResolvedValue({
running: false,
failure: { reason: "crashed", port: null },
}),
});
await expect(getEmbeddedServerFailure()).resolves.toEqual({
reason: "crashed",
port: null,
});
});
it("returns null when an older desktop build does not expose the status channel", async () => {
setElectronAPI({ isElectron: true });
await expect(getEmbeddedServerFailure()).resolves.toBeNull();
});
it("returns null rather than throwing when the IPC call itself fails", async () => {
setElectronAPI({
isElectron: true,
getEmbeddedServerStatus: vi.fn().mockRejectedValue(new Error("no ipc")),
});
await expect(getEmbeddedServerFailure()).resolves.toBeNull();
});
it("ignores a failure payload with an unrecognized reason", async () => {
setElectronAPI({
isElectron: true,
getEmbeddedServerStatus: vi.fn().mockResolvedValue({
running: false,
failure: { reason: "something-new", port: 30001 },
}),
});
await expect(getEmbeddedServerFailure()).resolves.toEqual({
reason: "crashed",
port: null,
});
});
});