mockaton 0.10.1 → 0.10.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 CHANGED
@@ -16,7 +16,7 @@ be used for downloading a TAR of your XHR requests following that convention.
16
16
  ### Mock Variants
17
17
  Each route can have many mocks, which could either be:
18
18
  - Different response __status code__.
19
- - e.g. for testing error responses. BTW, an _Internal Server
19
+ - e.g. for testing error responses. As a side note, an _Internal Server
20
20
  Error_ mock is autogenerated for routes that have no 500.
21
21
  - __Comment__ on the filename, which is anything within parentheses.
22
22
  - e.g. `api/user(my-comment).POST.201.json`
@@ -24,7 +24,7 @@ Each route can have many mocks, which could either be:
24
24
  Those alternatives can be manually selected in the dashboard
25
25
  UI, or programmatically, for instance, for setting up tests.
26
26
 
27
- About the default mock file, the first file in **alphabetical order** wins.
27
+ The first file in **alphabetical order** becomes the default mock.
28
28
 
29
29
  ### Proxying Routes
30
30
  `Config.proxyFallback` lets you specify a target
@@ -43,7 +43,7 @@ exploring its [sample-mocks/](./sample-mocks) directory. Then, run
43
43
  The clock icon next to the mock selector is a checkbox for delaying a
44
44
  particular response. They are handy for testing spinners.
45
45
 
46
- The milliseconds for the delay is globally configurable via `Config.delay = 1200`
46
+ The delay is globally configurable via `Config.delay = 1200` (milliseconds).
47
47
 
48
48
  ---
49
49
 
@@ -57,8 +57,8 @@ import { resolve } from 'node:path'
57
57
  import { Mockaton } from 'mockaton'
58
58
 
59
59
  Mockaton({
60
- mocksDir: resolve('my-mocks-dir'),
61
- port: 2345
60
+ mocksDir: resolve('my-mocks-dir'),
61
+ port: 2345
62
62
  })
63
63
  ```
64
64
 
@@ -71,9 +71,9 @@ node my-mockaton.js
71
71
  interface Config {
72
72
  mocksDir: string
73
73
  staticDir?: string
74
- host?: string, // 'localhost'
75
- port?: number // 0 auto-assigned
76
- delay?: number // 1200 ms
74
+ host?: string, // defaults to 'localhost'
75
+ port?: number // defaults to 0, which means auto-assigned
76
+ delay?: number // defaults to 1200 (ms)
77
77
  cookies?: object
78
78
  database?: object // for "Transforms"
79
79
  skipOpen?: boolean // Prevents opening the dashboard in a browser
@@ -84,7 +84,7 @@ interface Config {
84
84
 
85
85
  ## Cookies
86
86
  ```js
87
- import { jwtCookie } from 'src/Mockaton'
87
+ import { jwtCookie } from 'mockaton'
88
88
 
89
89
  Config.cookies = {
90
90
  'My Admin User': 'my-cookie=1;Path=/;SameSite=strict',
@@ -95,10 +95,10 @@ Config.cookies = {
95
95
  })
96
96
  }
97
97
  ```
98
- The key is just a label used in dashboard for selecting the desired cookie.
98
+ The key is just a label used for selecting a particular cookie in the dashboard.
99
99
 
100
- That `jwtCookie` has a hardcoded header and signature. In other
101
- words, it’s useful iff you care about its payload in the frontend.
100
+ `jwtCookie` has a hardcoded header and signature. In other
101
+ words, it’s useful if you only care about its payload.
102
102
 
103
103
  ---
104
104
 
@@ -115,7 +115,7 @@ The `Config.allowedExt` regex defaults to: `/\.(json|txt|md|mjs)$/`
115
115
 
116
116
 
117
117
  ### Dynamic Parameters
118
- Anything within square brackets. For example,
118
+ Anything within square brackets. For example:
119
119
  <pre>
120
120
  api/user/<b>[id]</b>/<b>[age]</b>.GET.200.json
121
121
  </pre>
@@ -134,10 +134,10 @@ api/foo.GET.200.json
134
134
  api/video<b>?limit=[limit]</b>.GET.200.json
135
135
  </pre>
136
136
 
137
- The query string is ignored when routing to it. It’s
138
- only used for documenting the URL API contract.
137
+ The query string is ignored when routing to it. In other words, it’s
138
+ only used for documenting the URL contract.
139
139
 
140
- BTW, in Windows, filenames containing "?" are [not
140
+ Speaking of which, in Windows, filenames containing "?" are [not
141
141
  permitted](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file),
142
142
  but since that’s part of the query string, it’s ignored anyway.
143
143
 
@@ -155,7 +155,7 @@ api/foo/(my comment).GET.200.json
155
155
 
156
156
  ## Documenting Contracts (.md)
157
157
  This is handy for documenting request payload parameters. The dashboard will
158
- print the markdown document (as plain text) above the actual payload content.
158
+ print the Markdown document (as plain text) above the actual payload content.
159
159
 
160
160
  Create a markdown file following the same filename convention.
161
161
  The status code can be any number. For example,
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.1",
5
+ "version": "0.10.3",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Dashboard.js CHANGED
@@ -341,7 +341,5 @@ function createSvgElement(tagName, props, ...children) {
341
341
  }
342
342
 
343
343
  function useRef() {
344
- return {
345
- currentMock: null
346
- }
344
+ return { current: null }
347
345
  }
@@ -23,7 +23,7 @@ export async function dispatchMock(req, response) {
23
23
  if (Config.proxyFallback)
24
24
  await proxy(req, response)
25
25
  else
26
- sendNotFound(response) // TESTME
26
+ sendNotFound(response) // TODO unit TESTME
27
27
  return
28
28
  }
29
29
 
@@ -59,7 +59,7 @@ const nonSafeMethods = ['PATCH', 'POST', 'PUT', 'DELETE', 'CONNECT']
59
59
 
60
60
  async function requestBodyForTransform(req, mockAsText) {
61
61
  if (nonSafeMethods.includes(req.method))
62
- return req.headers[DF.isForDashboard] // TESTME
62
+ return req.headers[DF.isForDashboard] // TODO unit TESTME
63
63
  ? JSON.parse(mockAsText)
64
64
  : await parseJSON(req)
65
65
  return ''