mockaton 8.11.4 → 8.11.5

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 CHANGED
@@ -3,26 +3,35 @@
3
3
  ![NPM Version](https://img.shields.io/npm/v/mockaton)
4
4
  ![NPM Version](https://img.shields.io/npm/l/mockaton)
5
5
 
6
- HTTP mock server for developing and testing frontends.
7
-
8
- ## Convention over Code
9
6
 
10
7
  With Mockaton you don’t need to write code for wiring mocks. Instead, it scans a
11
- given directory for mock filenames following a convention similar to the URLs.
8
+ given directory for filenames following a convention similar to the URLs.
12
9
 
13
- For example, for <code>/<b>api/user</b>/1234</code> the mock filename would be:
10
+ For example, for <code>/<b>api/user</b>/1234</code> the filename would be:
14
11
  <pre>
15
12
  <code>my-mocks-dir/<b>api/user</b>/[user-id].GET.200.json</code>
16
13
  </pre>
17
14
 
18
- ## Multiple Mock Variants
19
- You can have different mocks for a particular route by adding
20
- comments and/or using different status codes.
21
15
 
16
+ On the dashboard you can select a mock variant for a particular route, delaying responses,
17
+ and triggering an autogenerated `500` (Internal Server Error), among other features.
18
+
19
+ Nonetheless, there’s a programmatic API, which is handy
20
+ for setting up tests. See **Commander&nbsp;API** section.
21
+
22
+ <picture>
23
+ <source media="(prefers-color-scheme: light)" srcset="./pixaton-tests/pic-for-readme.vp840x800.light.gold.png">
24
+ <source media="(prefers-color-scheme: dark)" srcset="./pixaton-tests/pic-for-readme.vp840x800.dark.gold.png">
25
+ <img alt="Mockaton Dashboard" src="./pixaton-tests/pic-for-readme.vp840x800.light.gold.png">
26
+ </picture>
27
+
28
+
29
+ ## Multiple Mock Variants
30
+ Each route can have different mocks. There’s two options for doing that:
22
31
 
23
- ### Adding comments in filenames
24
- Comments are anything within parentheses, including them. They
25
- are ignored for URL purposes, so you can add as many as you want.
32
+ ### Adding comments to the filename
33
+ Comments are anything within parentheses,
34
+ including them. A filename can have many comments.
26
35
 
27
36
  <pre>
28
37
  api/login<b>(locked out user)</b>.POST.423.json
@@ -31,18 +40,19 @@ api/login<b>(invalid login attempt)</b>.POST.401.json
31
40
 
32
41
  ### Different response status code
33
42
  For instance, using a `4xx` or `5xx` status code for triggering error
34
- responses. Or `2xx` such as `204` (No Content) for testing collections without records.
43
+ responses. Or a `2xx` such as `204` (No Content) for testing empty collections.
35
44
 
36
45
  <pre>
37
- api/videos.GET.<b>204</b>.json
46
+ api/videos(empty list).GET.<b>204</b>.json
38
47
  api/videos.GET.<b>403</b>.json
39
- api/videos.GET.<b>500</b>.empty
48
+ api/videos.GET.<b>500</b>.txt
40
49
  </pre>
41
50
 
42
51
 
52
+
43
53
  ## Fallback to your Backend
44
- Mockaton can fallback to your real backend on routes you don’t have
45
- mocks for, or on routes that have the ☁️ **Cloud Checkbox** checked.
54
+ No need to mock everything. Mockaton can request from your backend the routes
55
+ you don’t have mocks for, or routes that have the ☁️ **Cloud Checkbox** checked.
46
56
 
47
57
 
48
58
  ### Scrapping Mocks from your Backend
@@ -51,23 +61,11 @@ They will be saved on your `config.mocksDir` following the filename convention.
51
61
 
52
62
 
53
63
 
54
- ## Dashboard
55
- On the dashboard you can select a mock variant for a particular route, delaying responses,
56
- and triggering an autogenerated `500` (Internal Server Error), among other features.
57
-
58
- Nonetheless, there’s a programmatic API see
59
- **Commander&nbsp;API** below, which is handy setting up tests.
60
-
61
- <picture>
62
- <source media="(prefers-color-scheme: light)" srcset="./pixaton-tests/pic-for-readme.vp830x800.light.gold.png">
63
- <source media="(prefers-color-scheme: dark)" srcset="./pixaton-tests/pic-for-readme.vp830x800.dark.gold.png">
64
- <img alt="Mockaton Dashboard" src="./pixaton-tests/pic-for-readme.vp830x800.light.gold.png">
65
- </picture>
66
-
67
-
68
-
69
64
  ## Basic Usage
65
+ Mockaton is a Node.js program with no build or runtime NPM dependencies.
66
+
70
67
  `tsx` is only needed if you want to write mocks in TypeScript.
68
+
71
69
  ```sh
72
70
  npm install mockaton tsx --save-dev
73
71
  ```
@@ -91,7 +89,7 @@ node --import=tsx my-mockaton.js
91
89
 
92
90
  ## Demo App (Vite)
93
91
 
94
- This is a minimal React + Vite + Mockaton app. It’s mainly a list of
92
+ This is a minimal React + Vite + Mockaton app. It’s a list of
95
93
  colors, which contains all of their possible states. For example,
96
94
  permutations for out-of-stock, new-arrival, and discontinued.
97
95
 
@@ -282,7 +280,7 @@ documenting the URL contract.
282
280
  api/video<b>?limit=[limit]</b>.GET.200.json
283
281
  </pre>
284
282
 
285
- Speaking of which, on Windows filenames containing "?" are [not
283
+ On Windows filenames containing "?" are [not
286
284
  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.
287
285
 
288
286
 
@@ -369,10 +367,11 @@ Mockaton’s predefined list. For that, you can add it to <code>config.extraMime
369
367
  Files under `config.staticDir` don’t use the filename convention.
370
368
  They take precedence over the `GET` mocks in `config.mocksDir`.
371
369
  For example, if you have two files for `GET /foo/bar.jpg`
372
- ```
373
- my-static-dir/foo/bar.jpg
374
- my-mocks-dir/foo/bar.jpg.GET.200.jpg // Unreacheable
375
- ```
370
+
371
+ <pre>
372
+ my-static-dir<b>/foo/bar.jpg</b>
373
+ my-mocks-dir<b>/foo/bar.jpg</b>.GET.200.jpg // Unreacheable
374
+ </pre>
376
375
 
377
376
 
378
377
  ### `cookies?: { [label: string]: string }`
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "A deterministic server-side for developing and testing frontend clients",
4
4
  "type": "module",
5
- "version": "8.11.4",
5
+ "version": "8.11.5",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Dashboard.css CHANGED
@@ -1,6 +1,6 @@
1
1
  :root {
2
2
  --boxShadow1: 0 2px 1px -1px rgba(0, 0, 0, 0.15), 0 1px 1px 0 rgba(0, 0, 0, 0.15), 0 1px 3px 0 rgba(0, 0, 0, 0.1);
3
- --radius: 28px;
3
+ --radius: 6px;
4
4
  --radiusSmall: 4px;
5
5
  }
6
6
 
@@ -17,7 +17,7 @@
17
17
  --colorSecondaryAction: #555;
18
18
  --colorDisabledMockSelector: #444;
19
19
  --colorHover: #dfefff;
20
- --colorLabel: #555;
20
+ --colorLabel: #444;
21
21
  --colorLightRed: #ffe4ee;
22
22
  --colorRed: #da0f00;
23
23
  --colorText: #000;
@@ -89,7 +89,7 @@ select {
89
89
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23888888'><path d='M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z'/></svg>") no-repeat;
90
90
  background-color: var(--colorComboBoxBackground);
91
91
  background-size: 16px;
92
- background-position: 98% center;
92
+ background-position: 100% center;
93
93
 
94
94
  &:enabled {
95
95
  box-shadow: var(--boxShadow1);
@@ -115,12 +115,12 @@ select {
115
115
  border-bottom: 1px solid rgba(127, 127, 127, 0.1);
116
116
  background: var(--colorHeaderBackground);
117
117
  box-shadow: var(--boxShadow1);
118
- gap: 6px;
118
+ gap: 10px;
119
119
 
120
120
  img {
121
121
  width: 130px;
122
122
  align-self: center;
123
- margin-right: 20px;
123
+ margin-right: 22px;
124
124
  }
125
125
 
126
126
  .Field {
@@ -129,7 +129,6 @@ select {
129
129
  span {
130
130
  display: flex;
131
131
  align-items: center;
132
- margin-left: 6px;
133
132
  color: var(--colorLabel);
134
133
  font-size: 11px;
135
134
  gap: 4px;
@@ -149,9 +148,9 @@ select {
149
148
  select {
150
149
  width: 100%;
151
150
  height: 28px;
152
- padding: 4px 12px;
151
+ padding: 4px 8px;
153
152
  border-right: 3px solid transparent;
154
- margin-top: 3px;
153
+ margin-top: 4px;
155
154
  color: var(--colorText);
156
155
  font-size: 11px;
157
156
  box-shadow: var(--boxShadow1);
@@ -164,7 +163,7 @@ select {
164
163
  }
165
164
 
166
165
  &.GlobalDelayField {
167
- width: 88px;
166
+ width: 84px;
168
167
 
169
168
  input[type=number] {
170
169
  padding-right: 0;
@@ -181,7 +180,7 @@ select {
181
180
 
182
181
  &.FallbackBackend {
183
182
  position: relative;
184
- width: 212px;
183
+ width: 210px;
185
184
 
186
185
  .SaveProxiedCheckbox {
187
186
  position: absolute;
@@ -194,10 +193,6 @@ select {
194
193
  font-size: 11px;
195
194
  gap: 4px;
196
195
 
197
- span {
198
- margin-left: 0;
199
- }
200
-
201
196
  input:disabled + span {
202
197
  opacity: 0.8;
203
198
  }
@@ -243,7 +238,7 @@ select {
243
238
  }
244
239
 
245
240
  tr {
246
- border-top: 1px solid transparent;
241
+ border-top: 2px solid transparent;
247
242
  }
248
243
  }
249
244
 
@@ -282,10 +277,10 @@ select {
282
277
 
283
278
  .PreviewLink {
284
279
  position: relative;
285
- left: -10px;
280
+ left: -6px;
286
281
  display: inline-block;
287
- width: 282px;
288
- padding: 8px 11px;
282
+ width: 272px;
283
+ padding: 8px 6px;
289
284
  border-radius: var(--radius);
290
285
  color: var(--colorAccent);
291
286
  text-decoration: none;
@@ -302,14 +297,14 @@ select {
302
297
  .MockSelector {
303
298
  width: 260px;
304
299
  height: 30px;
305
- padding-right: 11px;
306
- padding-left: 17px;
300
+ padding-right: 5px;
301
+ padding-left: 16px;
307
302
  border: 0;
308
303
  text-align: right;
309
304
  direction: rtl;
310
305
  text-overflow: ellipsis;
311
306
  font-size: 12px;
312
- background-position: 5px center;
307
+ background-position: 2px center;
313
308
 
314
309
  &.nonDefault {
315
310
  font-weight: bold;
@@ -319,7 +314,7 @@ select {
319
314
  background: var(--color4xxBackground);
320
315
  }
321
316
  &:disabled {
322
- padding-right: 10px;
317
+ padding-right: 4px;
323
318
  appearance: none;
324
319
  background: transparent;
325
320
  cursor: default;
@@ -368,8 +363,8 @@ select {
368
363
  }
369
364
 
370
365
  > svg {
371
- width: 20px;
372
- height: 20px;
366
+ width: 18px;
367
+ height: 18px;
373
368
  stroke-width: 2.5px;
374
369
  border-radius: 50%;
375
370
  background: var(--colorSecondaryButtonBackground);
@@ -377,7 +372,7 @@ select {
377
372
  }
378
373
 
379
374
  .ProxyToggler {
380
- padding: 1px 4px;
375
+ padding: 1px 3px;
381
376
  background: var(--colorSecondaryButtonBackground);
382
377
  border-radius: var(--radiusSmall);
383
378
 
@@ -425,7 +420,7 @@ select {
425
420
 
426
421
  .InternalServerErrorToggler {
427
422
  display: flex;
428
- margin-left: 6px;
423
+ margin-left: 8px;
429
424
  cursor: pointer;
430
425
 
431
426
  > input {
@@ -445,7 +440,7 @@ select {
445
440
  }
446
441
 
447
442
  > span {
448
- padding: 5px 4px;
443
+ padding: 4px;
449
444
  font-size: 10px;
450
445
  font-weight: bold;
451
446
  color: var(--colorSecondaryAction);
package/src/ProxyRelay.js CHANGED
@@ -21,7 +21,7 @@ export async function proxy(req, response, delay) {
21
21
  headers['set-cookie'] = proxyResponse.headers.getSetCookie() // parses multiple into an array
22
22
  response.writeHead(proxyResponse.status, headers)
23
23
  const body = await proxyResponse.text()
24
- setTimeout(() => response.end(body), delay) // TESTME
24
+ setTimeout(() => response.end(body), delay) // TESTME (Note that when the proxy fails e.g. wrong addr it doesn't delay)
25
25
 
26
26
  if (config.collectProxied) {
27
27
  const ext = extFor(proxyResponse.headers.get('content-type'))