mockaton 8.27.0 → 9.1.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/CHANGELOG.md +6 -0
- package/README.md +63 -17
- package/index.d.ts +23 -10
- package/index.js +0 -1
- package/lcov.info +2582 -0
- package/package.json +4 -3
- package/src/Api.js +20 -17
- package/src/ApiCommander.js +5 -43
- package/src/ApiConstants.js +2 -4
- package/src/Dashboard.css +19 -15
- package/src/Dashboard.js +55 -77
- package/src/Logo.svg +2 -2
- package/src/cli.js +6 -3
- package/src/config.js +12 -14
- package/src/utils/mime.js +26 -13
- package/mockup.svg +0 -1037
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## 9.0.0 (9/13/25)
|
|
5
|
+
- **Breaking change**: Commander GET APIs have been consolidated into `commander.getState()`. These were undocumented APIs, so likely you are not affected.
|
|
6
|
+
- `--no-open` new cli flag. Prevents opening dashboard in a browser. (No-ops `config.onReady`)
|
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|

|
|
5
5
|
[](https://github.com/ericfortis/mockaton/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/ericfortis/mockaton/actions/workflows/github-code-scanning/codeql)
|
|
7
|
+
[](https://codecov.io/github/ericfortis/mockaton)
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
An HTTP mock server for simulating APIs with minimal setup
|
|
9
11
|
— ideal for testing difficult to reproduce states.
|
|
@@ -121,22 +123,25 @@ They will be saved in your `config.mocksDir` following the filename convention.
|
|
|
121
123
|
- Does not write to disk. Except when you select ✅ **Save Mocks** for scraping mocks from a backend.
|
|
122
124
|
- Does not initiate network connections (no logs, no telemetry).
|
|
123
125
|
- Does not hijack your HTTP client.
|
|
124
|
-
- Auditable. Organized and small — under 4 KLoC (50% is UI and tests)
|
|
126
|
+
- Auditable. Organized and small — under 4 KLoC (50% is UI and tests).
|
|
125
127
|
|
|
126
128
|
|
|
127
129
|
## Basic Usage
|
|
128
|
-
|
|
130
|
+
1. Install Node.js, which comes with `npm` and `npx`
|
|
131
|
+
|
|
132
|
+
2. Create a sample mock in the default mocks directory (`./mockaton-mocks`)
|
|
129
133
|
```sh
|
|
130
134
|
mkdir -p mockaton-mocks/api/
|
|
131
135
|
echo "[1,2,3]" > mockaton-mocks/api/foo.GET.200.json
|
|
132
136
|
```
|
|
133
|
-
|
|
134
|
-
Mockaton is a Node.js program, so you install and run it with:
|
|
137
|
+
3. Run Mockaton (npx installs it if needed)
|
|
135
138
|
```shell
|
|
136
139
|
npx mockaton --port 2345
|
|
137
140
|
```
|
|
138
141
|
|
|
139
|
-
|
|
142
|
+
<details>
|
|
143
|
+
<summary>Or, if you have a package.json</summary>
|
|
144
|
+
|
|
140
145
|
```shell
|
|
141
146
|
npm install mockaton --save-dev
|
|
142
147
|
```
|
|
@@ -148,6 +153,20 @@ npm install mockaton --save-dev
|
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
155
|
```
|
|
156
|
+
</details>
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
<details>
|
|
160
|
+
<summary>Or, if want an executable without using NPM?</summary>
|
|
161
|
+
|
|
162
|
+
Clone this repo, and make a link to `src/cli.js`
|
|
163
|
+
```shell
|
|
164
|
+
git clone https://github.com/ericfortis/mockaton.git
|
|
165
|
+
ln -s `realpath mockaton/src/cli.js` ~/bin/mockaton # some dir in your $PATH
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
</details>
|
|
151
170
|
|
|
152
171
|
|
|
153
172
|
|
|
@@ -164,6 +183,8 @@ The CLI options override their counterparts in `mockaton.config.js`
|
|
|
164
183
|
-p, --port <port> (default: 0) which means auto-assigned
|
|
165
184
|
|
|
166
185
|
-q, --quiet Errors only
|
|
186
|
+
--no-open Don’t open dashboard in a browser (noops onReady callback)
|
|
187
|
+
|
|
167
188
|
-h, --help Show this help
|
|
168
189
|
-v, --version Show version
|
|
169
190
|
```
|
|
@@ -186,24 +207,20 @@ export default defineConfig({
|
|
|
186
207
|
|
|
187
208
|
host: '127.0.0.1',
|
|
188
209
|
port: 0,
|
|
210
|
+
|
|
211
|
+
logLevel: 'normal',
|
|
212
|
+
|
|
213
|
+
delay: 1200,
|
|
214
|
+
delayJitter: 0,
|
|
189
215
|
|
|
190
216
|
proxyFallback: '',
|
|
191
217
|
collectProxied: false,
|
|
192
218
|
formatCollectedJSON: true,
|
|
193
219
|
|
|
194
|
-
delay: 1200,
|
|
195
|
-
delayJitter: 0,
|
|
196
|
-
|
|
197
220
|
cookies: {},
|
|
198
|
-
|
|
199
221
|
extraHeaders: [],
|
|
200
|
-
|
|
201
222
|
extraMimes: {},
|
|
202
223
|
|
|
203
|
-
plugins: [
|
|
204
|
-
[/\.(js|ts)$/, jsToJsonPlugin]
|
|
205
|
-
],
|
|
206
|
-
|
|
207
224
|
corsAllowed: true,
|
|
208
225
|
corsOrigins: ['*'],
|
|
209
226
|
corsMethods: SUPPORTED_METHODS,
|
|
@@ -211,10 +228,13 @@ export default defineConfig({
|
|
|
211
228
|
corsExposedHeaders: [],
|
|
212
229
|
corsCredentials: true,
|
|
213
230
|
corsMaxAge: 0,
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
plugins: [
|
|
234
|
+
[/\.(js|ts)$/, jsToJsonPlugin]
|
|
235
|
+
],
|
|
214
236
|
|
|
215
237
|
onReady: await openInBrowser,
|
|
216
|
-
|
|
217
|
-
logLevel: 'normal'
|
|
218
238
|
})
|
|
219
239
|
```
|
|
220
240
|
|
|
@@ -354,7 +374,8 @@ config.extraHeaders = [
|
|
|
354
374
|
### `extraMimes?: { [fileExt: string]: string }`
|
|
355
375
|
```js
|
|
356
376
|
config.extraMimes = {
|
|
357
|
-
jpe: 'application/jpeg'
|
|
377
|
+
jpe: 'application/jpeg',
|
|
378
|
+
html: 'text/html; charset=utf-8' // overrides built-in
|
|
358
379
|
}
|
|
359
380
|
```
|
|
360
381
|
Those extra media types take precedence over the built-in
|
|
@@ -732,6 +753,14 @@ with many partial matches, their first mock in alphabetical order wins.
|
|
|
732
753
|
### Set route is delayed flag
|
|
733
754
|
```js
|
|
734
755
|
await mockaton.setRouteIsDelayed('GET', '/api/foo', true)
|
|
756
|
+
// or
|
|
757
|
+
await mockaton.setStaticRouteIsDelayed('/api/foo', true)
|
|
758
|
+
```
|
|
759
|
+
<br/>
|
|
760
|
+
|
|
761
|
+
### Set static route status
|
|
762
|
+
```js
|
|
763
|
+
await mockaton.setStaticRouteStatus('/api/foo', 404)
|
|
735
764
|
```
|
|
736
765
|
|
|
737
766
|
### Set route is proxied flag
|
|
@@ -762,6 +791,23 @@ await mockaton.setCollectProxied(true)
|
|
|
762
791
|
|
|
763
792
|
<br/>
|
|
764
793
|
|
|
794
|
+
### Set global delay value
|
|
795
|
+
```js
|
|
796
|
+
await mockaton.setGlobalDelsy(1200) // ms
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
<br/>
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
### Set CORS allowed
|
|
803
|
+
```js
|
|
804
|
+
await mockaton.setCorsAllowed(true)
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
<br/>
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
765
811
|
### Reset
|
|
766
812
|
Re-initialize the collection. The selected mocks, cookies, and delays go back to
|
|
767
813
|
default, but the `proxyFallback`, `colledProxied`, and `corsAllowed` are not affected.
|
package/index.d.ts
CHANGED
|
@@ -16,22 +16,20 @@ interface Config {
|
|
|
16
16
|
|
|
17
17
|
host?: string,
|
|
18
18
|
port?: number
|
|
19
|
+
|
|
20
|
+
logLevel?: 'normal' | 'quiet'
|
|
21
|
+
|
|
22
|
+
delay?: number
|
|
23
|
+
delayJitter?: number
|
|
19
24
|
|
|
20
25
|
proxyFallback?: string
|
|
21
26
|
collectProxied?: boolean
|
|
22
27
|
formatCollectedJSON?: boolean
|
|
23
28
|
|
|
24
|
-
delay?: number
|
|
25
|
-
delayJitter?: number
|
|
26
|
-
|
|
27
29
|
cookies?: { [label: string]: string }
|
|
28
|
-
|
|
29
30
|
extraHeaders?: string[]
|
|
30
|
-
|
|
31
31
|
extraMimes?: { [fileExt: string]: string }
|
|
32
32
|
|
|
33
|
-
plugins?: [filenameTester: RegExp, plugin: Plugin][]
|
|
34
|
-
|
|
35
33
|
corsAllowed?: boolean,
|
|
36
34
|
corsOrigins?: string[]
|
|
37
35
|
corsMethods?: string[]
|
|
@@ -39,15 +37,16 @@ interface Config {
|
|
|
39
37
|
corsExposedHeaders?: string[]
|
|
40
38
|
corsCredentials?: boolean
|
|
41
39
|
corsMaxAge?: number
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
plugins?: [filenameTester: RegExp, plugin: Plugin][]
|
|
42
43
|
|
|
43
44
|
onReady?: (address: string) => void
|
|
44
|
-
|
|
45
|
-
logLevel?: 'normal' | 'quiet'
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
|
|
49
48
|
export function Mockaton(options: Partial<Config>): Server | undefined
|
|
50
|
-
export function defineConfig(options: Partial<Config>): Config
|
|
49
|
+
export function defineConfig(options: Partial<Config>): Partial<Config>
|
|
51
50
|
|
|
52
51
|
export const jsToJsonPlugin: Plugin
|
|
53
52
|
|
|
@@ -86,3 +85,17 @@ export type ClientStaticBrokers = {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
|
|
88
|
+
export interface State {
|
|
89
|
+
brokersByMethod: ClientBrokersByMethod
|
|
90
|
+
staticBrokers: ClientStaticBrokers
|
|
91
|
+
|
|
92
|
+
cookies: [label:string, selected:boolean][]
|
|
93
|
+
comments: string[]
|
|
94
|
+
|
|
95
|
+
delay: number
|
|
96
|
+
|
|
97
|
+
collectProxied: boolean
|
|
98
|
+
proxyFallback: string
|
|
99
|
+
|
|
100
|
+
corsAllowed: boolean
|
|
101
|
+
}
|