mockaton 8.8.0 → 8.8.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 +17 -15
- package/package.json +1 -1
- package/src/Dashboard.js +26 -97
package/README.md
CHANGED
|
@@ -15,12 +15,27 @@ For example, for `/api/user/1234` the mock filename would be:
|
|
|
15
15
|
my-mocks-dir/api/user/[user-id].GET.200.json
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
## Dashboard
|
|
20
|
+
In the dashboard you can select a mock variant for a particular route, among
|
|
21
|
+
other features such as delaying responses, or triggering an autogenerated
|
|
22
|
+
`500` (Internal Server Error). Nonetheless, there’s a programmatic API,
|
|
23
|
+
which is handy for setting up tests (see **Commander API** below).
|
|
24
|
+
|
|
25
|
+
<picture>
|
|
26
|
+
<source media="(prefers-color-scheme: light)" srcset="./pixaton-tests/pic-for-readme.vp860x800.light.gold.png">
|
|
27
|
+
<source media="(prefers-color-scheme: dark)" srcset="./pixaton-tests/pic-for-readme.vp860x800.dark.gold.png">
|
|
28
|
+
<img alt="Mockaton Dashboard" src="./pixaton-tests/pic-for-readme.vp860x800.light.gold.png">
|
|
29
|
+
</picture>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
18
33
|
## No Need to Mock Everything
|
|
19
34
|
Mockaton can fallback to your real backend on routes you don’t have mocks
|
|
20
35
|
for. For that, type your backend address in the **Fallback Backend** field.
|
|
21
36
|
|
|
22
|
-
Similarly, if already have mocks for a route you can check the
|
|
23
|
-
checkbox** and
|
|
37
|
+
Similarly, if you already have mocks for a route you can check the
|
|
38
|
+
☁️ **Cloud checkbox** and that route will be requested from your backend.
|
|
24
39
|
|
|
25
40
|
|
|
26
41
|
## Scrapping Mocks from you Backend
|
|
@@ -43,19 +58,6 @@ For instance, you can have mocks with a `4xx` or `5xx` status code for triggerin
|
|
|
43
58
|
error responses. Or with a `204` (No Content) for testing empty collections.
|
|
44
59
|
|
|
45
60
|
|
|
46
|
-
## Dashboard
|
|
47
|
-
In the dashboard you can select a mock variant for a particular route, among
|
|
48
|
-
other features such as delaying responses, or triggering an autogenerated
|
|
49
|
-
`500` (Internal Server Error). Nonetheless, there’s a programmatic API,
|
|
50
|
-
which is handy for setting up tests (see **Commander API** below).
|
|
51
|
-
|
|
52
|
-
<picture>
|
|
53
|
-
<source media="(prefers-color-scheme: light)" srcset="./pixaton-tests/pic-for-readme.vp860x800.light.gold.png">
|
|
54
|
-
<source media="(prefers-color-scheme: dark)" srcset="./pixaton-tests/pic-for-readme.vp860x800.dark.gold.png">
|
|
55
|
-
<img alt="Mockaton Dashboard" src="./pixaton-tests/pic-for-readme.vp860x800.light.gold.png">
|
|
56
|
-
</picture>
|
|
57
|
-
|
|
58
|
-
|
|
59
61
|
|
|
60
62
|
## Basic Usage
|
|
61
63
|
`tsx` is only needed if you want to write mocks in TypeScript.
|
package/package.json
CHANGED
package/src/Dashboard.js
CHANGED
|
@@ -21,6 +21,7 @@ const Strings = {
|
|
|
21
21
|
empty_response_body: '/* Empty Response Body */',
|
|
22
22
|
fallback_server: 'Fallback Backend',
|
|
23
23
|
fallback_server_placeholder: 'Type Server Address',
|
|
24
|
+
got: 'Got',
|
|
24
25
|
internal_server_error: 'Internal Server Error',
|
|
25
26
|
mock: 'Mock',
|
|
26
27
|
no_mocks_found: 'No mocks found',
|
|
@@ -396,14 +397,21 @@ function PayloadViewerProgressBar() {
|
|
|
396
397
|
r('div', { style: { animationDuration: '1000ms' } }))) // TODO from Config.delay - 180
|
|
397
398
|
}
|
|
398
399
|
|
|
399
|
-
function PayloadViewerTitle({ file }) {
|
|
400
|
-
const { urlMask, method,
|
|
400
|
+
function PayloadViewerTitle({ file, status, statusText }) {
|
|
401
|
+
const { urlMask, method, ext } = parseFilename(file)
|
|
401
402
|
return (
|
|
402
403
|
r('span', null,
|
|
403
404
|
urlMask + '.' + method + '.',
|
|
404
|
-
r('abbr', { title:
|
|
405
|
+
r('abbr', { title: statusText }, status),
|
|
405
406
|
'.' + ext))
|
|
406
407
|
}
|
|
408
|
+
function PayloadViewerTitleWhenProxied({ mime, status, statusText }) {
|
|
409
|
+
return (
|
|
410
|
+
r('span', null,
|
|
411
|
+
Strings.got + ' ',
|
|
412
|
+
r('abbr', { title: statusText }, status),
|
|
413
|
+
' ' + mime))
|
|
414
|
+
}
|
|
407
415
|
|
|
408
416
|
async function previewMock(method, urlMask, href) {
|
|
409
417
|
const timer = setTimeout(renderProgressBar, 180)
|
|
@@ -417,10 +425,22 @@ async function previewMock(method, urlMask, href) {
|
|
|
417
425
|
}
|
|
418
426
|
|
|
419
427
|
async function updatePayloadViewer(method, urlMask, response) {
|
|
420
|
-
payloadViewerTitleRef.current.replaceChildren(
|
|
421
|
-
PayloadViewerTitle({ file: mockSelectorFor(method, urlMask).value }))
|
|
422
|
-
|
|
423
428
|
const mime = response.headers.get('content-type') || ''
|
|
429
|
+
|
|
430
|
+
const file = mockSelectorFor(method, urlMask).value
|
|
431
|
+
if (file === Strings.proxied)
|
|
432
|
+
payloadViewerTitleRef.current.replaceChildren(PayloadViewerTitleWhenProxied({
|
|
433
|
+
status: response.status,
|
|
434
|
+
statusText: response.statusText,
|
|
435
|
+
mime
|
|
436
|
+
}))
|
|
437
|
+
else
|
|
438
|
+
payloadViewerTitleRef.current.replaceChildren(PayloadViewerTitle({
|
|
439
|
+
status: response.status,
|
|
440
|
+
statusText: response.statusText,
|
|
441
|
+
file
|
|
442
|
+
}))
|
|
443
|
+
|
|
424
444
|
if (mime.startsWith('image/')) { // Naively assumes GET.200
|
|
425
445
|
payloadViewerRef.current.replaceChildren(
|
|
426
446
|
r('img', {
|
|
@@ -447,9 +467,6 @@ function trFor(method, urlMask) {
|
|
|
447
467
|
function linkFor(method, urlMask) {
|
|
448
468
|
return trFor(method, urlMask)?.querySelector(`a.${CSS.PreviewLink}`)
|
|
449
469
|
}
|
|
450
|
-
function checkbox500For(method, urlMask) {
|
|
451
|
-
return trFor(method, urlMask)?.querySelector(`.${CSS.InternalServerErrorToggler} > input`)
|
|
452
|
-
}
|
|
453
470
|
function mockSelectorFor(method, urlMask) {
|
|
454
471
|
return trFor(method, urlMask)?.querySelector(`select.${CSS.MockSelector}`)
|
|
455
472
|
}
|
|
@@ -540,91 +557,3 @@ function createSvgElement(tagName, props, ...children) {
|
|
|
540
557
|
function useRef() {
|
|
541
558
|
return { current: null }
|
|
542
559
|
}
|
|
543
|
-
|
|
544
|
-
const HttpStatus = {
|
|
545
|
-
100: 'Continue',
|
|
546
|
-
101: 'Switching Protocols',
|
|
547
|
-
102: 'Processing',
|
|
548
|
-
103: 'Early Hints',
|
|
549
|
-
200: 'OK',
|
|
550
|
-
201: 'Created',
|
|
551
|
-
202: 'Accepted',
|
|
552
|
-
203: 'Non-Authoritative Information',
|
|
553
|
-
204: 'No Content',
|
|
554
|
-
205: 'Reset Content',
|
|
555
|
-
206: 'Partial Content',
|
|
556
|
-
207: 'Multi-Status',
|
|
557
|
-
208: 'Already Reported',
|
|
558
|
-
218: 'This is fine (Apache Web Server)',
|
|
559
|
-
226: 'IM Used',
|
|
560
|
-
300: 'Multiple Choices',
|
|
561
|
-
301: 'Moved Permanently',
|
|
562
|
-
302: 'Found',
|
|
563
|
-
303: 'See Other',
|
|
564
|
-
304: 'Not Modified',
|
|
565
|
-
306: 'Switch Proxy',
|
|
566
|
-
307: 'Temporary Redirect',
|
|
567
|
-
308: 'Resume Incomplete',
|
|
568
|
-
400: 'Bad Request',
|
|
569
|
-
401: 'Unauthorized',
|
|
570
|
-
402: 'Payment Required',
|
|
571
|
-
403: 'Forbidden',
|
|
572
|
-
404: 'Not Found',
|
|
573
|
-
405: 'Method Not Allowed',
|
|
574
|
-
406: 'Not Acceptable',
|
|
575
|
-
407: 'Proxy Authentication Required',
|
|
576
|
-
408: 'Request Timeout',
|
|
577
|
-
409: 'Conflict',
|
|
578
|
-
410: 'Gone',
|
|
579
|
-
411: 'Length Required',
|
|
580
|
-
412: 'Precondition Failed',
|
|
581
|
-
413: 'Request Entity Too Large',
|
|
582
|
-
414: 'Request-URI Too Long',
|
|
583
|
-
415: 'Unsupported Media Type',
|
|
584
|
-
416: 'Requested Range Not Satisfiable',
|
|
585
|
-
417: 'Expectation Failed',
|
|
586
|
-
418: 'I’m a teapot',
|
|
587
|
-
419: 'Page Expired (Laravel Framework)',
|
|
588
|
-
420: 'Method Failure (Spring Framework)',
|
|
589
|
-
421: 'Misdirected Request',
|
|
590
|
-
422: 'Unprocessable Entity',
|
|
591
|
-
423: 'Locked',
|
|
592
|
-
424: 'Failed Dependency',
|
|
593
|
-
426: 'Upgrade Required',
|
|
594
|
-
428: 'Precondition Required',
|
|
595
|
-
429: 'Too Many Requests',
|
|
596
|
-
431: 'Request Header Fields Too Large',
|
|
597
|
-
440: 'Login Time-out',
|
|
598
|
-
444: 'Connection Closed Without Response',
|
|
599
|
-
449: 'Retry With',
|
|
600
|
-
450: 'Blocked by Windows Parental Controls',
|
|
601
|
-
451: 'Unavailable For Legal Reasons',
|
|
602
|
-
494: 'Request Header Too Large',
|
|
603
|
-
495: 'SSL Certificate Error',
|
|
604
|
-
496: 'SSL Certificate Required',
|
|
605
|
-
497: 'HTTP Request Sent to HTTPS Port',
|
|
606
|
-
498: 'Invalid Token (Esri)',
|
|
607
|
-
499: 'Client Closed Request',
|
|
608
|
-
500: 'Internal Server Error',
|
|
609
|
-
501: 'Not Implemented',
|
|
610
|
-
502: 'Bad Gateway',
|
|
611
|
-
503: 'Service Unavailable',
|
|
612
|
-
504: 'Gateway Timeout',
|
|
613
|
-
505: 'HTTP Version Not Supported',
|
|
614
|
-
506: 'Variant Also Negotiates',
|
|
615
|
-
507: 'Insufficient Storage',
|
|
616
|
-
508: 'Loop Detected',
|
|
617
|
-
509: 'Bandwidth Limit Exceeded',
|
|
618
|
-
510: 'Not Extended',
|
|
619
|
-
511: 'Network Authentication Required',
|
|
620
|
-
520: 'Unknown Error',
|
|
621
|
-
521: 'Web Server Is Down',
|
|
622
|
-
522: 'Connection Timed Out',
|
|
623
|
-
523: 'Origin Is Unreachable',
|
|
624
|
-
524: 'A Timeout Occurred',
|
|
625
|
-
525: 'SSL Handshake Failed',
|
|
626
|
-
526: 'Invalid SSL Certificate',
|
|
627
|
-
527: 'Railgun Listener to Origin Error',
|
|
628
|
-
530: 'Origin DNS Error',
|
|
629
|
-
598: 'Network Read Timeout Error'
|
|
630
|
-
}
|