mockaton 8.21.0 → 8.21.3
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 +15 -12
- package/package.json +6 -7
- package/src/Dashboard.css +24 -90
- package/src/Dashboard.html +0 -2
- package/src/Dashboard.js +26 -8
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ With Mockaton, developers can achieve correctness without sacrificing speed.
|
|
|
25
25
|
|
|
26
26
|
### Speed
|
|
27
27
|
- Prevents progress from being blocked by waiting for APIs.
|
|
28
|
-
-
|
|
28
|
+
- Works around unstable dev backends while developing UIs.
|
|
29
29
|
- Time travel. If you commit the mocks to your repo, it’s straightforward
|
|
30
30
|
to check out long-lived branches and bisect bugs, so you don’t
|
|
31
31
|
have to downgrade backends to old API contracts or databases.
|
|
@@ -65,7 +65,8 @@ for setting up tests (see **Commander API** section below).
|
|
|
65
65
|
<br/>
|
|
66
66
|
|
|
67
67
|
## Multiple Mock Variants
|
|
68
|
-
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.
|
|
69
70
|
|
|
70
71
|
### Adding comments to the filename
|
|
71
72
|
Comments are anything within parentheses, including them.
|
|
@@ -80,9 +81,9 @@ For instance, you can use a `4xx` or `5xx` status code for triggering error
|
|
|
80
81
|
responses, or a `2xx` such as `204` for testing empty collections.
|
|
81
82
|
|
|
82
83
|
<pre>
|
|
83
|
-
api/videos
|
|
84
|
-
api/videos.GET.<b>403</b>.json
|
|
85
|
-
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
|
|
86
87
|
</pre>
|
|
87
88
|
|
|
88
89
|
|
|
@@ -91,8 +92,8 @@ api/videos.GET.<b>500</b>.txt # Internal Server Error
|
|
|
91
92
|
## Scraping Mocks from your Backend
|
|
92
93
|
|
|
93
94
|
### Option 1: Browser Extension
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
96
97
|
get saved following Mockaton’s filename convention.
|
|
97
98
|
|
|
98
99
|
### Option 2: Fallback to Your Backend
|
|
@@ -183,7 +184,7 @@ permutations for out-of-stock, new-arrival, and discontinued.
|
|
|
183
184
|
- Spinners by delaying responses
|
|
184
185
|
- Setting up UI tests
|
|
185
186
|
|
|
186
|
-
###
|
|
187
|
+
### Demoing complex backend states
|
|
187
188
|
Sometimes, the ideal flow you need is too difficult to reproduce from the actual backend.
|
|
188
189
|
For this, you can **Bulk Select** mocks by comments to simulate the complete states
|
|
189
190
|
you want. For example, by adding `(demo-part1)`, `(demo-part2)` to the filenames.
|
|
@@ -307,8 +308,10 @@ want a `Content-Type` header in the response.
|
|
|
307
308
|
<br/>
|
|
308
309
|
|
|
309
310
|
### Dynamic parameters
|
|
310
|
-
Anything within square brackets is always matched.
|
|
311
|
-
|
|
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:
|
|
312
315
|
|
|
313
316
|
<pre><code>api/company/<b>[id]</b>/user/<b>[uid]</b>.GET.200.json</code></pre>
|
|
314
317
|
|
|
@@ -351,7 +354,7 @@ string it’s ignored anyway.
|
|
|
351
354
|
<br/>
|
|
352
355
|
|
|
353
356
|
### Index-like routes
|
|
354
|
-
If you have
|
|
357
|
+
If you have <a href="#">api/foo</a> and <a href="#">api/foo/bar</a>, you have two options:
|
|
355
358
|
|
|
356
359
|
**Option A.** Standard naming:
|
|
357
360
|
```
|
|
@@ -379,7 +382,7 @@ as explained above in the _Use Cases_ section.
|
|
|
379
382
|
|
|
380
383
|
Files under `config.staticDir` take precedence over corresponding
|
|
381
384
|
`GET` mocks in `config.mocksDir` (regardless of status code).
|
|
382
|
-
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:
|
|
383
386
|
<pre>
|
|
384
387
|
my-static-dir<b>/foo/bar.jpg</b> <span style="color:green"> // Wins</span>
|
|
385
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.21.
|
|
5
|
+
"version": "8.21.3",
|
|
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
|
@@ -21,6 +21,18 @@
|
|
|
21
21
|
--colorRed: #da0f00;
|
|
22
22
|
--colorText: #000;
|
|
23
23
|
}
|
|
24
|
+
.SyntaxHighlight {
|
|
25
|
+
color: var(--colorSecondaryAction);
|
|
26
|
+
.key {
|
|
27
|
+
color: #ed206a
|
|
28
|
+
}
|
|
29
|
+
.val {
|
|
30
|
+
color: #9b71e8
|
|
31
|
+
}
|
|
32
|
+
.string {
|
|
33
|
+
color: #3e8300
|
|
34
|
+
}
|
|
35
|
+
}
|
|
24
36
|
}
|
|
25
37
|
@media (prefers-color-scheme: dark) {
|
|
26
38
|
:root {
|
|
@@ -40,6 +52,18 @@
|
|
|
40
52
|
--colorRed: #f41606;
|
|
41
53
|
--colorText: #fff;
|
|
42
54
|
}
|
|
55
|
+
.SyntaxHighlight {
|
|
56
|
+
color: var(--colorSecondaryAction);
|
|
57
|
+
.key {
|
|
58
|
+
color: #f92672
|
|
59
|
+
}
|
|
60
|
+
.val {
|
|
61
|
+
color: #ae81ff
|
|
62
|
+
}
|
|
63
|
+
.string {
|
|
64
|
+
color: #a6e22e
|
|
65
|
+
}
|
|
66
|
+
}
|
|
43
67
|
}
|
|
44
68
|
|
|
45
69
|
html,
|
|
@@ -590,93 +614,3 @@ table {
|
|
|
590
614
|
transform: translateY(0);
|
|
591
615
|
}
|
|
592
616
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
/*
|
|
596
|
-
* Prism
|
|
597
|
-
*/
|
|
598
|
-
|
|
599
|
-
@media (prefers-color-scheme: dark) {
|
|
600
|
-
.token.cdata, .token.comment, .token.doctype, .token.prolog {
|
|
601
|
-
color: #8292a2
|
|
602
|
-
}
|
|
603
|
-
.token.punctuation {
|
|
604
|
-
color: #f8f8f2
|
|
605
|
-
}
|
|
606
|
-
.token.namespace {
|
|
607
|
-
opacity: .7
|
|
608
|
-
}
|
|
609
|
-
.token.constant, .token.deleted, .token.property, .token.symbol, .token.tag {
|
|
610
|
-
color: #f92672
|
|
611
|
-
}
|
|
612
|
-
.token.boolean, .token.number {
|
|
613
|
-
color: #ae81ff
|
|
614
|
-
}
|
|
615
|
-
.token.attr-name, .token.builtin, .token.char, .token.inserted, .token.selector, .token.string {
|
|
616
|
-
color: #a6e22e
|
|
617
|
-
}
|
|
618
|
-
.language-css .token.string, .style .token.string, .token.entity, .token.operator, .token.url, .token.variable {
|
|
619
|
-
color: #f8f8f2
|
|
620
|
-
}
|
|
621
|
-
.token.atrule, .token.attr-value, .token.class-name, .token.function {
|
|
622
|
-
color: #e6db74
|
|
623
|
-
}
|
|
624
|
-
.token.keyword {
|
|
625
|
-
color: #66d9ef
|
|
626
|
-
}
|
|
627
|
-
.token.important, .token.regex {
|
|
628
|
-
color: #fd971f
|
|
629
|
-
}
|
|
630
|
-
.token.bold, .token.important {
|
|
631
|
-
font-weight: 700
|
|
632
|
-
}
|
|
633
|
-
.token.italic {
|
|
634
|
-
font-style: italic
|
|
635
|
-
}
|
|
636
|
-
.token.entity {
|
|
637
|
-
cursor: help
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
@media (prefers-color-scheme: light) {
|
|
642
|
-
.token.cdata, .token.comment, .token.doctype, .token.prolog {
|
|
643
|
-
color: #708090
|
|
644
|
-
}
|
|
645
|
-
.token.punctuation {
|
|
646
|
-
color: #999
|
|
647
|
-
}
|
|
648
|
-
.token.namespace {
|
|
649
|
-
opacity: .7
|
|
650
|
-
}
|
|
651
|
-
.token.constant, .token.deleted, .token.property, .token.symbol, .token.tag {
|
|
652
|
-
color: #ed206a
|
|
653
|
-
}
|
|
654
|
-
.token.boolean, .token.number {
|
|
655
|
-
color: #9b71e8
|
|
656
|
-
}
|
|
657
|
-
.token.attr-name, .token.builtin, .token.char, .token.inserted, .token.selector, .token.string {
|
|
658
|
-
color: #3e8300
|
|
659
|
-
}
|
|
660
|
-
.language-css .token.string, .style .token.string, .token.entity, .token.operator, .token.url {
|
|
661
|
-
color: #9a6e3a;
|
|
662
|
-
background: hsla(0, 0%, 100%, .5)
|
|
663
|
-
}
|
|
664
|
-
.token.atrule, .token.attr-value, .token.keyword {
|
|
665
|
-
color: #07a
|
|
666
|
-
}
|
|
667
|
-
.token.class-name, .token.function {
|
|
668
|
-
color: #dd4a68
|
|
669
|
-
}
|
|
670
|
-
.token.important, .token.regex, .token.variable {
|
|
671
|
-
color: #e90
|
|
672
|
-
}
|
|
673
|
-
.token.bold, .token.important {
|
|
674
|
-
font-weight: 700
|
|
675
|
-
}
|
|
676
|
-
.token.italic {
|
|
677
|
-
font-style: italic
|
|
678
|
-
}
|
|
679
|
-
.token.entity {
|
|
680
|
-
cursor: help
|
|
681
|
-
}
|
|
682
|
-
}
|
package/src/Dashboard.html
CHANGED
|
@@ -10,7 +10,5 @@
|
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<script src="./mockaton/Dashboard.js" type="module"></script>
|
|
13
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js" data-manual integrity="sha512-7Z9J3l1+EYfeaPKcGXu3MS/7T+w19WtKQY/n+xzmw4hZhJ9tyYmcUS+4QqAlzhicE5LAfMQSF3iFTK9bQdTxXg==" crossorigin="anonymous" referrerpolicy="no-referrer" defer></script>
|
|
14
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js" integrity="sha512-QXFMVAusM85vUYDaNgcYeU3rzSlc+bTV4JvkfJhjxSHlQEo+ig53BtnGkvFTiNJh8D+wv6uWAQ2vJaVmxe8d3w==" crossorigin="anonymous" referrerpolicy="no-referrer" defer></script>
|
|
15
13
|
</body>
|
|
16
14
|
</html>
|
package/src/Dashboard.js
CHANGED
|
@@ -3,13 +3,6 @@ import { parseFilename } from './Filename.js'
|
|
|
3
3
|
import { Commander } from './Commander.js'
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
function syntaxHighlightJson(textBody) {
|
|
7
|
-
const prism = window.Prism
|
|
8
|
-
return prism?.highlight && prism?.languages?.json
|
|
9
|
-
? prism.highlight(textBody, prism.languages.json, 'json')
|
|
10
|
-
: false
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
const Strings = {
|
|
14
7
|
bulk_select: 'Bulk Select',
|
|
15
8
|
bulk_select_disabled_title: 'No mock files have comments, which are anything within parentheses on the filename.',
|
|
@@ -56,6 +49,7 @@ const CSS = {
|
|
|
56
49
|
ResetButton: null,
|
|
57
50
|
SaveProxiedCheckbox: null,
|
|
58
51
|
StaticFilesList: null,
|
|
52
|
+
SyntaxHighlight: null,
|
|
59
53
|
|
|
60
54
|
chosen: null,
|
|
61
55
|
dittoDir: null,
|
|
@@ -566,7 +560,7 @@ function PayloadViewer() {
|
|
|
566
560
|
r('div', className(CSS.PayloadViewer),
|
|
567
561
|
r('h2', { ref: payloadViewerTitleRef }, Strings.preview),
|
|
568
562
|
r('pre', null,
|
|
569
|
-
r('code', { ref: payloadViewerRef }, Strings.click_link_to_preview))))
|
|
563
|
+
r('code', { ref: payloadViewerRef, className: CSS.SyntaxHighlight }, Strings.click_link_to_preview))))
|
|
570
564
|
}
|
|
571
565
|
|
|
572
566
|
function PayloadViewerProgressBar() {
|
|
@@ -846,3 +840,27 @@ function dittoSplitPaths(paths) {
|
|
|
846
840
|
]
|
|
847
841
|
console.assert(JSON.stringify(dittoSplitPaths(input)) === JSON.stringify(expected))
|
|
848
842
|
}())
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
function syntaxHighlightJson(textBody) {
|
|
847
|
+
return textBody.replace(
|
|
848
|
+
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(\.\d+)?)/g,
|
|
849
|
+
match => {
|
|
850
|
+
if (/^".*":$/.test(match))
|
|
851
|
+
return `<span class="key">${escapeHTML(match.slice(0, -1))}</span>:`
|
|
852
|
+
|
|
853
|
+
return /^"/.test(match)
|
|
854
|
+
? `<span class="string">${escapeHTML(match)}</span>`
|
|
855
|
+
: `<span class="val">${match}</span>`
|
|
856
|
+
}
|
|
857
|
+
)
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function escapeHTML(str) {
|
|
861
|
+
return str.replace(/&/g, '&')
|
|
862
|
+
.replace(/</g, '<')
|
|
863
|
+
.replace(/>/g, '>')
|
|
864
|
+
.replace(/"/g, '"')
|
|
865
|
+
.replace(/'/g, ''')
|
|
866
|
+
}
|