You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the sake of the question, let me set a simplified context: I have a monorepo setup (pnpm + Turborepo) with a React app built with Webpack and an API "adapter" package built with Vite. Both the app and package are written in Typescript.
.
└── monorepo/
├── apps/
│ └── react-app-built-with-webpack/
│ └── src/
│ └── **.test.tsx (attempting to use MSW worker here)
└── packages/
└── api-controller-package/
├── adapters/ (class/objects with methods that make HTTP requests to the back-end)
├── schemas/ (schemas + types in Zod)
└── mocks/ (mocks defined manually with Zod schema and MSW worker + server export using Zod mocks in handlers)
The "adapter" package is built as a library with full typescript support but outputs to js, cjs, and esm, as well as types.
Because this package is where the adapters to communicate between all the front-end apps and the back-end is going to go, this is also a good place to put the schemas and associated types for back-end data models. Turns out, it also could be a great place for MSW. I can setup all the handlers for the various back-end APIs I talk to and leverage the mocks I've already written. Then I can export the configured worker and node server from MSW from this package.
I'm attempting to consume the MSW service worker in a front-end app where Jest tests are housed (with Testing Library) but it doesn't quite work.
My question for the community here is: what are some best practices to do something like this? Have a package in your monorepo export the MSW instances from a single place that the applications in your monorepo can consume?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
For the sake of the question, let me set a simplified context: I have a monorepo setup (pnpm + Turborepo) with a React app built with Webpack and an API "adapter" package built with Vite. Both the app and package are written in Typescript.
The "adapter" package is built as a library with full typescript support but outputs to js, cjs, and esm, as well as types.
Because this package is where the adapters to communicate between all the front-end apps and the back-end is going to go, this is also a good place to put the schemas and associated types for back-end data models. Turns out, it also could be a great place for MSW. I can setup all the handlers for the various back-end APIs I talk to and leverage the mocks I've already written. Then I can export the configured worker and node server from MSW from this package.
I'm attempting to consume the MSW service worker in a front-end app where Jest tests are housed (with Testing Library) but it doesn't quite work.
My question for the community here is: what are some best practices to do something like this? Have a package in your monorepo export the MSW instances from a single place that the applications in your monorepo can consume?
Beta Was this translation helpful? Give feedback.
All reactions