mockaton 2.3.1 → 3.0.0
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 +11 -11
- package/Tests.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/Config.js +4 -8
- package/src/Mockaton.js +2 -2
- package/src/utils/openInBrowser.js +8 -0
- package/src/utils/validate.js +4 -0
package/README.md
CHANGED
|
@@ -44,17 +44,17 @@ node my-mockaton.js
|
|
|
44
44
|
## Config Options
|
|
45
45
|
```ts
|
|
46
46
|
interface Config {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
mocksDir: string
|
|
48
|
+
staticDir?: string
|
|
49
|
+
host?: string, // defaults to 'localhost'
|
|
50
|
+
port?: number // defaults to 0, which means auto-assigned
|
|
51
|
+
delay?: number // defaults to 1200 (ms)
|
|
52
|
+
open?: (dashboardUrl: string) => void // pass a noop to prevent opening the dashboard
|
|
53
|
+
cookies?: object
|
|
54
|
+
proxyFallback?: string // e.g. http://localhost:9999 Target for relaying routes without mocks
|
|
55
|
+
allowedExt?: RegExp // /\.(json|txt|md|js)$/ Just for excluding temporary editor files (e.g. JetBrains appends a ~)
|
|
56
|
+
generate500?: boolean // autogenerates an Internal Server Error empty mock for routes that have no 500
|
|
57
|
+
extraHeaders?: []
|
|
58
58
|
}
|
|
59
59
|
```
|
|
60
60
|
|
package/Tests.js
CHANGED
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/Config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { validate, is, optional } from './utils/validate.js'
|
|
1
|
+
import { openInBrowser } from './utils/openInBrowser.js'
|
|
2
|
+
import { validate, is, optional, isDirectory } from './utils/validate.js'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const Config = {
|
|
@@ -8,8 +8,8 @@ export const Config = {
|
|
|
8
8
|
host: '127.0.0.1',
|
|
9
9
|
port: 0, // auto-assigned
|
|
10
10
|
delay: 1200, // milliseconds
|
|
11
|
+
open: openInBrowser,
|
|
11
12
|
cookies: {}, // defaults to the first kv
|
|
12
|
-
skipOpen: false,
|
|
13
13
|
proxyFallback: '', // e.g. http://localhost:9999
|
|
14
14
|
allowedExt: /\.(json|txt|md|js)$/, // Just for excluding temporary editor files (e.g. JetBrains appends a ~)
|
|
15
15
|
generate500: false,
|
|
@@ -24,8 +24,8 @@ export function setup(options) {
|
|
|
24
24
|
host: is(String),
|
|
25
25
|
port: port => Number.isInteger(port) && port >= 0 && port < 2 ** 16,
|
|
26
26
|
delay: ms => Number.isInteger(ms) && ms > 0,
|
|
27
|
+
open: is(Function),
|
|
27
28
|
cookies: is(Object),
|
|
28
|
-
skipOpen: is(Boolean),
|
|
29
29
|
proxyFallback: optional(URL.canParse),
|
|
30
30
|
allowedExt: is(RegExp),
|
|
31
31
|
generate500: is(Boolean),
|
|
@@ -33,8 +33,4 @@ export function setup(options) {
|
|
|
33
33
|
})
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function isDirectory(dir) {
|
|
37
|
-
return exists(dir) && lstatSync(dir).isDirectory()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
36
|
|
package/src/Mockaton.js
CHANGED
package/src/utils/validate.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { existsSync as exists, lstatSync } from 'node:fs'
|
|
2
|
+
|
|
3
|
+
|
|
1
4
|
export function validate(obj, shape) {
|
|
2
5
|
for (const [field, value] of Object.entries(obj))
|
|
3
6
|
if (!shape[field](value))
|
|
@@ -6,3 +9,4 @@ export function validate(obj, shape) {
|
|
|
6
9
|
|
|
7
10
|
export const is = ctor => val => val.constructor === ctor
|
|
8
11
|
export const optional = tester => val => !val || tester(val)
|
|
12
|
+
export const isDirectory = dir => exists(dir) && lstatSync(dir).isDirectory()
|