26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createLogger } from "../src/index.js";
|
|
import { createSentrySink } from "../src/sentry.js";
|
|
|
|
describe("createSentrySink", () => {
|
|
it("captures errors with namespace and structured context, but ignores warnings", () => {
|
|
const scope = { setLevel: vi.fn(), setTag: vi.fn(), setExtras: vi.fn() };
|
|
const sentry = {
|
|
withScope: (callback: (value: typeof scope) => void) => callback(scope),
|
|
captureException: vi.fn(),
|
|
captureMessage: vi.fn(),
|
|
};
|
|
const logger = createLogger({
|
|
environment: "production",
|
|
namespace: "API",
|
|
sinks: [createSentrySink(sentry)],
|
|
});
|
|
const error = new Error("offline");
|
|
logger.warn("ignored");
|
|
logger.error("Request failed", error, { requestId: "req_1" });
|
|
expect(sentry.captureException).toHaveBeenCalledWith(error);
|
|
expect(scope.setTag).toHaveBeenCalledWith("logger.namespace", "API");
|
|
expect(scope.setExtras).toHaveBeenCalledWith({ context_0: { requestId: "req_1" } });
|
|
});
|
|
});
|