mockaton 8.1.2 → 8.1.4
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 +46 -39
- package/package.json +8 -3
- package/src/Dashboard.js +5 -3
- package/ui-tests/_setup.js +32 -0
- package/ui-tests/bulk-select.test.js +10 -0
- package/ui-tests/bulk-select.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/bulk-select.vp1024x800.light.gold.png +0 -0
- package/ui-tests/initial-dashboard-state.test.js +4 -0
- package/ui-tests/initial-dashboard-state.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/initial-dashboard-state.vp1024x800.light.gold.png +0 -0
- package/ui-tests/payload-viewer-formats-json.test.js +9 -0
- package/ui-tests/payload-viewer-formats-json.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/payload-viewer-formats-json.vp1024x800.light.gold.png +0 -0
- package/ui-tests/payload-viewer-renders-images.test.js +9 -0
- package/ui-tests/payload-viewer-renders-images.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/payload-viewer-renders-images.vp1024x800.light.gold.png +0 -0
- package/ui-tests/select-mock-variant.test.js +10 -0
- package/ui-tests/select-mock-variant.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/select-mock-variant.vp1024x800.light.gold.png +0 -0
package/README.md
CHANGED
|
@@ -2,35 +2,65 @@
|
|
|
2
2
|
|
|
3
3
|
_Mockaton_ is a mock server for developing and testing frontends.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
[
|
|
13
|
-
|
|
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
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
|
|
22
|
-
|
|
23
16
|
<picture>
|
|
24
17
|
<source media="(prefers-color-scheme: light)" srcset="./README-dashboard-light.png">
|
|
25
18
|
<source media="(prefers-color-scheme: dark)" srcset="./README-dashboard-dark.png">
|
|
26
19
|
<img alt="Mockaton Dashboard Demo" src="./README-dashboard-light.png" style="max-width: 860px">
|
|
27
20
|
</picture>
|
|
28
21
|
|
|
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
22
|
|
|
33
|
-
|
|
23
|
+
## Basic Usage
|
|
24
|
+
`tsx` is only needed if you want to write mocks in TypeScript
|
|
25
|
+
```
|
|
26
|
+
npm install mockaton tsx
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Create a `my-mockaton.js` file
|
|
30
|
+
```js
|
|
31
|
+
import { resolve } from 'node:path'
|
|
32
|
+
import { Mockaton } from 'mockaton'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// The Config options are explained in a section below
|
|
36
|
+
Mockaton({
|
|
37
|
+
mocksDir: resolve('my-mocks-dir'),
|
|
38
|
+
port: 2345
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
node --import=tsx my-mockaton.js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Running the Example Demo
|
|
48
|
+
This demo uses the [sample-mocks/](./sample-mocks) directory of this repository.
|
|
49
|
+
|
|
50
|
+
- Checkout this repo
|
|
51
|
+
- `git clone https://github.com/ericfortis/mockaton.git`
|
|
52
|
+
- `cd mockaton`
|
|
53
|
+
- `npm install tsx` (optional)
|
|
54
|
+
- `npm run demo:ts` it will open a dashboard
|
|
55
|
+
|
|
56
|
+
Experiment with the Dashboard:
|
|
57
|
+
|
|
58
|
+
- Pick a mock variant from the Mock dropdown (we’ll discuss
|
|
59
|
+
them later)
|
|
60
|
+
- Toggle the clock icon, which _Delays_ responses (e.g. for testing spinners)
|
|
61
|
+
- Toggle _500_ button, which sends and _Internal Server Error_ on that endpoint
|
|
62
|
+
|
|
63
|
+
Finally, edit a mock file. You don’t need to restart Mockaton for that. The
|
|
34
64
|
_Reset_ button is for registering newly added, removed, or renamed mocks.
|
|
35
65
|
|
|
36
66
|
|
|
@@ -56,29 +86,6 @@ _Reset_ button is for registering newly added, removed, or renamed mocks.
|
|
|
56
86
|
- Reverse Proxies such as [Burp](https://portswigger.net/burp) are also handy for overriding responses.
|
|
57
87
|
- [Mock Server Worker](https://mswjs.io)
|
|
58
88
|
|
|
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
89
|
---
|
|
83
90
|
|
|
84
91
|
## Mock Variants
|
package/package.json
CHANGED
|
@@ -2,14 +2,19 @@
|
|
|
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.
|
|
5
|
+
"version": "8.1.4",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": "https://github.com/ericfortis/mockaton",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "node --test",
|
|
11
|
+
"test": "node --test src/**.test.js",
|
|
12
12
|
"demo": "node _usage_example.js",
|
|
13
|
-
"demo:ts": "node --import=tsx _usage_example.js"
|
|
13
|
+
"demo:ts": "node --import=tsx _usage_example.js",
|
|
14
|
+
"demo:test-ui": "node --test --import=./ui-tests/_setup.js --experimental-test-isolation=none \"./ui-tests/**/*.test.js\""
|
|
15
|
+
},
|
|
16
|
+
"optionalDependencies": {
|
|
17
|
+
"puppeteer": "23.7.1",
|
|
18
|
+
"pixaton": "0.1.0"
|
|
14
19
|
}
|
|
15
20
|
}
|
package/src/Dashboard.js
CHANGED
|
@@ -94,8 +94,8 @@ function CookieSelector({ list }) {
|
|
|
94
94
|
title: disabled ? Strings.cookie_disabled_title : '',
|
|
95
95
|
onChange
|
|
96
96
|
},
|
|
97
|
-
list.map(([
|
|
98
|
-
r('option', { value
|
|
97
|
+
list.map(([value, selected]) =>
|
|
98
|
+
r('option', { value, selected }, value)))))
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
|
|
@@ -113,6 +113,7 @@ function BulkSelector({ comments }) {
|
|
|
113
113
|
r('label', null,
|
|
114
114
|
r('span', null, Strings.bulk_select_by_comment),
|
|
115
115
|
r('select', {
|
|
116
|
+
'data-qaid': 'BulkSelector',
|
|
116
117
|
autocomplete: 'off',
|
|
117
118
|
disabled,
|
|
118
119
|
title: disabled ? Strings.bulk_select_by_comment_disabled_title : '',
|
|
@@ -280,13 +281,14 @@ function MockSelector({ broker }) {
|
|
|
280
281
|
}
|
|
281
282
|
|
|
282
283
|
const selected = broker.currentMock.file
|
|
283
|
-
const { status } = parseFilename(selected)
|
|
284
|
+
const { status, urlMask } = parseFilename(selected)
|
|
284
285
|
const files = broker.mocks.filter(item =>
|
|
285
286
|
status === 500 ||
|
|
286
287
|
!item.includes(DEFAULT_500_COMMENT))
|
|
287
288
|
|
|
288
289
|
return (
|
|
289
290
|
r('select', {
|
|
291
|
+
'data-qaid': urlMask,
|
|
290
292
|
autocomplete: 'off',
|
|
291
293
|
className: className(selected === files[0], status),
|
|
292
294
|
disabled: files.length <= 1,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { after } from 'node:test'
|
|
2
|
+
import { launch } from 'puppeteer'
|
|
3
|
+
import {
|
|
4
|
+
removeDiffsAndCandidates,
|
|
5
|
+
testPixels as _testPixels,
|
|
6
|
+
diffServer
|
|
7
|
+
} from 'pixaton'
|
|
8
|
+
import { Commander } from '../index.js'
|
|
9
|
+
|
|
10
|
+
// Before running these tests you need to spin up the demo:
|
|
11
|
+
// npm run demo
|
|
12
|
+
|
|
13
|
+
const MOCKATON_ADDR = 'http://localhost:2345'
|
|
14
|
+
const mockaton = new Commander(MOCKATON_ADDR)
|
|
15
|
+
|
|
16
|
+
const testsDir = import.meta.dirname
|
|
17
|
+
|
|
18
|
+
removeDiffsAndCandidates(testsDir)
|
|
19
|
+
const browser = await launch({ headless: true })
|
|
20
|
+
const page = await browser.newPage()
|
|
21
|
+
|
|
22
|
+
after(() => {
|
|
23
|
+
browser?.close()
|
|
24
|
+
diffServer(testsDir)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export function testPixels(testFileName, options = {}) {
|
|
28
|
+
options.beforeSuite = async () => await mockaton.reset()
|
|
29
|
+
options.viewports ??= [{ width: 1024, height: 800 }]
|
|
30
|
+
options.colorSchemes ??= ['light', 'dark']
|
|
31
|
+
_testPixels(page, testFileName, MOCKATON_ADDR + '/mockaton', 'body', options)
|
|
32
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|