mockaton 0.10.0 → 0.10.2

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
@@ -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 directory
5
- and file name convention, which is similar to the URL paths. For
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,13 +15,20 @@ 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 status code. For example, for testing error responses.
19
- - Comment on the filename, which is anything within parentheses.
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
- About the default mock file, the first file in **alphabetical order** wins.
27
+ The first file in **alphabetical order** becomes the default mock.
28
+
29
+ ### Proxying Routes
30
+ `Config.proxyFallback` lets you specify a target
31
+ server for serving routes you don’t have mocks for.
25
32
 
26
33
 
27
34
  ## Getting Started
@@ -32,25 +39,11 @@ exploring its [sample-mocks/](./sample-mocks) directory. Then, run
32
39
  ![](./README-dashboard.png)
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
- ![](./README-dashboard-dropdown.png)
44
-
45
- ### Mock Variants with Comments
46
- Comments are anything within parentheses, including them.
47
- ![](./README-mocks-with-comments.png)
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.
52
45
 
53
- The milliseconds for the delay is globally configurable via `Config.delay = 1200`
46
+ The delay is globally configurable via `Config.delay = 1200` (milliseconds).
54
47
 
55
48
  ---
56
49
 
@@ -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 'src/Mockaton'
57
+ import { Mockaton } from 'mockaton'
65
58
 
66
- Mockaton({ // Config options
67
- port: 2345,
68
- mocksDir: resolve('my-mocks-dir')
59
+ Mockaton({
60
+ mocksDir: resolve('my-mocks-dir'),
61
+ port: 2345
69
62
  })
70
63
  ```
71
64
 
@@ -81,17 +74,17 @@ interface Config {
81
74
  host?: string, // 'localhost'
82
75
  port?: number // 0 auto-assigned
83
76
  delay?: number // 1200 ms
84
- cookies?(): object
77
+ cookies?: object
85
78
  database?: object // for "Transforms"
86
79
  skipOpen?: boolean // Prevents opening the dashboard in a browser
87
- proxyFallback?: string // e.g. http://localhost:9999 For relaying routes without mocks
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
  ```
91
84
 
92
85
  ## Cookies
93
86
  ```js
94
- import { jwtCookie } from 'src/Mockaton'
87
+ import { jwtCookie } from 'mockaton'
95
88
 
96
89
  Config.cookies = {
97
90
  'My Admin User': 'my-cookie=1;Path=/;SameSite=strict',
@@ -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
@@ -6,9 +6,7 @@ interface Config {
6
6
  host?: string,
7
7
  port?: number
8
8
  delay?: number
9
-
10
- cookies?(): object
11
-
9
+ cookies?: object
12
10
  database?: object
13
11
  skipOpen?: boolean
14
12
  proxyFallback?: 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": "0.10.0",
5
+ "version": "0.10.2",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
Binary file
Binary file