mockaton 8.4.0 → 8.4.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/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": "8.4.0",
5
+ "version": "8.4.1",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Mockaton.js CHANGED
@@ -17,10 +17,8 @@ export function Mockaton(options) {
17
17
  mockBrokerCollection.init()
18
18
 
19
19
  watch(config.mocksDir, { recursive: true, persistent: false }, (_, filename) => {
20
- if (existsSync(join(config.mocksDir, filename))) {
21
- const broker = mockBrokerCollection.registerMock(filename)
22
- broker.ensureItHas500()
23
- }
20
+ if (existsSync(join(config.mocksDir, filename)))
21
+ mockBrokerCollection.registerMock(filename, 'ensureItHas500')
24
22
  else
25
23
  mockBrokerCollection.unregisterMock(filename)
26
24
  })
@@ -23,8 +23,7 @@ export function init() {
23
23
 
24
24
  listFilesRecursively(config.mocksDir)
25
25
  .sort()
26
- .filter(f => !config.ignore.test(f) && filenameIsValid(f))
27
- .forEach(registerMock)
26
+ .forEach(f => registerMock(f))
28
27
 
29
28
  forEachBroker(broker => {
30
29
  broker.ensureItHas500()
@@ -32,15 +31,19 @@ export function init() {
32
31
  })
33
32
  }
34
33
 
35
- /** @returns {MockBroker} */
36
- export function registerMock(file) {
34
+ export function registerMock(file, shouldEnsure500) {
35
+ if (config.ignore.test(file) || !filenameIsValid(file))
36
+ return
37
+
37
38
  const { method, urlMask } = parseFilename(file)
38
39
  collection[method] ??= {}
39
40
  if (!collection[method][urlMask])
40
41
  collection[method][urlMask] = new MockBroker(file)
41
42
  else
42
43
  collection[method][urlMask].register(file)
43
- return collection[method][urlMask]
44
+
45
+ if (shouldEnsure500)
46
+ collection[method][urlMask].ensureItHas500()
44
47
  }
45
48
 
46
49
  export function unregisterMock(file) {