mockaton 8.11.3 → 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.3",
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,7 +1,7 @@
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;
4
- --radiusSmall: 2px;
3
+ --radius: 6px;
4
+ --radiusSmall: 4px;
5
5
  }
6
6
 
7
7
  @media (prefers-color-scheme: light) {
@@ -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: 28px;
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;
@@ -239,7 +238,7 @@ select {
239
238
  }
240
239
 
241
240
  tr {
242
- border-top: 1px solid transparent;
241
+ border-top: 2px solid transparent;
243
242
  }
244
243
  }
245
244
 
@@ -298,14 +297,14 @@ select {
298
297
  .MockSelector {
299
298
  width: 260px;
300
299
  height: 30px;
301
- padding-right: 11px;
302
- padding-left: 17px;
300
+ padding-right: 5px;
301
+ padding-left: 16px;
303
302
  border: 0;
304
303
  text-align: right;
305
304
  direction: rtl;
306
305
  text-overflow: ellipsis;
307
306
  font-size: 12px;
308
- background-position: 5px center;
307
+ background-position: 2px center;
309
308
 
310
309
  &.nonDefault {
311
310
  font-weight: bold;
@@ -315,7 +314,7 @@ select {
315
314
  background: var(--color4xxBackground);
316
315
  }
317
316
  &:disabled {
318
- padding-right: 10px;
317
+ padding-right: 4px;
319
318
  appearance: none;
320
319
  background: transparent;
321
320
  cursor: default;
@@ -364,8 +363,8 @@ select {
364
363
  }
365
364
 
366
365
  > svg {
367
- width: 20px;
368
- height: 20px;
366
+ width: 18px;
367
+ height: 18px;
369
368
  stroke-width: 2.5px;
370
369
  border-radius: 50%;
371
370
  background: var(--colorSecondaryButtonBackground);
@@ -373,7 +372,7 @@ select {
373
372
  }
374
373
 
375
374
  .ProxyToggler {
376
- padding: 1px 4px;
375
+ padding: 1px 3px;
377
376
  background: var(--colorSecondaryButtonBackground);
378
377
  border-radius: var(--radiusSmall);
379
378
 
@@ -421,7 +420,7 @@ select {
421
420
 
422
421
  .InternalServerErrorToggler {
423
422
  display: flex;
424
- margin-left: 6px;
423
+ margin-left: 8px;
425
424
  cursor: pointer;
426
425
 
427
426
  > input {
@@ -441,7 +440,7 @@ select {
441
440
  }
442
441
 
443
442
  > span {
444
- padding: 5px 4px;
443
+ padding: 4px;
445
444
  font-size: 10px;
446
445
  font-weight: bold;
447
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'))