Adds initSentryServerNode + initSentryClientReact to core-shared (Vite/non-Next variants of the existing init helpers — same R31/R32/R33 posture, R34/R35/R37 replay defaults). Extends no-sentry.ts to mock @sentry/node + @sentry/react. Wires the web-tanstack server/client instrumentation entry hooks and adds the R38 PII test. Spec deviation: web-tanstack has no vite.config.ts yet (placeholder app per its package.json). The @sentry/vite-plugin dep is added but unused until the TanStack Start build is wired in a later plan. A minimal src/vite-env.d.ts shims ImportMetaEnv for the client entry until the full Vite types land. @sentry/node and @sentry/react are added to core-shared as optional peerDependencies so feature packages don't transitively pull them in; they're also devDependencies of core-shared for typecheck/test runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
// packages/core-shared/src/instrumentation/sentry/init-server-node.test.ts
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
vi.mock("@sentry/node", () => ({
|
|
init: vi.fn(),
|
|
}));
|
|
|
|
import * as SentryNode from "@sentry/node";
|
|
import { initSentryServerNode } from "@/instrumentation/sentry/init-server-node";
|
|
|
|
describe("initSentryServerNode", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("calls SentryNode.init with sendDefaultPii: false (R31)", () => {
|
|
initSentryServerNode({ dsn: "https://x@y/1", app: "web-tanstack" });
|
|
const call = (SentryNode.init as ReturnType<typeof vi.fn>).mock.calls[0]![0] as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(call["sendDefaultPii"]).toBe(false);
|
|
});
|
|
|
|
it("attaches beforeSend + beforeSendTransaction scrubbers", () => {
|
|
initSentryServerNode({ dsn: "https://x@y/1", app: "web-tanstack" });
|
|
const call = (SentryNode.init as ReturnType<typeof vi.fn>).mock.calls[0]![0] as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(typeof call["beforeSend"]).toBe("function");
|
|
expect(typeof call["beforeSendTransaction"]).toBe("function");
|
|
});
|
|
|
|
it("tags events with the app name", () => {
|
|
initSentryServerNode({ dsn: "https://x@y/1", app: "web-tanstack" });
|
|
const call = (SentryNode.init as ReturnType<typeof vi.fn>).mock.calls[0]![0] as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
const initialScope = call["initialScope"] as { tags?: Record<string, string> };
|
|
expect(initialScope?.tags?.["app"]).toBe("web-tanstack");
|
|
});
|
|
|
|
it("is a no-op when dsn is missing", () => {
|
|
initSentryServerNode({ dsn: "", app: "web-tanstack" });
|
|
expect(SentryNode.init).not.toHaveBeenCalled();
|
|
initSentryServerNode({ dsn: undefined as unknown as string, app: "web-tanstack" });
|
|
expect(SentryNode.init).not.toHaveBeenCalled();
|
|
});
|
|
});
|