mockaton 11.1.0 → 11.1.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
@@ -267,6 +267,7 @@ export default defineConfig({
267
267
  mocksDir: 'mockaton-mocks',
268
268
  staticDir: 'mockaton-static-mocks',
269
269
  ignore: /(\.DS_Store|~)$/,
270
+ watcherEnabled: true,
270
271
 
271
272
  host: '127.0.0.1',
272
273
  port: 0,
@@ -297,8 +298,7 @@ export default defineConfig({
297
298
  [/\.(js|ts)$/, jsToJsonPlugin]
298
299
  ],
299
300
 
300
- onReady: await openInBrowser,
301
- watcherEnabled: true
301
+ onReady: await openInBrowser
302
302
  })
303
303
  ```
304
304
 
@@ -329,13 +329,26 @@ my-static-dir<b>/foo/bar.jpg</b> <span style="color:green"> // Wins</span>
329
329
  <br/>
330
330
 
331
331
  ### `ignore?: RegExp`
332
- Defaults to `/(\.DS_Store|~)$/`. The regex rule is
333
- tested against the basename (filename without directory path).
332
+ Defaults to `/(\.DS_Store|~)$/`
333
+
334
+ The regex rule is tested against the basename (filename without directory path).
334
335
 
335
336
 
336
337
  <br/>
337
338
 
338
339
 
340
+ ### `watcherEnabled?: boolean`
341
+ Defaults to `true`
342
+
343
+ When `false`, if you **add**, **delete**, or **rename** you’ll need to click **"Reset"**
344
+ on the Dashboard, or call `commander.reset()` in order to re-initialize the collection.
345
+
346
+ On the other hand, **edits are not affected by this
347
+ flag**; mocks are always read from disk on every request.
348
+
349
+ <br/>
350
+
351
+
339
352
  ### `host?: string`
340
353
  Defaults to `'127.0.0.1'`
341
354
 
@@ -549,13 +562,6 @@ Defaults to `'normal'`.
549
562
  - `normal`: info, mock access, warnings, and errors
550
563
  - `verbose`: normal + API access
551
564
 
552
- <br/>
553
-
554
-
555
- ### `watcherEnabled?: boolean`
556
- Defaults to `true`. When `true`, newly added mocks get registered,
557
- or unregistered when deleting them.
558
-
559
565
  </details>
560
566
 
561
567
 
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Server, IncomingMessage, OutgoingMessage } from 'node:http'
2
2
 
3
- type Plugin = (
3
+ export type Plugin = (
4
4
  filePath: string,
5
5
  request: IncomingMessage,
6
6
  response: OutgoingMessage
@@ -9,10 +9,11 @@ type Plugin = (
9
9
  body: string | Uint8Array
10
10
  }>
11
11
 
12
- interface Config {
12
+ export interface Config {
13
13
  mocksDir?: string
14
14
  staticDir?: string
15
15
  ignore?: RegExp
16
+ watcherEnabled?: boolean
16
17
 
17
18
  host?: string,
18
19
  port?: number
@@ -42,8 +43,6 @@ interface Config {
42
43
  plugins?: [filenameTester: RegExp, plugin: Plugin][]
43
44
 
44
45
  onReady?: (address: string) => void
45
-
46
- watcherEnabled?: boolean
47
46
  }
48
47
 
49
48
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "HTTP Mock Server",
4
4
  "type": "module",
5
- "version": "11.1.0",
5
+ "version": "11.1.2",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
@@ -13,7 +13,7 @@ export class Commander {
13
13
  getState = () =>
14
14
  fetch(this.#addr + API.state)
15
15
 
16
- /**
16
+ /**
17
17
  * @param {number?} currSyncVer - On mismatch, it responds immediately. Otherwise, long polls.
18
18
  * @param {AbortSignal} abortSignal
19
19
  * @returns {JsonPromise<number>}
@@ -24,8 +24,8 @@ export class Commander {
24
24
  abortSignal,
25
25
  AbortSignal.timeout(LONG_POLL_SERVER_TIMEOUT + 1000)
26
26
  ].filter(Boolean)),
27
- headers: currSyncVer !== undefined
28
- ? { [HEADER_SYNC_VERSION]: currSyncVer }
27
+ headers: currSyncVer !== undefined
28
+ ? { [HEADER_SYNC_VERSION]: currSyncVer }
29
29
  : {}
30
30
  })
31
31
 
@@ -45,12 +45,24 @@ export class Commander {
45
45
  setProxyFallback = proxyAddr => this.#patch(API.fallback, proxyAddr)
46
46
  setCollectProxied = shouldCollect => this.#patch(API.collectProxied, shouldCollect)
47
47
 
48
- select = file => this.#patch(API.select, file)
49
- bulkSelectByComment = comment => this.#patch(API.bulkSelect, comment)
48
+ /** @returns {JsonPromise<ClientMockBroker>} */
49
+ select = file =>
50
+ this.#patch(API.select, file)
50
51
 
51
- toggle500 = (method, urlMask) => this.#patch(API.toggle500, [method, urlMask])
52
- setRouteIsProxied = (method, urlMask, proxied) => this.#patch(API.proxied, [method, urlMask, proxied])
53
- setRouteIsDelayed = (method, urlMask, delayed) => this.#patch(API.delay, [method, urlMask, delayed])
52
+ bulkSelectByComment = comment =>
53
+ this.#patch(API.bulkSelect, comment)
54
+
55
+ /** @returns {JsonPromise<ClientMockBroker>} */
56
+ toggle500 = (method, urlMask) =>
57
+ this.#patch(API.toggle500, [method, urlMask])
58
+
59
+ /** @returns {JsonPromise<ClientMockBroker>} */
60
+ setRouteIsProxied = (method, urlMask, proxied) =>
61
+ this.#patch(API.proxied, [method, urlMask, proxied])
62
+
63
+ /** @returns {JsonPromise<ClientMockBroker>} */
64
+ setRouteIsDelayed = (method, urlMask, delayed) =>
65
+ this.#patch(API.delay, [method, urlMask, delayed])
54
66
 
55
67
  setStaticRouteStatus = (urlMask, status) => this.#patch(API.staticStatus, [urlMask, status])
56
68
  setStaticRouteIsDelayed = (urlMask, delayed) => this.#patch(API.delayStatic, [urlMask, delayed])
package/src/Dashboard.css CHANGED
@@ -15,7 +15,7 @@
15
15
  --colorSecondaryActionBorder: #ddd;
16
16
  --colorSecondaryAction: #666;
17
17
  --colorDisabledMockSelector: #444;
18
- --colorHover: #dfefff;
18
+ --colorHover: rgba(119, 193, 255, 0.5);
19
19
  --colorLabel: #555;
20
20
  --colorLightRed: #ffe4ee;
21
21
  --colorRed: #da0f00;
@@ -37,7 +37,7 @@
37
37
  --colorSecondaryAction: #aaa;
38
38
  --colorComboBoxHeaderBackground: #222;
39
39
  --colorDisabledMockSelector: #b9b9b9;
40
- --colorHover: #023661;
40
+ --colorHover: rgba(0, 63, 115, 0.5);
41
41
  --colorLabel: #aaa;
42
42
  --colorLightRed: #ffe4ee;
43
43
  --colorRed: #f41606;
@@ -76,29 +76,35 @@ body {
76
76
  scrollbar-width: thin;
77
77
  }
78
78
 
79
- select, a, input, button {
80
- cursor: pointer;
81
-
79
+ a,
80
+ input,
81
+ select,
82
+ button {
82
83
  &:focus-visible {
84
+ outline-offset: -1px;
83
85
  outline: 2px solid var(--colorAccent);
84
86
  }
85
87
  }
86
88
 
87
- a {
88
- text-decoration: none;
89
+ a,
90
+ select,
91
+ button,
92
+ input[type=checkbox] {
93
+ cursor: pointer;
94
+
95
+ &:active {
96
+ cursor: grabbing;
97
+ }
89
98
  }
90
99
 
91
- a:active,
92
- button:active,
93
- input[type=checkbox]:active {
94
- cursor: grabbing;
100
+ a {
101
+ text-decoration: none;
95
102
  }
96
103
 
97
104
  select {
98
105
  border: 1px solid transparent;
99
106
  font-size: 100%;
100
107
  color: var(--colorText);
101
- cursor: pointer;
102
108
  border-radius: var(--radius);
103
109
  appearance: none;
104
110
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23888888'><path d='M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z'/></svg>") no-repeat;
@@ -110,7 +116,6 @@ select {
110
116
  background-color: var(--colorSecondaryButtonBackground);
111
117
  &:hover {
112
118
  border-color: var(--colorHover);
113
- cursor: pointer;
114
119
  background-color: var(--colorHover);
115
120
  }
116
121
  }
@@ -247,7 +252,6 @@ header {
247
252
  border: 1px solid var(--colorRed);
248
253
  margin-right: 8px;
249
254
  margin-left: 4px;
250
- outline-offset: 1px;
251
255
  background: transparent;
252
256
  border-radius: 50px;
253
257
  color: var(--colorRed);
package/src/Dashboard.js CHANGED
@@ -139,12 +139,11 @@ function GlobalDelayField() {
139
139
  }
140
140
 
141
141
  function BulkSelector() {
142
- // TODO For a11y, this should be a `menu` instead of this `select`
143
142
  const { comments } = store
144
143
  const firstOption = t`Pick Comment…`
145
144
  function onChange() {
146
145
  const value = this.value
147
- this.value = firstOption // Hack
146
+ this.value = firstOption // hack so it’s always selected
148
147
  store.bulkSelectByComment(value)
149
148
  }
150
149
  const disabled = !comments.length
@@ -161,6 +160,7 @@ function BulkSelector() {
161
160
  r('option', { value: firstOption }, firstOption),
162
161
  r('hr'),
163
162
  comments.map(value => r('option', { value }, value)))))
163
+ // TODO For a11y, use `menu` instead of `select`
164
164
  }
165
165
 
166
166
  function CookieSelector() {
package/src/MockBroker.js CHANGED
@@ -55,7 +55,7 @@ export class MockBroker {
55
55
  }
56
56
 
57
57
  toggle500() {
58
- this.proxied = false // TESTME
58
+ this.proxied = false
59
59
  if (this.auto500 || this.status === 500)
60
60
  this.selectDefaultFile()
61
61
  else {
@@ -74,7 +74,7 @@ export class MockBroker {
74
74
  }
75
75
 
76
76
  setProxied(proxied) {
77
- this.auto500 = false // TESTME
77
+ this.auto500 = false
78
78
  this.proxied = proxied
79
79
  }
80
80
 
@@ -46,7 +46,7 @@ export async function dispatchMock(req, response) {
46
46
  setTimeout(() => response.end(isHead ? null : body),
47
47
  Number(broker.delayed && calcDelay()))
48
48
  }
49
- catch (error) {
49
+ catch (error) { // TESTME
50
50
  if (error?.code === 'ENOENT') // mock-file has been deleted
51
51
  sendMockNotFound(response)
52
52
  else
package/src/Mockaton.js CHANGED
@@ -21,7 +21,7 @@ export function Mockaton(options) {
21
21
  mockBrokerCollection.init()
22
22
  staticCollection.init()
23
23
 
24
- if (options.watcherEnabled) {
24
+ if (config.watcherEnabled) {
25
25
  watchMocksDir()
26
26
  watchStaticDir()
27
27
  }
package/src/Watcher.js CHANGED
@@ -45,7 +45,7 @@ export function watchMocksDir() {
45
45
  if (!file)
46
46
  return
47
47
 
48
- if (isDirectory(join(dir, file))) {
48
+ if (isDirectory(join(dir, file))) { // TESTME
49
49
  mockBrokerCollection.init()
50
50
  uiSyncVersion.increment()
51
51
  }
@@ -61,7 +61,7 @@ export function watchMocksDir() {
61
61
  })
62
62
  }
63
63
 
64
- export function watchStaticDir() {
64
+ export function watchStaticDir() { // TESTME
65
65
  const dir = config.staticDir
66
66
  if (!dir)
67
67
  return
package/src/config.js CHANGED
@@ -19,6 +19,7 @@ const schema = {
19
19
  mocksDir: [resolve('mockaton-mocks'), isDirectory],
20
20
  staticDir: [resolve('mockaton-static-mocks'), optional(isDirectory)],
21
21
  ignore: [/(\.DS_Store|~)$/, is(RegExp)], // TODO think about .well-known/appspecific/com.chrome.devtools
22
+ watcherEnabled: [true, is(Boolean)],
22
23
 
23
24
  host: ['127.0.0.1', is(String)],
24
25
  port: [0, port => Number.isInteger(port) && port >= 0 && port < 2 ** 16], // 0 means auto-assigned
@@ -49,9 +50,7 @@ const schema = {
49
50
  [/\.(js|ts)$/, jsToJsonPlugin]
50
51
  ], Array.isArray],
51
52
 
52
- onReady: [await openInBrowser, is(Function)],
53
-
54
- watcherEnabled: [true, is(Boolean)],
53
+ onReady: [await openInBrowser, is(Function)]
55
54
  }
56
55
 
57
56
 
@@ -29,7 +29,7 @@ export function init() {
29
29
 
30
30
  /** @returns {boolean} registered */
31
31
  export function registerMock(relativeFile) {
32
- if (!isFileAllowed(basename(relativeFile)))
32
+ if (!isFileAllowed(basename(relativeFile))) // TESTME
33
33
  return false
34
34
 
35
35
  const route = '/' + relativeFile