Skip to content

Commit b1e3586

Browse files
committed
Merge branch 'fix/v1.0.2'
2 parents 1d3ef70 + 3633573 commit b1e3586

File tree

12 files changed

+216
-163
lines changed

12 files changed

+216
-163
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11

2+
## v1.0.2
3+
[compare changes](https://github.com/shunnNet/nuxt-msw/compare/v1.0.1...v1.0.2)
4+
5+
### 🩹 Fixes
6+
- Lost type infos when `msw.enable: false`([e2bc95b](https://github.com/shunnNet/nuxt-msw/commit/e2bc95b))
7+
- Related to: [issues/2](https://github.com/shunnNet/nuxt-msw/issues/2).
8+
- In previous versions, when `enable: false`, the auto imports provided by `nuxt-msw` would lose type information. This could hinder type checking and potentially cause unnecessary confusion for developers. Therefore, in this update, the auto imports will be retained even when `enable: false` to avoid these issues.
9+
10+
### 🏡 Chore
11+
- Move `ofetch` and `unimport` to dev deps ([0eab2b8](https://github.com/shunnNet/nuxt-msw/commit/0eab2b8))
12+
13+
### ❤️ Contributors
14+
15+
- Net <wendell20904102@gmail.com>
16+
217
## v1.0.1
318

419
## doc

README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# 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+
[![npm version](https://img.shields.io/npm/v/@crazydos/nuxt-msw.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/@crazydos/nuxt-msw)
3+
[![npm downloads](https://img.shields.io/npm/dm/@crazydos/nuxt-msw.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/@crazydos/nuxt-msw)
4+
[![License](https://img.shields.io/github/license/nuxt/nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://github.com/shunnNet/nuxt-msw/blob/main/LICENSE)
65

76
`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.
87

98

10-
- [&nbsp;Release Notes](/CHANGELOG.md)
9+
[✨ Release Notes](/CHANGELOG.md)
1110
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/nuxt-msw?file=playground%2Fapp.vue) -->
1211
<!-- - [📖 &nbsp;Documentation](https://example.com) -->
1312

1413
- [nuxt-msw](#nuxt-msw)
1514
- [Features](#features)
15+
- [Online Playground](#online-playground)
1616
- [Migrate: `0.x` -\> `1.x` users](#migrate-0x---1x-users)
1717
- [Setup](#setup)
1818
- [Usage](#usage)
@@ -38,6 +38,12 @@
3838
- ⛰ Intercept both server-side and client-side request, including `$fetch`, `useFetch` and any other api requests.
3939
- 🥧 Support Nuxt layer.
4040

41+
## Online Playground
42+
You can try out the functionality of `nuxt-msw` online through the following website.
43+
44+
[![Play in Codesandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/devbox/3jdr8d?embed=1)
45+
<!-- [![Play in Stackblitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/nuxt-starter-ex6po1?file=app.vue) -->
46+
4147
## Migrate: `0.x` -> `1.x` users
4248
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.
4349

@@ -216,27 +222,38 @@ export default defineNuxtConfig({
216222
msw: {
217223
/**
218224
* 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+
* }
219236
*/
220-
enable: true,
237+
enable: true, // default: true
221238
/**
222239
* Path to the nuxt-msw runtime folder that include worker and server files.
223-
* default: `~/msw`
240+
* @default "~/msw"
224241
*/
225242
folderPath: "~/msw"
226-
227243
/**
228244
* Should include nuxt layers msw settings or not
229-
* default: true
245+
* @default true
230246
*/
231247
includeLayer?: boolean
232-
233248
/**
234249
*
235250
* Enable unit test mode. default: false
236251
*
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).
238253
*
239-
* Which means msw server will be used in this mode.
254+
* When enable: false, this mode is inactive.
255+
*
256+
* @default true
240257
*/
241258
testUtils?: boolean
242259
},
@@ -369,7 +386,8 @@ await setupNuxtMswServer({
369386
})
370387
```
371388

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.
373391
374392

375393
#### E2E Tests

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@crazydos/nuxt-msw",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Nuxt module integration for MSW (Mock Service Worker)",
55
"author": {
66
"name": "shunnNet",
@@ -42,9 +42,7 @@
4242
"test:pl": "playwright test"
4343
},
4444
"dependencies": {
45-
"@nuxt/kit": "^3.11.2",
46-
"ofetch": "^1.3.4",
47-
"unimport": "^3.7.1"
45+
"@nuxt/kit": "^3.11.2"
4846
},
4947
"peerDependencies": {
5048
"msw": "^2.x"
@@ -67,7 +65,9 @@
6765
"typescript": "latest",
6866
"vitest": "^1.6.0",
6967
"vitest-environment-nuxt": "^1.0.1",
70-
"vue-tsc": "^2.0.16"
68+
"vue-tsc": "^2.0.16",
69+
"ofetch": "^1.3.4",
70+
"unimport": "^3.7.1"
7171
},
7272
"msw": {
7373
"workerDirectory": [

playground/layers/test-layer/msw/server.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ export default defineNuxtMswServerOption(() => {
44
const baseURL = useRuntimeConfig().public.msw?.baseURL
55
const handlers = [
66
// Intercept "GET https://example.com/user" requests...
7-
// http.get(baseURL + '/api/user', () => {
8-
// // ...and respond to them using this JSON response.
9-
// return HttpResponse.json({
10-
// id: 'Mock03 layer',
11-
// firstName: 'Mock layer',
12-
// lastName: 'User layer',
13-
// })
14-
// }),
7+
http.get(baseURL + '/api/user', () => {
8+
// ...and respond to them using this JSON response.
9+
return HttpResponse.json({
10+
id: 'Mock03 layer',
11+
firstName: 'Mock layer',
12+
lastName: 'User layer',
13+
})
14+
}),
1515
]
1616
return {
17-
// baseURL,
17+
baseURL,
1818
handlers,
1919
serverOptions: {
2020
onUnhandledRequest: 'bypass',

playground/msw/server.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { http, HttpResponse } from 'msw'
33
const baseURL = useRuntimeConfig().public.msw?.baseURL
44
const handlers = [
55
// Intercept "GET https://example.com/user" requests...
6-
// http.get(baseURL + '/api/user', () => {
7-
// // ...and respond to them using this JSON response.
8-
// return HttpResponse.json({
9-
// id: 'Mock03',
10-
// firstName: 'Mock2',
11-
// lastName: 'User',
12-
// })
13-
// }),
6+
http.get(baseURL + '/api/user', () => {
7+
// ...and respond to them using this JSON response.
8+
return HttpResponse.json({
9+
id: 'Mock03',
10+
firstName: 'Mock2',
11+
lastName: 'User',
12+
})
13+
}),
1414
]
1515
export default defineNuxtMswServerOption({
1616
baseURL,

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ConfigOptions } from '@nuxt/test-utils/playwright'
55
export default defineConfig<ConfigOptions>({
66
use: {
77
nuxt: {
8-
// rootDir: fileURLToPath(new URL('./test/fixtures/basic', import.meta.url)),
8+
rootDir: fileURLToPath(new URL('./test/fixtures/basic', import.meta.url)),
99
},
1010
headless: false,
1111
channel: 'chrome',

0 commit comments

Comments
 (0)