mockaton 0.10.0 → 0.10.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 +18 -24
- package/index.d.ts +1 -3
- package/package.json +1 -1
- package/README-dashboard-dropdown.png +0 -0
- package/README-mocks-with-comments.png +0 -0
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Mockaton
|
|
2
2
|
_Mockaton_ is a mock server for developing and testing frontends.
|
|
3
3
|
|
|
4
|
-
It scans `Config.mocksDir` for files following a specific
|
|
5
|
-
|
|
4
|
+
It scans `Config.mocksDir` for files following a specific
|
|
5
|
+
file name convention, which is similar to the URL paths. For
|
|
6
6
|
example, the following file will be served for `/api/user/1234`
|
|
7
7
|
```
|
|
8
8
|
my-mocks-dir/api/user/[user-id].GET.200.json
|
|
@@ -15,14 +15,21 @@ be used for downloading a TAR of your XHR requests following that convention.
|
|
|
15
15
|
|
|
16
16
|
### Mock Variants
|
|
17
17
|
Each route can have many mocks, which could either be:
|
|
18
|
-
- Different response
|
|
19
|
-
-
|
|
18
|
+
- Different response __status code__.
|
|
19
|
+
- e.g. for testing error responses. BTW, an _Internal Server
|
|
20
|
+
Error_ mock is autogenerated for routes that have no 500.
|
|
21
|
+
- __Comment__ on the filename, which is anything within parentheses.
|
|
22
|
+
- e.g. `api/user(my-comment).POST.201.json`
|
|
20
23
|
|
|
21
24
|
Those alternatives can be manually selected in the dashboard
|
|
22
25
|
UI, or programmatically, for instance, for setting up tests.
|
|
23
26
|
|
|
24
27
|
About the default mock file, the first file in **alphabetical order** wins.
|
|
25
28
|
|
|
29
|
+
### Proxying Routes
|
|
30
|
+
`Config.proxyFallback` lets you specify a target
|
|
31
|
+
server for serving routes you don’t have mocks for.
|
|
32
|
+
|
|
26
33
|
|
|
27
34
|
## Getting Started
|
|
28
35
|
The best way to learn _Mockaton_ is by checking out this repo and
|
|
@@ -32,20 +39,6 @@ exploring its [sample-mocks/](./sample-mocks) directory. Then, run
|
|
|
32
39
|

|
|
33
40
|
|
|
34
41
|
|
|
35
|
-
### Mock Variants of Status Code
|
|
36
|
-
The **sample-mocks/** directory has three mock alternatives for serving
|
|
37
|
-
`/api/user/friends`:
|
|
38
|
-
- _200 - OK_
|
|
39
|
-
- _204 - No Content_ with an empty list of friends
|
|
40
|
-
- _500 - Internal Server Error_
|
|
41
|
-
- BTW, 500 mocks get autogenerated for routes that have no 500’s.
|
|
42
|
-
|
|
43
|
-

|
|
44
|
-
|
|
45
|
-
### Mock Variants with Comments
|
|
46
|
-
Comments are anything within parentheses, including them.
|
|
47
|
-

|
|
48
|
-
|
|
49
42
|
## Delay 🕓
|
|
50
43
|
The clock icon next to the mock selector is a checkbox for delaying a
|
|
51
44
|
particular response. They are handy for testing spinners.
|
|
@@ -61,11 +54,11 @@ npm install mockaton
|
|
|
61
54
|
Create a `my-mockaton.js` file
|
|
62
55
|
```js
|
|
63
56
|
import { resolve } from 'node:path'
|
|
64
|
-
import { Mockaton } from '
|
|
57
|
+
import { Mockaton } from 'mockaton'
|
|
65
58
|
|
|
66
|
-
Mockaton({
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
Mockaton({
|
|
60
|
+
mocksDir: resolve('my-mocks-dir'),
|
|
61
|
+
port: 2345
|
|
69
62
|
})
|
|
70
63
|
```
|
|
71
64
|
|
|
@@ -81,10 +74,10 @@ interface Config {
|
|
|
81
74
|
host?: string, // 'localhost'
|
|
82
75
|
port?: number // 0 auto-assigned
|
|
83
76
|
delay?: number // 1200 ms
|
|
84
|
-
cookies
|
|
77
|
+
cookies?: object
|
|
85
78
|
database?: object // for "Transforms"
|
|
86
79
|
skipOpen?: boolean // Prevents opening the dashboard in a browser
|
|
87
|
-
|
|
80
|
+
proxyFallback?: string // e.g. http://localhost:9999 Target for relaying routes without mocks
|
|
88
81
|
allowedExt?: RegExp // /\.(json|txt|md|mjs)$/ Just for excluding temporary editor files (e.g. JetBrains appends a ~)
|
|
89
82
|
}
|
|
90
83
|
```
|
|
@@ -102,6 +95,7 @@ Config.cookies = {
|
|
|
102
95
|
})
|
|
103
96
|
}
|
|
104
97
|
```
|
|
98
|
+
The key is just a label used in dashboard for selecting the desired cookie.
|
|
105
99
|
|
|
106
100
|
That `jwtCookie` has a hardcoded header and signature. In other
|
|
107
101
|
words, it’s useful iff you care about its payload in the frontend.
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|