mockaton 8.20.4 → 8.21.1
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 +28 -22
- package/package.json +6 -7
- package/src/Dashboard.css +14 -11
package/README.md
CHANGED
|
@@ -19,11 +19,16 @@ With Mockaton, developers can achieve correctness without sacrificing speed.
|
|
|
19
19
|
- Enables testing of complex scenarios that would otherwise be
|
|
20
20
|
skipped. For example, triggering an error on a third-party API. Or if
|
|
21
21
|
you are a frontend developer, triggering it on your project’s backend.
|
|
22
|
-
- Allows for deterministic, comprehensive, and consistent state
|
|
22
|
+
- Allows for deterministic, comprehensive, and consistent state, which helps
|
|
23
|
+
spot inadvertent regressions during development, or for setting up screenshot
|
|
24
|
+
tests, e.g., with [pixaton](https://github.com/ericfortis/pixaton).
|
|
23
25
|
|
|
24
26
|
### Speed
|
|
25
27
|
- Prevents progress from being blocked by waiting for APIs.
|
|
26
|
-
-
|
|
28
|
+
- Works around unstable dev backends while developing UIs.
|
|
29
|
+
- Time travel. If you commit the mocks to your repo, it’s straightforward
|
|
30
|
+
to check out long-lived branches and bisect bugs, so you don’t
|
|
31
|
+
have to downgrade backends to old API contracts or databases.
|
|
27
32
|
|
|
28
33
|
<br/>
|
|
29
34
|
|
|
@@ -44,13 +49,15 @@ For example, for [/api/user/123](#), the filename could be:
|
|
|
44
49
|
|
|
45
50
|
On the dashboard you can select a mock variant for a particular route, delaying responses,
|
|
46
51
|
or triggering an autogenerated `500` error, among other features.
|
|
52
|
+
|
|
53
|
+
|
|
47
54
|
Nonetheless, there’s a programmatic API, which is handy
|
|
48
55
|
for setting up tests (see **Commander API** section below).
|
|
49
56
|
|
|
50
57
|
<picture>
|
|
51
|
-
<source media="(prefers-color-scheme: light)" srcset="pixaton-tests/macos/pic-for-readme.
|
|
52
|
-
<source media="(prefers-color-scheme: dark)" srcset="pixaton-tests/macos/pic-for-readme.
|
|
53
|
-
<img alt="Mockaton Dashboard" src="pixaton-tests/macos/pic-for-readme.
|
|
58
|
+
<source media="(prefers-color-scheme: light)" srcset="pixaton-tests/macos/pic-for-readme.vp880x800.light.gold.png">
|
|
59
|
+
<source media="(prefers-color-scheme: dark)" srcset="pixaton-tests/macos/pic-for-readme.vp880x800.dark.gold.png">
|
|
60
|
+
<img alt="Mockaton Dashboard" src="pixaton-tests/macos/pic-for-readme.vp880x800.light.gold.png">
|
|
54
61
|
</picture>
|
|
55
62
|
|
|
56
63
|
|
|
@@ -58,7 +65,8 @@ for setting up tests (see **Commander API** section below).
|
|
|
58
65
|
<br/>
|
|
59
66
|
|
|
60
67
|
## Multiple Mock Variants
|
|
61
|
-
Each route can have different mocks. There are two
|
|
68
|
+
Each route can have different mocks. There are two
|
|
69
|
+
options for doing that, and they can be combined.
|
|
62
70
|
|
|
63
71
|
### Adding comments to the filename
|
|
64
72
|
Comments are anything within parentheses, including them.
|
|
@@ -73,9 +81,9 @@ For instance, you can use a `4xx` or `5xx` status code for triggering error
|
|
|
73
81
|
responses, or a `2xx` such as `204` for testing empty collections.
|
|
74
82
|
|
|
75
83
|
<pre>
|
|
76
|
-
api/videos
|
|
77
|
-
api/videos.GET.<b>403</b>.json
|
|
78
|
-
api/videos.GET.<b>500</b>.txt
|
|
84
|
+
api/videos.GET.<b>204</b>.empty # No Content
|
|
85
|
+
api/videos.GET.<b>403</b>.json # Forbidden
|
|
86
|
+
api/videos.GET.<b>500</b>.txt # Internal Server Error
|
|
79
87
|
</pre>
|
|
80
88
|
|
|
81
89
|
|
|
@@ -84,15 +92,15 @@ api/videos.GET.<b>500</b>.txt # Internal Server Error
|
|
|
84
92
|
## Scraping Mocks from your Backend
|
|
85
93
|
|
|
86
94
|
### Option 1: Browser Extension
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
With the companion [browser-devtools extension](https://github.com/ericfortis/download-http-requests-browser-ext)
|
|
96
|
+
you can download all the HTTP responses at once, and they
|
|
89
97
|
get saved following Mockaton’s filename convention.
|
|
90
98
|
|
|
91
99
|
### Option 2: Fallback to Your Backend
|
|
92
100
|
<details>
|
|
93
101
|
<summary>Details</summary>
|
|
94
102
|
|
|
95
|
-
This option could be a bit elaborate if your backend uses third-party
|
|
103
|
+
This option could be a bit elaborate if your backend uses third-party authentication,
|
|
96
104
|
because you’d have to manually inject cookies or `sessionStorage` tokens.
|
|
97
105
|
|
|
98
106
|
On the other hand, proxying to your backend is straightforward if your backend
|
|
@@ -118,6 +126,7 @@ Create a `my-mockaton.js` file
|
|
|
118
126
|
import { resolve } from 'node:path'
|
|
119
127
|
import { Mockaton } from 'mockaton'
|
|
120
128
|
|
|
129
|
+
|
|
121
130
|
Mockaton({
|
|
122
131
|
mocksDir: resolve('my-mocks-dir'), // must exist
|
|
123
132
|
port: 2345
|
|
@@ -175,12 +184,7 @@ permutations for out-of-stock, new-arrival, and discontinued.
|
|
|
175
184
|
- Spinners by delaying responses
|
|
176
185
|
- Setting up UI tests
|
|
177
186
|
|
|
178
|
-
###
|
|
179
|
-
If you commit the mocks to your repo, it’s straightforward to
|
|
180
|
-
bisect bugs and check out long-lived branches, so you don’t
|
|
181
|
-
have to downgrade backends to old API contracts or databases.
|
|
182
|
-
|
|
183
|
-
### Simulating complex backend states
|
|
187
|
+
### Demoing complex backend states
|
|
184
188
|
Sometimes, the ideal flow you need is too difficult to reproduce from the actual backend.
|
|
185
189
|
For this, you can **Bulk Select** mocks by comments to simulate the complete states
|
|
186
190
|
you want. For example, by adding `(demo-part1)`, `(demo-part2)` to the filenames.
|
|
@@ -304,8 +308,10 @@ want a `Content-Type` header in the response.
|
|
|
304
308
|
<br/>
|
|
305
309
|
|
|
306
310
|
### Dynamic parameters
|
|
307
|
-
Anything within square brackets is always matched.
|
|
308
|
-
|
|
311
|
+
Anything within square brackets is always matched.
|
|
312
|
+
|
|
313
|
+
For example, for <a href="#">/api/company/<b>123</b>/user/<b>789</b></a>,
|
|
314
|
+
the filename could be:
|
|
309
315
|
|
|
310
316
|
<pre><code>api/company/<b>[id]</b>/user/<b>[uid]</b>.GET.200.json</code></pre>
|
|
311
317
|
|
|
@@ -348,7 +354,7 @@ string it’s ignored anyway.
|
|
|
348
354
|
<br/>
|
|
349
355
|
|
|
350
356
|
### Index-like routes
|
|
351
|
-
If you have
|
|
357
|
+
If you have <a href="#">api/foo</a> and <a href="#">api/foo/bar</a>, you have two options:
|
|
352
358
|
|
|
353
359
|
**Option A.** Standard naming:
|
|
354
360
|
```
|
|
@@ -376,7 +382,7 @@ as explained above in the _Use Cases_ section.
|
|
|
376
382
|
|
|
377
383
|
Files under `config.staticDir` take precedence over corresponding
|
|
378
384
|
`GET` mocks in `config.mocksDir` (regardless of status code).
|
|
379
|
-
For example, if you have two files for `GET
|
|
385
|
+
For example, if you have two files for `GET` <a href="#">/foo/bar.jpg</a> such as:
|
|
380
386
|
<pre>
|
|
381
387
|
my-static-dir<b>/foo/bar.jpg</b> <span style="color:green"> // Wins</span>
|
|
382
388
|
my-mocks-dir<b>/foo/bar.jpg</b>.GET.200.jpg <span style="color:red"> // Unreachable</span>
|
package/package.json
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
"name": "mockaton",
|
|
3
3
|
"description": "HTTP Mock Server",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.21.1",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": "https://github.com/ericfortis/mockaton",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"mock-server",
|
|
12
|
+
"rest-api",
|
|
12
13
|
"mock",
|
|
13
14
|
"api",
|
|
14
|
-
"testing"
|
|
15
|
-
"front-end",
|
|
16
|
-
"back-end"
|
|
15
|
+
"testing"
|
|
17
16
|
],
|
|
18
17
|
"scripts": {
|
|
19
18
|
"test": "node --test \"src/**/*.test.js\"",
|
|
@@ -22,11 +21,11 @@
|
|
|
22
21
|
"pixaton": "node --test --import=./pixaton-tests/_setup.js --experimental-test-isolation=none \"pixaton-tests/**/*.test.js\"",
|
|
23
22
|
"outdated": "npm outdated --parseable | awk -F: '{ printf \"npm i %-30s ;# %s\\n\", $4, $2 }'"
|
|
24
23
|
},
|
|
25
|
-
"optionalDependencies": {
|
|
26
|
-
"open": "^10"
|
|
27
|
-
},
|
|
28
24
|
"devDependencies": {
|
|
29
25
|
"pixaton": "1.1.2",
|
|
30
26
|
"puppeteer": "24.18.0"
|
|
27
|
+
},
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"open": "10.2.0"
|
|
31
30
|
}
|
|
32
31
|
}
|
package/src/Dashboard.css
CHANGED
|
@@ -125,7 +125,7 @@ header {
|
|
|
125
125
|
align-items: flex-end;
|
|
126
126
|
gap: 16px 10px;
|
|
127
127
|
|
|
128
|
-
@media (max-width:
|
|
128
|
+
@media (max-width: 879px) {
|
|
129
129
|
max-width: 400px;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -235,7 +235,7 @@ header {
|
|
|
235
235
|
|
|
236
236
|
.Help {
|
|
237
237
|
min-width: 24px;
|
|
238
|
-
align-self:
|
|
238
|
+
align-self: end;
|
|
239
239
|
margin-left: auto;
|
|
240
240
|
fill: var(--colorSecondaryAction);
|
|
241
241
|
|
|
@@ -243,7 +243,7 @@ header {
|
|
|
243
243
|
fill: var(--colorAccent);
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
@media (max-width:
|
|
246
|
+
@media (max-width: 520px) {
|
|
247
247
|
display: none;
|
|
248
248
|
}
|
|
249
249
|
}
|
|
@@ -256,22 +256,19 @@ main {
|
|
|
256
256
|
grid-template-columns: minmax(min-content, max-content) 1fr;
|
|
257
257
|
|
|
258
258
|
@media (max-width: 1160px) {
|
|
259
|
-
grid-template-columns: min(
|
|
259
|
+
grid-template-columns: min(580px) 1fr;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
@media (max-width:
|
|
262
|
+
@media (max-width: 879px) {
|
|
263
263
|
grid-template-columns: 100%;
|
|
264
264
|
grid-template-rows: 1fr 1fr;
|
|
265
|
-
|
|
266
|
-
.leftSide {
|
|
267
|
-
box-shadow: var(--boxShadow1);
|
|
268
|
-
}
|
|
269
265
|
}
|
|
270
266
|
|
|
271
267
|
.leftSide {
|
|
272
268
|
padding: 16px;
|
|
273
269
|
padding-bottom: 0;
|
|
274
270
|
overflow-y: auto;
|
|
271
|
+
box-shadow: var(--boxShadow1);
|
|
275
272
|
}
|
|
276
273
|
|
|
277
274
|
.rightSide {
|
|
@@ -292,6 +289,12 @@ table {
|
|
|
292
289
|
tbody {
|
|
293
290
|
border-bottom: 20px solid transparent;
|
|
294
291
|
}
|
|
292
|
+
|
|
293
|
+
td:nth-child(3),
|
|
294
|
+
td:nth-child(4),
|
|
295
|
+
td:nth-child(5) {
|
|
296
|
+
max-width: 280px;
|
|
297
|
+
}
|
|
295
298
|
}
|
|
296
299
|
|
|
297
300
|
.empty {
|
|
@@ -323,7 +326,7 @@ table {
|
|
|
323
326
|
.MockSelector {
|
|
324
327
|
width: 100%;
|
|
325
328
|
height: 26px;
|
|
326
|
-
padding-right:
|
|
329
|
+
padding-right: 16px;
|
|
327
330
|
padding-left: 8px;
|
|
328
331
|
text-overflow: ellipsis;
|
|
329
332
|
font-size: 12px;
|
|
@@ -343,7 +346,7 @@ table {
|
|
|
343
346
|
background: transparent;
|
|
344
347
|
cursor: default;
|
|
345
348
|
color: var(--colorDisabledMockSelector);
|
|
346
|
-
opacity:
|
|
349
|
+
opacity: 0.8;
|
|
347
350
|
}
|
|
348
351
|
}
|
|
349
352
|
|