mockaton 8.1.3 → 8.1.5

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.
Files changed (2) hide show
  1. package/README.md +51 -43
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,23 +2,17 @@
2
2
 
3
3
  _Mockaton_ is a mock server for developing and testing frontends.
4
4
 
5
- It scans a given directory for files following a specific
6
- file name convention, which is similar to the URL paths. For
7
- example, the following file will be served for `/api/user/1234`
5
+ The mock filename convention is similar to the URL paths. For
6
+ example, the following file will be served on `/api/user/1234`
8
7
  ```
9
8
  my-mocks-dir/api/user/[user-id].GET.200.json
10
9
  ```
11
10
 
12
- [This browser extension](https://github.com/ericfortis/devtools-ext-tar-http-requests)
13
- can be used for downloading a TAR of your XHR requests following that convention.
11
+ By the way, [this browser
12
+ extension](https://github.com/ericfortis/devtools-ext-tar-http-requests)
13
+ can create a TAR of your XHR requests following that convention.
14
14
 
15
-
16
- ## Getting Started Demo
17
- - Checkout this repo
18
- - `npm install tsx` (optional)
19
- - `npm run demo:ts`
20
- which will open the following dashboard
21
- - Explore the [sample-mocks/](./sample-mocks) directory
15
+ ### Dashboard Example
22
16
 
23
17
  <picture>
24
18
  <source media="(prefers-color-scheme: light)" srcset="./README-dashboard-light.png">
@@ -26,11 +20,48 @@ can be used for downloading a TAR of your XHR requests following that convention
26
20
  <img alt="Mockaton Dashboard Demo" src="./README-dashboard-light.png" style="max-width: 860px">
27
21
  </picture>
28
22
 
29
- Then, pick a mock variant from the Mock dropdown (we’ll discuss
30
- them later). At its right, note the _Delay_ toggler, and the button
31
- for sending _500 - Internal Server Error_ on that endpoint.
32
23
 
33
- Then edit a mock file. You don’t need to restart Mockaton for that, the
24
+ ## Basic Usage
25
+ `tsx` is only needed if you want to write mocks in TypeScript
26
+ ```
27
+ npm install mockaton tsx
28
+ ```
29
+
30
+ Create a `my-mockaton.js` file
31
+ ```js
32
+ import { resolve } from 'node:path'
33
+ import { Mockaton } from 'mockaton'
34
+
35
+
36
+ // The Config options are explained in a section below
37
+ Mockaton({
38
+ mocksDir: resolve('my-mocks-dir'),
39
+ port: 2345
40
+ })
41
+ ```
42
+
43
+ ```sh
44
+ node --import=tsx my-mockaton.js
45
+ ```
46
+
47
+
48
+ ## Running the Example Demo
49
+ This demo uses the [sample-mocks/](./sample-mocks) directory of this repository.
50
+
51
+ - Checkout this repo
52
+ - `git clone https://github.com/ericfortis/mockaton.git`
53
+ - `cd mockaton`
54
+ - `npm install tsx` (optional)
55
+ - `npm run demo:ts` it will open a dashboard
56
+
57
+ Experiment with the Dashboard:
58
+
59
+ - Pick a mock variant from the Mock dropdown (we’ll discuss
60
+ them later)
61
+ - Toggle the 🕓 Clock button, which _Delays_ responses (e.g. for testing spinners)
62
+ - Toggle the _500_ button, which sends and _Internal Server Error_ on that endpoint
63
+
64
+ Finally, edit a mock file. You don’t need to restart Mockaton for that. The
34
65
  _Reset_ button is for registering newly added, removed, or renamed mocks.
35
66
 
36
67
 
@@ -56,39 +87,16 @@ _Reset_ button is for registering newly added, removed, or renamed mocks.
56
87
  - Reverse Proxies such as [Burp](https://portswigger.net/burp) are also handy for overriding responses.
57
88
  - [Mock Server Worker](https://mswjs.io)
58
89
 
59
-
60
- ## Basic Usage
61
- `tsx` is only needed if you want to write mocks in TypeScript
62
- ```
63
- npm install mockaton tsx
64
- ```
65
- Create a `my-mockaton.js` file
66
- ```js
67
- import { resolve } from 'node:path'
68
- import { Mockaton } from 'mockaton'
69
-
70
-
71
- // The Config options are explained in a section below
72
- Mockaton({
73
- mocksDir: resolve('my-mocks-dir'),
74
- port: 2345
75
- })
76
- ```
77
-
78
- ```sh
79
- node --import=tsx my-mockaton.js
80
- ```
81
-
82
90
  ---
83
91
 
84
92
  ## Mock Variants
85
93
  Each route can have many mocks, which could either be:
86
94
  - Different response __status code__. For example, for testing error responses.
87
95
  - __Comment__ on the filename, which is anything within parentheses.
88
- - e.g. `api/user(my-comment).POST.201.json`
96
+ - e.g. `api/login(locked out user).POST.423.json`
89
97
 
90
- Those alternatives can be manually selected in the dashboard
91
- UI, or programmatically, for instance, for setting up tests.
98
+ Those alternatives can be manually selected on the dashboard, or
99
+ programmatically (see **Commander API** section), for instance, for setting up tests.
92
100
 
93
101
  ### Default Mock for a Route
94
102
  You can add the comment: `(default)` to a filename.
@@ -357,7 +365,7 @@ Config.onReady = open
357
365
 
358
366
  ---
359
367
 
360
- ## HTTP API
368
+ ## Commander API
361
369
  `Commander` is a wrapper for the Mockaton HTTP API.
362
370
  All of its methods return their `fetch` response promise.
363
371
  ```js
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.1.3",
5
+ "version": "8.1.5",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",