mockaton 7.6.1 → 7.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ _Reset_ button is for registering newly added, removed, or renamed mocks.
|
|
|
51
51
|
## Alternatives
|
|
52
52
|
- Chrome DevTools allows for [overriding responses](https://developer.chrome.com/docs/devtools/overrides)
|
|
53
53
|
- Reverse Proxies such as [Burp](https://portswigger.net/burp) are also handy for overriding responses.
|
|
54
|
-
-
|
|
54
|
+
- [Mock Server Worker](https://mswjs.io)
|
|
55
55
|
|
|
56
56
|
### Caveats
|
|
57
57
|
- Syncing the mocks, but the browser extension mentioned above helps.
|
|
@@ -84,11 +84,11 @@ interface Config {
|
|
|
84
84
|
mocksDir: string
|
|
85
85
|
ignore?: RegExp // Defaults to /(\.DS_Store|~)$/
|
|
86
86
|
|
|
87
|
-
staticDir?: string
|
|
87
|
+
staticDir?: string
|
|
88
88
|
|
|
89
89
|
host?: string, // Defaults to 'localhost'
|
|
90
90
|
port?: number // Defaults to 0, which means auto-assigned
|
|
91
|
-
proxyFallback?: string //
|
|
91
|
+
proxyFallback?: string // Target for relaying routes without mocks
|
|
92
92
|
|
|
93
93
|
delay?: number // Defaults to 1200 (ms)
|
|
94
94
|
cookies?: { [label: string]: string }
|
|
@@ -150,14 +150,20 @@ export default function optionalName(request, response) {
|
|
|
150
150
|
}
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
If you need to serve a static `.js` file, put it in `Config.staticDir`.
|
|
153
|
+
If you need to serve a static `.js` file, put it in your `Config.staticDir`.
|
|
154
154
|
|
|
155
155
|
|
|
156
156
|
## File Name Convention
|
|
157
|
-
|
|
157
|
+
This convention is only for files within your `Config.mocksDir`.
|
|
158
158
|
|
|
159
159
|
### Extension
|
|
160
|
-
|
|
160
|
+
|
|
161
|
+
The last 3 dots are reserved for the HTTP Method,
|
|
162
|
+
Response Status Code, and the File Extension.
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
api/user.GET.200.json
|
|
166
|
+
```
|
|
161
167
|
|
|
162
168
|
|
|
163
169
|
### Dynamic Parameters
|
|
@@ -204,32 +210,29 @@ api/foo/.GET.200.json
|
|
|
204
210
|
```
|
|
205
211
|
|
|
206
212
|
---
|
|
213
|
+
## Config
|
|
207
214
|
|
|
208
|
-
|
|
209
|
-
Files under `Config.staticDir` don’t use the filename convention.
|
|
210
|
-
Also, they take precedence over the `GET` mocks in `Config.mockDir`.
|
|
211
|
-
|
|
212
|
-
For example, if you have two files for `GET /foo/bar.jpg`
|
|
213
|
-
```
|
|
214
|
-
my-static-dir/foo/bar.jpg
|
|
215
|
-
my-mocks-dir/foo/bar.jpg.GET.200.jpg // Unreacheable
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
## `Config.proxyFallback`
|
|
215
|
+
### `proxyFallback`
|
|
220
216
|
Lets you specify a target server for serving routes you don’t have mocks for.
|
|
217
|
+
For example, `Config.proxyFallback = 'http://example.com:8080'`
|
|
221
218
|
|
|
222
219
|
|
|
223
|
-
|
|
220
|
+
### `delay` 🕓
|
|
224
221
|
The clock icon next to the mock selector is a checkbox for delaying a
|
|
225
222
|
particular response. They are handy for testing spinners.
|
|
226
223
|
|
|
227
224
|
The delay is globally configurable via `Config.delay = 1200` (milliseconds).
|
|
228
225
|
|
|
229
226
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
227
|
+
### `staticDir`
|
|
228
|
+
Files under `Config.staticDir` don’t use the filename convention.
|
|
229
|
+
Also, they take precedence over the `GET` mocks in `Config.mockDir`.
|
|
230
|
+
|
|
231
|
+
For example, if you have two files for `GET /foo/bar.jpg`
|
|
232
|
+
```
|
|
233
|
+
my-static-dir/foo/bar.jpg
|
|
234
|
+
my-mocks-dir/foo/bar.jpg.GET.200.jpg // Unreacheable
|
|
235
|
+
```
|
|
233
236
|
|
|
234
237
|
Use Case 1: If you have a bunch of static assets you don’t want to add `.GET.200.ext`
|
|
235
238
|
|
|
@@ -237,7 +240,7 @@ Use Case 2: For a standalone demo server. For example,
|
|
|
237
240
|
build your frontend bundle, and serve it from Mockaton.
|
|
238
241
|
|
|
239
242
|
|
|
240
|
-
|
|
243
|
+
### `cookies`
|
|
241
244
|
The selected cookie is sent in every response in the `Set-Cookie` header.
|
|
242
245
|
|
|
243
246
|
The key is just a label used for selecting a particular cookie in the
|
|
@@ -261,7 +264,7 @@ Config.cookies = {
|
|
|
261
264
|
}
|
|
262
265
|
```
|
|
263
266
|
|
|
264
|
-
|
|
267
|
+
### `extraHeaders`
|
|
265
268
|
They are applied last, right before ending the response.
|
|
266
269
|
In other words, they can overwrite the `Content-Type`. Note
|
|
267
270
|
that it's an array and the header name goes in even indices.
|
|
@@ -274,14 +277,14 @@ Config.extraHeaders = [
|
|
|
274
277
|
]
|
|
275
278
|
```
|
|
276
279
|
|
|
277
|
-
|
|
280
|
+
### `extraMimes`
|
|
278
281
|
```js
|
|
279
282
|
Config.extraMimes = {
|
|
280
283
|
jpg: 'application/jpeg'
|
|
281
284
|
}
|
|
282
285
|
```
|
|
283
286
|
|
|
284
|
-
|
|
287
|
+
### `corsAllowed`
|
|
285
288
|
```js
|
|
286
289
|
Config.corsAllowed = true
|
|
287
290
|
|
|
@@ -294,7 +297,7 @@ Config.corsMaxAge = 0 // seconds to cache the preflight req
|
|
|
294
297
|
Config.corsExposedHeaders = [] // headers you need to access in client-side JS
|
|
295
298
|
```
|
|
296
299
|
|
|
297
|
-
|
|
300
|
+
### `onReady`
|
|
298
301
|
This is a callback `(dashboardAddress: string) => void`, which defaults to
|
|
299
302
|
trying to open the dashboard in your default browser in macOS and Windows.
|
|
300
303
|
|
|
@@ -368,8 +371,13 @@ but `Config.proxyFallback` and `Config.corsAllowed` are not affected.
|
|
|
368
371
|
await mockaton.reset()
|
|
369
372
|
```
|
|
370
373
|
|
|
374
|
+
<div style="display: flex; align-items: center; gap: 20px">
|
|
375
|
+
<img src="./sample-mocks/api/user/avatar.GET.200.png" width="170"/>
|
|
376
|
+
<p style="font-size: 18px">“Use Mockaton” - Albert Einstein</p>
|
|
377
|
+
</div>
|
|
378
|
+
|
|
371
379
|
|
|
372
380
|
## TODO
|
|
373
381
|
- Refactor Tests
|
|
374
|
-
- Dashboard. Indicate if some
|
|
375
|
-
- jsonc, json5
|
|
382
|
+
- Dashboard. Indicate if some file on `staticDir` is overriding a mock.
|
|
383
|
+
- jsonc, json5?
|
package/package.json
CHANGED