mockaton 8.2.21 → 8.2.22
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 +21 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,8 +17,8 @@ By the way, [this browser
|
|
|
17
17
|
extension](https://github.com/ericfortis/devtools-ext-tar-http-requests)
|
|
18
18
|
can create a TAR of your requests following that convention.
|
|
19
19
|
|
|
20
|
-
Nonetheless, you don’t need to mock all your APIs.
|
|
21
|
-
|
|
20
|
+
Nonetheless, you don’t need to mock all your APIs. Mockaton
|
|
21
|
+
can request from your backend the routes you don’t have mocks for.
|
|
22
22
|
That’s done with `config.proxyFallback = 'http://mybackend'`
|
|
23
23
|
|
|
24
24
|
## Multiple Mock Variants
|
|
@@ -123,15 +123,6 @@ filename, such as `(demo-part1)`, `(demo-part2)`.
|
|
|
123
123
|
- Reverse Proxies such as [Burp](https://portswigger.net/burp) are also handy for overriding responses.
|
|
124
124
|
- [Mock Server Worker](https://mswjs.io)
|
|
125
125
|
|
|
126
|
-
---
|
|
127
|
-
## Default Mock for a Route
|
|
128
|
-
You can add the comment: `(default)` to a filename.
|
|
129
|
-
Otherwise, the first file in **alphabetical order** wins.
|
|
130
|
-
|
|
131
|
-
```
|
|
132
|
-
api/user(default).GET.200.json
|
|
133
|
-
```
|
|
134
|
-
|
|
135
126
|
---
|
|
136
127
|
|
|
137
128
|
## You can write JSON mocks in JavaScript or TypeScript
|
|
@@ -227,6 +218,15 @@ api/foo<b>(my comment)</b>.GET.200.json
|
|
|
227
218
|
api/foo.GET.200.json
|
|
228
219
|
</pre>
|
|
229
220
|
|
|
221
|
+
### Default Mock for a Route
|
|
222
|
+
You can add the comment: `(default)`.
|
|
223
|
+
Otherwise, the first file in **alphabetical order** wins.
|
|
224
|
+
|
|
225
|
+
<pre>
|
|
226
|
+
api/user<b>(default)</b>.GET.200.json
|
|
227
|
+
</pre>
|
|
228
|
+
|
|
229
|
+
|
|
230
230
|
### Query String Params
|
|
231
231
|
The query string is ignored when routing to it. In other words, it’s only used for
|
|
232
232
|
documenting the URL contract.
|
|
@@ -238,9 +238,8 @@ Speaking of which, on Windows filenames containing "?" are [not
|
|
|
238
238
|
permitted](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file), but since that’s part of the query string, it’s ignored anyway.
|
|
239
239
|
|
|
240
240
|
|
|
241
|
-
### Index-like
|
|
242
|
-
|
|
243
|
-
`api/foo`, you have two options:
|
|
241
|
+
### Index-like routes
|
|
242
|
+
If you have `api/foo` and `api/foo/bar`, you have two options:
|
|
244
243
|
|
|
245
244
|
**Option A:**
|
|
246
245
|
```
|
|
@@ -309,15 +308,13 @@ config.cookies = {
|
|
|
309
308
|
})
|
|
310
309
|
}
|
|
311
310
|
```
|
|
312
|
-
The selected cookie is
|
|
311
|
+
The selected cookie, which is the first one by default, is sent in every
|
|
312
|
+
response in a `Set-Cookie` header. If you need to send more
|
|
313
|
+
cookies, inject them globally in `config.extraHeaders`.
|
|
313
314
|
|
|
314
315
|
By the way, the `jwtCookie` helper has a hardcoded header and signature.
|
|
315
316
|
In other words, it’s useful only if you care about the payload.
|
|
316
317
|
|
|
317
|
-
If you need to send more than one cookie,
|
|
318
|
-
inject them globally in `config.extraHeaders`.
|
|
319
|
-
|
|
320
|
-
|
|
321
318
|
|
|
322
319
|
### `extraHeaders?: string[]`
|
|
323
320
|
Note it’s a unidimensional array. The header name goes at even indices.
|
|
@@ -337,6 +334,8 @@ config.extraMimes = {
|
|
|
337
334
|
jpe: 'application/jpeg'
|
|
338
335
|
}
|
|
339
336
|
```
|
|
337
|
+
These media types take precedence over the built-in
|
|
338
|
+
[utils/mime.js](src/utils/mime.js), so you can override them.
|
|
340
339
|
|
|
341
340
|
|
|
342
341
|
### `plugins?: [filenameTester: RegExp, plugin: Plugin][]`
|
|
@@ -352,7 +351,7 @@ type Plugin = (
|
|
|
352
351
|
```
|
|
353
352
|
Plugins are for processing mocks before sending them.
|
|
354
353
|
|
|
355
|
-
Note: don’t call `response.end()`
|
|
354
|
+
Note: don’t call `response.end()` on them.
|
|
356
355
|
|
|
357
356
|
<details>
|
|
358
357
|
<summary><b> See Plugin Examples </b></summary>
|
|
@@ -366,7 +365,7 @@ import { readFileSync } from 'node:js'
|
|
|
366
365
|
import { jsToJsonPlugin } from 'mockaton'
|
|
367
366
|
|
|
368
367
|
config.plugins = [
|
|
369
|
-
[/\.(js|ts)$/, jsToJsonPlugin], // Default
|
|
368
|
+
[/\.(js|ts)$/, jsToJsonPlugin], // Default but you need to add it to your list if you need it
|
|
370
369
|
[/\.yml$/, yamlToJsonPlugin],
|
|
371
370
|
[/foo\.GET\.200\.txt$/, capitalizePlugin], // e.g. GET /api/foo would be capitalized
|
|
372
371
|
]
|
|
@@ -401,7 +400,7 @@ config.corsExposedHeaders = [] // headers you need to access in client-side JS
|
|
|
401
400
|
|
|
402
401
|
|
|
403
402
|
### `onReady?: (dashboardUrl: string) => void`
|
|
404
|
-
This defaults to trying to open the dashboard in your default browser
|
|
403
|
+
This defaults to trying to open the dashboard in your default browser on macOS and
|
|
405
404
|
Windows. For a more cross-platform utility, you could `npm install open` and pass it.
|
|
406
405
|
```js
|
|
407
406
|
import open from 'open'
|
package/package.json
CHANGED