--format=mocks (default)
Layout is <output>/<url path>/<METHOD>.json. Each file is the raw response body, nothing else: no headers, no status codes. This is the layout mocks-to-msw and mocks-to-playwright consume and connect-api-mocker (Express / webpack-dev-server middleware) serves.
Then do this
import { createMockHandler } from "mocks-to-msw";
import mocks from "./mocks/mocks";
const { mock } = createMockHandler<keyof typeof mocks>({ mocks, debug: true });
export const handlers = [
mock.get("/client"),
mock.post("/client/application", (data) => ({ ...data, modified: true })),
];
mocks-to-msw adds type-safe URL/method pairing, async loading, response modifiers, debug logging, origin configuration, and a CLI that generates a typed import file from the mocks folder.
Or in Playwright tests
import { createMockRoutes } from "mocks-to-playwright";
import mocks from "./mocks/mocks";
const { mock } = createMockRoutes<keyof typeof mocks>({ mocks });
test("shows the client", async ({ page }) => {
await mock.get("/client")(page);
await mock.post("/client/application", (data) => ({ ...data, status: "approved" }))(page);
await page.goto("/");
});
mocks-to-playwright serves the same mocks through page.route() with the same typed API, works on a page or a whole browser context, and reads the same generated mocks.ts.