| 
1 | 1 | # nuxt-msw  | 
2 |  | -<!-- [![npm version][npm-version-src]][npm-version-href]  | 
3 |  | -[![npm downloads][npm-downloads-src]][npm-downloads-href]  | 
4 |  | -[![License][license-src]][license-href]  | 
5 |  | -[![Nuxt][nuxt-src]][nuxt-href] -->  | 
 | 2 | +[](https://www.npmjs.com/package/@crazydos/nuxt-msw)  | 
 | 3 | +[](https://www.npmjs.com/package/@crazydos/nuxt-msw)  | 
 | 4 | +[](https://github.com/shunnNet/nuxt-msw/blob/main/LICENSE)  | 
6 | 5 | 
 
  | 
7 | 6 | `nuxt-msw` integrates [MSW (Mock Service Worker)](https://mswjs.io/) into a Nuxt project, allowing you to use it for API mocking during development. Most of the code can be directly shared with test mocks.   | 
8 | 7 | 
 
  | 
9 | 8 | 
 
  | 
10 |  | -- [✨  Release Notes](/CHANGELOG.md)  | 
 | 9 | +[✨ Release Notes](/CHANGELOG.md)  | 
11 | 10 | <!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/nuxt-msw?file=playground%2Fapp.vue) -->  | 
12 | 11 | <!-- - [📖  Documentation](https://example.com) -->  | 
13 | 12 | 
 
  | 
14 | 13 | - [nuxt-msw](#nuxt-msw)  | 
15 | 14 |   - [Features](#features)  | 
 | 15 | +  - [Online Playground](#online-playground)  | 
16 | 16 |   - [Migrate: `0.x` -\> `1.x` users](#migrate-0x---1x-users)  | 
17 | 17 |   - [Setup](#setup)  | 
18 | 18 |   - [Usage](#usage)  | 
 | 
38 | 38 | - ⛰ Intercept both server-side and client-side request, including `$fetch`, `useFetch` and any other api requests.  | 
39 | 39 | - 🥧 Support Nuxt layer.  | 
40 | 40 | 
 
  | 
 | 41 | +## Online Playground  | 
 | 42 | +You can try out the functionality of `nuxt-msw` online through the following website.  | 
 | 43 | + | 
 | 44 | +[](https://codesandbox.io/p/devbox/3jdr8d?embed=1)  | 
 | 45 | +<!-- [](https://stackblitz.com/edit/nuxt-starter-ex6po1?file=app.vue) -->  | 
 | 46 | + | 
41 | 47 | ## Migrate: `0.x` -> `1.x` users  | 
42 | 48 | Thank you to all the users of version 0.x. I believe you won’t need to put in too much effort to upgrade to version 1.x.  | 
43 | 49 | 
 
  | 
@@ -216,27 +222,38 @@ export default defineNuxtConfig({  | 
216 | 222 |   msw: {  | 
217 | 223 |     /**  | 
218 | 224 |      * Whether to enable the module. Default to `true`  | 
 | 225 | +     *   | 
 | 226 | +     * This is useful when you need to enable or disable msw based on the environment.  | 
 | 227 | +     *   | 
 | 228 | +     * When `enable: false`, the msw worker and server will not try to intercept requests, but keeps auto import composables for type checking.  | 
 | 229 | +     *   | 
 | 230 | +     * @default true  | 
 | 231 | +     *   | 
 | 232 | +     * @example  | 
 | 233 | +     * {  | 
 | 234 | +     *   enable: process.env.TEST === 'true'  | 
 | 235 | +     * }  | 
219 | 236 |      */  | 
220 |  | -    enable: true,  | 
 | 237 | +    enable: true, // default: true  | 
221 | 238 |      /**  | 
222 | 239 |       * Path to the nuxt-msw runtime folder that include worker and server files.  | 
223 |  | -      * default: `~/msw`  | 
 | 240 | +      * @default "~/msw"  | 
224 | 241 |       */   | 
225 | 242 |     folderPath: "~/msw"  | 
226 |  | -      | 
227 | 243 |     /**  | 
228 | 244 |      * Should include nuxt layers msw settings or not  | 
229 |  | -     * default: true  | 
 | 245 | +     * @default true  | 
230 | 246 |      */  | 
231 | 247 |     includeLayer?: boolean  | 
232 |  | -      | 
233 | 248 |     /**  | 
234 | 249 |      *  | 
235 | 250 |      * Enable unit test mode. default: false  | 
236 | 251 |      *  | 
237 |  | -     * In unit test mode, the module run <folderPath>/unit.{ts,js,mjs,cjs} file which run in nodejs environment.  | 
 | 252 | +     * When this mode is enabled, you can use `setupNuxtMswServer` to start the msw server in a unit test environment (which is a Node.js environment).  | 
238 | 253 |      *  | 
239 |  | -     * Which means msw server will be used in this mode.  | 
 | 254 | +     *  When enable: false, this mode is inactive.  | 
 | 255 | +     *   | 
 | 256 | +     * @default true  | 
240 | 257 |      */  | 
241 | 258 |     testUtils?: boolean  | 
242 | 259 |   },  | 
@@ -369,7 +386,8 @@ await setupNuxtMswServer({  | 
369 | 386 | })  | 
370 | 387 | ```  | 
371 | 388 | 
 
  | 
372 |  | -> [!NOTE] `baseURL` here is just a valid domain, it is not necessary to match nuxt server address. But if you run a real server and want msw fallback to there, you need to set baseURL to the real server address.    | 
 | 389 | +> [!NOTE]   | 
 | 390 | +> `baseURL` here is just a valid domain, it is not necessary to match nuxt server address. But if you run a real server and want msw fallback to there, you need to set baseURL to the real server address.    | 
373 | 391 | 
  | 
374 | 392 | 
 
  | 
375 | 393 | #### E2E Tests  | 
 | 
0 commit comments