Skip to content

Commit 5f1b404

Browse files
authored
docs: update for detail description (#103)
1 parent 501a6f6 commit 5f1b404

File tree

2 files changed

+345
-22
lines changed

2 files changed

+345
-22
lines changed

README.md

Lines changed: 215 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,220 @@
1-
# Greeting
2-
- Thx for using this package:`msw-dev-tool`!
3-
- This allows you more flexible and extensive API mocking with UI.
4-
- This package is based on [msw](https://mswjs.io/) and [zustand](https://zustand.docs.pmnd.rs/).
1+
# MSW Dev Tool
52

6-
# Docs
7-
- [link](https://msw-dev-tool-docs.vercel.app/)
3+
A powerful development tool to control mock logic, modify responses, and monitor API calls with [MSW (Mock Service Worker)](https://mswjs.io/).
84

9-
# Structure
5+
## 📚 Documentation
6+
7+
For complete documentation, guides, and examples, visit our official documentation site:
8+
9+
**👉 [https://msw-dev-tool-docs.vercel.app/](https://msw-dev-tool-docs.vercel.app/)**
10+
11+
### Quick Links
12+
13+
- [Getting Started](https://msw-dev-tool-docs.vercel.app/docs/get-started) - Installation and setup guide
14+
- [Tools](https://msw-dev-tool-docs.vercel.app/docs/tools) - Overview of available tools
15+
- [Handler Table](https://msw-dev-tool-docs.vercel.app/docs/handler-table) - Manage your handlers
16+
- [Debugger](https://msw-dev-tool-docs.vercel.app/docs/debugger) - Test and debug handlers
17+
- [Custom Trigger](https://msw-dev-tool-docs.vercel.app/docs/custom-trigger) - Customize the UI trigger
18+
- [Playground](https://msw-dev-tool-docs.vercel.app/docs/playground) - Interactive examples
19+
- [Temp Handler](https://msw-dev-tool-docs.vercel.app/docs/temp-handler) - Add temporary handlers
20+
- [Roadmap](https://msw-dev-tool-docs.vercel.app/docs/roadmap) - Future plans and features
21+
22+
## What Problem Does This Solve?
23+
24+
When developing frontend applications with MSW, developers often face the following challenges:
25+
26+
- **Code modification required**: To change mock responses or test different scenarios, you need to modify handler code and restart the development server
27+
- **No runtime control**: There's no way to dynamically control mock behavior during development
28+
- **Limited visibility**: It's difficult to see which handlers are active and monitor API calls in real-time
29+
- **Testing overhead**: Testing different response scenarios requires writing multiple handlers or conditional logic
30+
31+
**MSW Dev Tool** solves these problems by providing a **visual UI** that allows you to:
32+
33+
- Control mock handlers at runtime without code changes
34+
- Modify response behaviors (delay, errors, disable mocks) on the fly
35+
- Monitor all API calls and their handlers
36+
- Test different scenarios instantly during development
37+
38+
## Key Features
39+
40+
### 🎛️ Handler Table
41+
42+
View and manage all your MSW handlers in a comprehensive table interface. Enable, disable, or modify handlers without touching your code.
43+
44+
### 🐛 Debugger
45+
46+
Test and debug your handlers with an interactive debugger. Send requests, inspect responses, and verify handler logic in real-time.
47+
48+
### ⚡ Response Behavior Control
49+
50+
Dynamically control response behaviors:
51+
52+
- **Delay**: Simulate network latency
53+
- **Error**: Trigger error responses
54+
- **Disable Mock**: Bypass specific handlers
55+
- **Custom Logic**: Modify responses on the fly
56+
57+
### 🎨 Customizable UI
58+
59+
Fully customizable trigger UI that can be integrated seamlessly into your application's design.
60+
61+
### 🧪 Temp Handler
62+
63+
Quickly add temporary handlers for testing specific scenarios without modifying your existing handler setup.
64+
65+
### 📊 API Call Monitoring
66+
67+
Monitor all API calls made by your application and see which handlers are intercepting them.
68+
69+
## Installation
70+
71+
### New Package Structure (Recommended)
72+
73+
We recommend using the new modular package structure with `@msw-dev-tool/core` and `@msw-dev-tool/react`:
74+
75+
```bash
76+
# Using pnpm
77+
pnpm add -D @msw-dev-tool/core @msw-dev-tool/react
78+
79+
# Using npm
80+
npm i @msw-dev-tool/core @msw-dev-tool/react --save-dev
81+
82+
# Using yarn
83+
yarn add @msw-dev-tool/core @msw-dev-tool/react --dev
84+
```
85+
86+
### Legacy Package
87+
88+
The `msw-dev-tool` package is now **legacy** and will be deprecated in the future. However, it is still **stable** and fully supported. For new projects, please use the new package structure above.
89+
90+
```bash
91+
# Using pnpm
92+
pnpm add -D msw-dev-tool
93+
94+
# Using npm
95+
npm i msw-dev-tool --save-dev
96+
97+
# Using yarn
98+
yarn add msw-dev-tool --dev
99+
```
100+
101+
For detailed installation and setup instructions, see the [Getting Started Guide](https://msw-dev-tool-docs.vercel.app/docs/get-started).
102+
103+
## Quick Start
104+
105+
### Using New Package Structure
106+
107+
1. **Replace MSW's `setupWorker` with `setupDevToolWorker`:**
108+
109+
```typescript
110+
import { setupDevToolWorker } from "@msw-dev-tool/core";
111+
112+
export const worker = setupDevToolWorker(...handlers);
113+
```
114+
115+
2. **Add the DevTool UI component:**
116+
117+
```tsx
118+
import { MSWDevTool } from "@msw-dev-tool/react";
119+
import "@msw-dev-tool/react/msw-dev-tool.css";
120+
121+
export default function App() {
122+
return (
123+
<>
124+
{/* Your app components */}
125+
<MSWDevTool />
126+
</>
127+
);
128+
}
129+
```
130+
131+
### Using Legacy Package
132+
133+
1. **Replace MSW's `setupWorker` with `setupDevToolWorker`:**
134+
135+
```typescript
136+
import { setupDevToolWorker } from "msw-dev-tool";
137+
138+
export const worker = setupDevToolWorker(...handlers);
139+
```
140+
141+
2. **Add the DevTool UI component:**
142+
143+
```tsx
144+
import { MSWDevTool } from "msw-dev-tool";
145+
import "msw-dev-tool/msw-dev-tool.css";
146+
147+
export default function App() {
148+
return (
149+
<>
150+
{/* Your app components */}
151+
<MSWDevTool />
152+
</>
153+
);
154+
}
155+
```
156+
157+
## Internal Architecture
158+
159+
This project is built on top of two core technologies:
160+
161+
- **[MSW](https://mswjs.io/)**: The foundation for API mocking using Service Workers
162+
- **[Zustand](https://zustand.docs.pmnd.rs/)**: State management for the dev tool UI and handler control
163+
164+
### System Overview
165+
166+
The library consists of two main parts:
167+
168+
1. **Core Logic** (`@msw-dev-tool/core`):
169+
- Wraps MSW's `setupWorker` with `setupDevToolWorker`
170+
- Manages handler state and behavior modifications
171+
- Provides APIs for runtime handler control
172+
- Uses Zustand for state management
173+
174+
2. **React UI** (`@msw-dev-tool/react`):
175+
- React components for the dev tool interface
176+
- Handler table, debugger, and other UI features
177+
- Communicates with core logic through Zustand store
178+
- Depends on `@msw-dev-tool/core` as a peer dependency
179+
180+
### How It Works
181+
182+
1. **Worker Integration**: `setupDevToolWorker` wraps MSW's worker and adds additional capabilities for runtime control
183+
2. **State Management**: Zustand store maintains the state of all handlers, their behaviors, and API call history
184+
3. **Runtime Control**: The UI components interact with the Zustand store to modify handler behaviors, which are then applied to the MSW worker
185+
4. **API Monitoring**: Intercepts and logs all API calls made through MSW handlers
186+
187+
## Project Structure
10188

11189
This project uses pnpm workspaces.
12190

13-
| Project | Description |
14-
| ---------------- | ----------------------------------------------------------------------------------------------------- |
15-
| **docs** | The documentation of the library.
16-
| **core** | `@msw-dev-tool/core`: Core lib logic to control msw handlers |
17-
| **react** | `@msw-dev-tool/lib`: Implement of react UI |
18-
| **example** | A sample project to develop and test `msw-dev-tool`. You need to build `msw-dev-tool` before testing. |
19-
| **msw-dev-tool** | The **LEGACY** source code of the library. |
20-
|
191+
| Project | Description |
192+
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
193+
| **docs** | The documentation of the library. |
194+
| **core** | `@msw-dev-tool/core`: Core library logic to control MSW handlers |
195+
| **react** | `@msw-dev-tool/react`: React UI implementation |
196+
| **example** | A sample project to develop and test `msw-dev-tool`. You need to build `msw-dev-tool` before testing. |
197+
| **msw-dev-tool** | The **LEGACY** source code of the library. This package will be deprecated in favor of the new modular structure (`@msw-dev-tool/core` + `@msw-dev-tool/react`). |
198+
199+
## Documentation
200+
201+
For complete documentation, visit: [https://msw-dev-tool-docs.vercel.app/](https://msw-dev-tool-docs.vercel.app/)
202+
203+
Key documentation pages:
204+
205+
- [Getting Started](https://msw-dev-tool-docs.vercel.app/docs/get-started)
206+
- [Tools](https://msw-dev-tool-docs.vercel.app/docs/tools)
207+
- [Handler Table](https://msw-dev-tool-docs.vercel.app/docs/handler-table)
208+
- [Debugger](https://msw-dev-tool-docs.vercel.app/docs/debugger)
209+
- [Custom Trigger](https://msw-dev-tool-docs.vercel.app/docs/custom-trigger)
210+
- [Playground](https://msw-dev-tool-docs.vercel.app/docs/playground)
211+
- [Temp Handler](https://msw-dev-tool-docs.vercel.app/docs/temp-handler)
212+
- [Roadmap](https://msw-dev-tool-docs.vercel.app/docs/roadmap)
213+
214+
## Contributing
215+
216+
We welcome contributions! Please feel free to submit a Pull Request.
217+
218+
## License
219+
220+
This project is open source and available under the MIT License.

0 commit comments

Comments
 (0)