mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-10-07 16:58:14 +08:00
* chore: remove unused utility functions * chore: Remove PR-only artifacts --------- Co-authored-by: allhands-bot <allhands-bot@users.noreply.github.com>
62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import posthog from "posthog-js";
|
|
import { trackError } from "#/utils/error-handler";
|
|
|
|
vi.mock("posthog-js", () => ({
|
|
default: {
|
|
captureException: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
describe("Error Handler", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe("trackError", () => {
|
|
it("should send error to PostHog with basic info", () => {
|
|
const error = {
|
|
message: "Test error",
|
|
source: "test",
|
|
posthog,
|
|
};
|
|
|
|
trackError(error);
|
|
|
|
expect(posthog.captureException).toHaveBeenCalledWith(
|
|
new Error("Test error"),
|
|
{
|
|
error_source: "test",
|
|
},
|
|
);
|
|
});
|
|
|
|
it("should include additional metadata in PostHog event", () => {
|
|
const error = {
|
|
message: "Test error",
|
|
source: "test",
|
|
metadata: {
|
|
extra: "info",
|
|
details: { foo: "bar" },
|
|
},
|
|
posthog,
|
|
};
|
|
|
|
trackError(error);
|
|
|
|
expect(posthog.captureException).toHaveBeenCalledWith(
|
|
new Error("Test error"),
|
|
{
|
|
error_source: "test",
|
|
extra: "info",
|
|
details: { foo: "bar" },
|
|
},
|
|
);
|
|
});
|
|
});
|
|
});
|