дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 19:25:54 +02:00
The native Settings window showed only its title bar until its startup chain finished; a page that failed to register ended the chain silently. The steps are now guarded and openSettings runs in finally. Uncaught errors and unhandled rejections of every window (and caught errors via logError) are written to the log file through log_frontend, deduplicated and capped per window.
49 рядки
1.6 KiB
TypeScript
49 рядки
1.6 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
const logFrontend = vi.hoisted(() => vi.fn(() => Promise.resolve()));
|
|
vi.mock("@tauri-apps/api/webviewWindow", () => ({
|
|
getCurrentWebviewWindow: () => ({
|
|
label: "settings-main",
|
|
listen: () => Promise.resolve(() => {}),
|
|
close: () => Promise.resolve(),
|
|
setTitle: () => Promise.resolve(),
|
|
}),
|
|
}));
|
|
vi.mock("@/platform/ipc", async (importOriginal) => {
|
|
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
|
const ok = (data: unknown) => Promise.resolve({ status: "ok", data });
|
|
return {
|
|
...real,
|
|
isTauri: () => true,
|
|
commands: {
|
|
...real.commands,
|
|
logFrontend,
|
|
remoteCurrent: () => ok(null),
|
|
projectCurrent: () => ok(null),
|
|
settingsGetGlobal: () => ok({}),
|
|
windowTakeLaunch: () => Promise.resolve(null),
|
|
},
|
|
};
|
|
});
|
|
vi.mock("../dialog/LazySettingsDialog", () => ({
|
|
LazySettingsDialog: () => null,
|
|
loadBuiltinPages: () => Promise.reject(new Error("page failed")),
|
|
unloadBuiltinPages: () => {},
|
|
}));
|
|
|
|
const { activateSettingsWindow } = await import("..");
|
|
const { useSettingsDialog } = await import("../model/staging");
|
|
|
|
describe("the native Settings window", () => {
|
|
it("opens even when a page fails to register, and logs why", async () => {
|
|
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
const dispose = activateSettingsWindow("main");
|
|
await vi.waitFor(() => expect(useSettingsDialog.getState().open).toBe(true));
|
|
expect(logFrontend).toHaveBeenCalledWith(
|
|
"error",
|
|
expect.stringContaining("cannot register settings pages: Error: page failed"),
|
|
);
|
|
dispose();
|
|
});
|
|
});
|