@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
||||
// Start has no `onRequestError`: the loaders and the server entry report what they leave unhandled, and a
|
||||
// redirect or a not-found the app raised on purpose is control flow.
|
||||
|
||||
import { notFound, redirect } from "@tanstack/react-router"
|
||||
import { afterEach, describe, expect, it, vi } from "vitest"
|
||||
|
||||
const mocks = vi.hoisted(() => ({ current: undefined as unknown }))
|
||||
vi.mock("@app/config", () => ({ currentObservability: () => mocks.current }))
|
||||
|
||||
const { reportFailure } = await import("../apps/web/src/server/report")
|
||||
|
||||
const context = { routePath: "/$org", routeType: "loader" }
|
||||
const observer = () => ({
|
||||
captureException: vi.fn(),
|
||||
log: { error: vi.fn(), warn: vi.fn(), info: vi.fn(), debug: vi.fn() },
|
||||
})
|
||||
const request = new Request("http://app.test/acme/notes?x=1", { headers: { traceparent: "t" } })
|
||||
|
||||
afterEach(() => {
|
||||
mocks.current = undefined
|
||||
})
|
||||
|
||||
describe("a failed request's report", () => {
|
||||
it("reports a fault with the route, and says nothing of a redirect or a not-found", () => {
|
||||
const observe = observer()
|
||||
mocks.current = observe
|
||||
|
||||
reportFailure(notFound(), request, context)
|
||||
reportFailure(redirect({ href: "/" }), request, context)
|
||||
expect(observe.captureException).not.toHaveBeenCalled()
|
||||
|
||||
const fault = new Error("fault")
|
||||
reportFailure(fault, request, context)
|
||||
expect(observe.captureException).toHaveBeenCalledWith(fault, { route: "/$org", kind: "loader" })
|
||||
expect(observe.log.error).toHaveBeenCalledOnce()
|
||||
expect(observe.log.error.mock.calls[0]?.[1]).toMatchObject({ "url.path": "/acme/notes" })
|
||||
})
|
||||
|
||||
it("does nothing in a process that started no observability", () => {
|
||||
expect(() => reportFailure(new Error("fault"), request, context)).not.toThrow()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user