mockaton 8.12.7 → 8.12.9
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 +16 -14
- package/package.json +9 -1
- package/src/Commander.js +1 -1
package/README.md
CHANGED
|
@@ -8,10 +8,12 @@ An HTTP mock server for simulating APIs with minimal setup
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
## Overview
|
|
11
|
-
With Mockaton, you don’t need to write code for wiring up your
|
|
12
|
-
given directory is scanned for filenames
|
|
11
|
+
With Mockaton, you don’t need to write code for wiring up your
|
|
12
|
+
mocks. Instead, a given directory is scanned for filenames
|
|
13
|
+
following a convention similar to the URLs.
|
|
14
|
+
|
|
15
|
+
For example, for [/api/user/123](#), the mock filename could be:
|
|
13
16
|
|
|
14
|
-
For example, for <code>/<b>api/user</b>/1234</code> the filename would be:
|
|
15
17
|
<pre>
|
|
16
18
|
<code>my-mocks-dir/<b>api/user</b>/[user-id].GET.200.json</code>
|
|
17
19
|
</pre>
|
|
@@ -20,8 +22,7 @@ For example, for <code>/<b>api/user</b>/1234</code> the filename would be:
|
|
|
20
22
|
## Dashboard
|
|
21
23
|
|
|
22
24
|
On the dashboard you can select a mock variant for a particular route, delaying responses,
|
|
23
|
-
or triggering an autogenerated `500`
|
|
24
|
-
|
|
25
|
+
or triggering an autogenerated `500` error, among other features.
|
|
25
26
|
Nonetheless, there’s a programmatic API, which is handy
|
|
26
27
|
for setting up tests (see **Commander API** section).
|
|
27
28
|
|
|
@@ -60,12 +61,12 @@ api/videos.GET.<b>500</b>.txt # Internal Server Error
|
|
|
60
61
|
<br/>
|
|
61
62
|
|
|
62
63
|
## Fallback to Your Backend
|
|
63
|
-
No need to mock everything.
|
|
64
|
+
No need to mock everything. You can forward requests to your backend for routes
|
|
64
65
|
you don’t have mocks for, or routes that have the ☁️ **Cloud Checkbox** checked.
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
### Scraping mocks from your backend
|
|
68
|
-
|
|
69
|
+
By checking ✅ **Save Mocks**, you can collect the responses that hit your backend.
|
|
69
70
|
They will be saved in your `config.mocksDir` following the filename convention.
|
|
70
71
|
|
|
71
72
|
|
|
@@ -111,9 +112,10 @@ cd mockaton/demo-app-vite
|
|
|
111
112
|
npm install
|
|
112
113
|
|
|
113
114
|
npm run mockaton
|
|
114
|
-
npm run start
|
|
115
|
-
|
|
116
|
-
#
|
|
115
|
+
npm run start # in another terminal
|
|
116
|
+
|
|
117
|
+
# BTW, that directory has scripts for running both
|
|
118
|
+
# servers with one command in two terminals.
|
|
117
119
|
```
|
|
118
120
|
|
|
119
121
|
|
|
@@ -167,7 +169,7 @@ For example, `api/foo.GET.200.js`
|
|
|
167
169
|
**Option A:** An Object, Array, or String is sent as JSON.
|
|
168
170
|
|
|
169
171
|
```js
|
|
170
|
-
export default
|
|
172
|
+
export default { foo: 'bar' }
|
|
171
173
|
```
|
|
172
174
|
|
|
173
175
|
**Option B:** Function
|
|
@@ -205,7 +207,7 @@ export default async function insertColor(request, response) {
|
|
|
205
207
|
}
|
|
206
208
|
```
|
|
207
209
|
|
|
208
|
-
`api/colors
|
|
210
|
+
`api/colors.GET.200.js`
|
|
209
211
|
```js
|
|
210
212
|
import colorsFixture from './colors.json' with { type: 'json' }
|
|
211
213
|
|
|
@@ -386,7 +388,7 @@ header was not sent by your backend.
|
|
|
386
388
|
|
|
387
389
|
<p>
|
|
388
390
|
An <code>.unknown</code> extension means the <code>Content-Type</code> is not in
|
|
389
|
-
|
|
391
|
+
the predefined list. For that, you can add it to <code>config.extraMimes</code>
|
|
390
392
|
</p>
|
|
391
393
|
</details>
|
|
392
394
|
|
|
@@ -520,7 +522,7 @@ config.corsExposedHeaders = [] // headers you need to access in client-side JS
|
|
|
520
522
|
### `onReady?: (dashboardUrl: string) => void`
|
|
521
523
|
By default, it will open the dashboard in your default browser on macOS and
|
|
522
524
|
Windows. But for a more cross-platform utility you could `npm install open` and
|
|
523
|
-
|
|
525
|
+
that implementation will be automatically used instead.
|
|
524
526
|
|
|
525
527
|
If you don’t want to open a browser, pass a noop:
|
|
526
528
|
```js
|
package/package.json
CHANGED
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
"name": "mockaton",
|
|
3
3
|
"description": "HTTP Mock Server",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.12.
|
|
5
|
+
"version": "8.12.9",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": "https://github.com/ericfortis/mockaton",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"mock-server",
|
|
12
|
+
"mock",
|
|
13
|
+
"api",
|
|
14
|
+
"testing",
|
|
15
|
+
"front-end",
|
|
16
|
+
"back-end"
|
|
17
|
+
],
|
|
10
18
|
"scripts": {
|
|
11
19
|
"test": "node --test \"src/**/*.test.js\"",
|
|
12
20
|
"coverage": "node --test --test-reporter=lcov --test-reporter-destination=.coverage/lcov.info --experimental-test-coverage \"src/**/*.test.js\"",
|
package/src/Commander.js
CHANGED