mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 17:02:17 +00: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.
36 lines
1.6 KiB
TypeScript
36 lines
1.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const logFrontend = vi.hoisted(() => vi.fn(() => Promise.resolve()));
|
|
vi.mock("@tauri-apps/api/webviewWindow", () => ({ getCurrentWebviewWindow: () => ({ label: "project-2" }) }));
|
|
vi.mock("./ipc", () => ({ isTauri: () => true, commands: { logFrontend } }));
|
|
|
|
import { describeError, installErrorLogging } from "./errorLog";
|
|
|
|
afterEach(() => logFrontend.mockClear());
|
|
|
|
describe("frontend errors in the log", () => {
|
|
it("writes uncaught errors and unhandled rejections once each, with the window", () => {
|
|
const off = installErrorLogging();
|
|
const boom = new Error("boom");
|
|
window.dispatchEvent(new ErrorEvent("error", { error: boom, message: "boom" }));
|
|
window.dispatchEvent(new ErrorEvent("error", { error: boom, message: "boom" }));
|
|
const rejection = new Event("unhandledrejection") as PromiseRejectionEvent;
|
|
Object.assign(rejection, { reason: "no project" });
|
|
window.dispatchEvent(rejection);
|
|
off();
|
|
const late = new Event("unhandledrejection") as PromiseRejectionEvent;
|
|
Object.assign(late, { reason: "after" });
|
|
window.dispatchEvent(late);
|
|
expect(logFrontend.mock.calls.map((c) => c as unknown[])).toEqual([
|
|
["error", expect.stringMatching(/^\[project-2\] uncaught error: Error: boom\n\s+at /)],
|
|
["error", "[project-2] unhandled rejection: no project"],
|
|
]);
|
|
});
|
|
|
|
it("describes errors, strings and other values", () => {
|
|
expect(describeError("x")).toBe("x");
|
|
expect(describeError({ kind: "notFound" })).toBe('{"kind":"notFound"}');
|
|
expect(describeError(undefined)).toBe("undefined");
|
|
});
|
|
});
|