// Mock composition root. Imported by `mocks/node.ts`, `mocks/browser.tsx`, // and the vitest setup file — same handlers, three environments. // // To enable per-vendor canonical mocks, install the corresponding // `@raredays/*` packages (already in your deps if you selected the module) // and uncomment the relevant import + spread below. // // Per-app handlers go in the trailing array; later handlers win on equal // URL specificity, so app-specific overrides should come after vendor sets. import { defineMocks, type RequestHandler } from "@raredays/mocks"; import { http, HttpResponse } from "msw"; // CRDA:mocks-imports // Explicit annotation — TS2742 otherwise points at MSW's internal // HttpResponse-*.mjs path which isn't portable across consumer apps. export const handlers: RequestHandler[] = defineMocks( // CRDA:mocks-spread [ // App-local handlers — the demo at /demo/widgets calls /api/widgets, // which by default returns []. With MOCKS on, MSW intercepts here and // returns canned data so you can design UI against realistic responses. http.get("/api/widgets", () => HttpResponse.json({ widgets: [ { id: "w_1", name: "Mock Widget A", inventory: 12 }, { id: "w_2", name: "Mock Widget B", inventory: 7 }, { id: "w_3", name: "Mock Widget C", inventory: 0 }, ], total: 3, }), ), ], );