import { expect, test, vi } from "vitest" import { normalizeBrowserExceptionRecord, normalizeExceptionRecord, normalizeNodejsExceptionRecord, } from "#Source/exception/index.ts" test("normalizeExceptionRecord infers message and timestamp", () => { vi.spyOn(Date, "now").mockReturnValue(123) const example1 = normalizeExceptionRecord({ runtime: "unknown", source: "custom", exception: new Error("boom"), }) const example2 = normalizeExceptionRecord({ runtime: "unknown", source: "custom", exception: "text-error", }) expect(example1.message).toBe("boom") expect(example1.timestamp).toBe(123) expect(example2.message).toBe("text-error") }) test("normalizeBrowserExceptionRecord preserves browser-specific fields", () => { const example1 = normalizeBrowserExceptionRecord({ source: "browser.global-error", exception: new Error("boom"), filename: "app.ts", lineno: 8, colno: 13, timestamp: 10, }) expect(example1.runtime).toBe("browser") expect(example1.filename).toBe("app.ts") expect(example1.lineno).toBe(8) expect(example1.colno).toBe(13) }) test("normalizeNodejsExceptionRecord preserves nodejs-specific fields", () => { const promise = Promise.resolve("ok") const example1 = normalizeNodejsExceptionRecord({ source: "nodejs.unhandled-rejection", exception: new Error("boom"), origin: "unhandledRejection", promise, timestamp: 11, }) expect(example1.runtime).toBe("nodejs") expect(example1.origin).toBe("unhandledRejection") expect(example1.promise).toBe(promise) })