mockaton 8.2.0 → 8.2.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.
Binary file
Binary file
package/README.md CHANGED
@@ -127,6 +127,7 @@ database, or pull data from a backend.
127
127
  Don’t call `response.end()`, just return a `string | Buffer | Uint8Array`.
128
128
 
129
129
  ```js
130
+
130
131
  export default function optionalName(request, response) {
131
132
  globalThis.myDatabase ??= { count: 0 }
132
133
  globalThis.myDatabase.count++
@@ -142,6 +143,19 @@ export default function optionalName(request, response) {
142
143
  If you need to serve a static `.js` file, put it in your
143
144
  `Config.staticDir` without the mock filename convention.
144
145
 
146
+ This example will echo back the request body concatenated with another fixture.
147
+ ```js
148
+ // api/color.POST.201.js
149
+
150
+ import colors from './colors.json' with { type: 'json' }
151
+ import { parseJSON } from 'mockaton' // body-parser alike
152
+
153
+ export default async function concatColor(request, response) {
154
+ const newColor = await parseJSON(request)
155
+ return JSON.stringify(colors.concat(newColor))
156
+ }
157
+ ```
158
+
145
159
  ---
146
160
 
147
161
  ## Mock File Name Convention
package/index.d.ts CHANGED
@@ -42,8 +42,13 @@ export function Mockaton(options: Config): Server
42
42
 
43
43
  export const jsToJsonPlugin: Plugin
44
44
 
45
+
46
+ // Utils
47
+
45
48
  export function jwtCookie(cookieName: string, payload: any): string
46
49
 
50
+ export function parseJSON(request: IncomingMessage): Promise<any>
51
+
47
52
 
48
53
  export class Commander {
49
54
  constructor(addr: string)
package/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export { Mockaton } from './src/Mockaton.js'
2
- export { jwtCookie } from './src/utils/jwt.js'
3
2
  export { Commander } from './src/Commander.js'
4
3
  export { jsToJsonPlugin } from './src/MockDispatcherPlugins.js'
4
+
5
+ export { jwtCookie } from './src/utils/jwt.js'
6
+ export { parseJSON } from './src/utils/http-request.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.2.0",
5
+ "version": "8.2.1",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
@@ -11,10 +11,11 @@
11
11
  "test": "node --test src/**.test.js",
12
12
  "demo": "node _usage_example.js",
13
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\""
14
+ "demo:test-ui": "node --test --import=./ui-tests/_setup.js --experimental-test-isolation=none \"./ui-tests/**/*.test.js\"",
15
+ "outdated": "npm outdated --parseable | awk -F: '{ printf \"npm i %-30s ;# %s\\n\", $4, $2 }'"
15
16
  },
16
17
  "optionalDependencies": {
17
- "puppeteer": "23.7.1",
18
- "pixaton": "0.1.0"
18
+ "pixaton": ">=1.0.1",
19
+ "puppeteer": ">=23.10.1"
19
20
  }
20
21
  }
package/src/Dashboard.css CHANGED
@@ -1,12 +1,12 @@
1
1
  :root {
2
- --boxShadow1: 0 2px 1px -1px rgba(0, 0, 0, 0.2), 0 1px 1px 0 rgba(0, 0, 0, 0.14), 0 1px 3px 0 rgba(0, 0, 0, 0.12);
2
+ --boxShadow1: 0 2px 1px -1px rgba(0, 0, 0, 0.1), 0 1px 1px 0 rgba(0, 0, 0, 0.1), 0 1px 3px 0 rgba(0, 0, 0, 0.08);
3
3
  }
4
4
 
5
5
  @media (prefers-color-scheme: light) {
6
6
  :root {
7
7
  --color4xxBackground: #ffedd1;
8
- --colorAccent: #0072d6;
9
- --colorAccentAlt: #0e906c;
8
+ --colorAccent: #0081ef;
9
+ --colorAccentAlt: #009c71;
10
10
  --colorBackground: #fff;
11
11
  --colorHeaderBackground: #f7f7f7;
12
12
  --colorComboBoxBackground: #fafafa;
@@ -23,8 +23,8 @@
23
23
  @media (prefers-color-scheme: dark) {
24
24
  :root {
25
25
  --color4xxBackground: #403630;
26
- --colorAccent: #1f91ff;
27
- --colorAccentAlt: #00E676;
26
+ --colorAccent: #2495ff;
27
+ --colorAccentAlt: #00bf64;
28
28
  --colorBackground: #161616;
29
29
  --colorHeaderBackground: #090909;
30
30
  --colorComboBoxBackground: #252525;
@@ -62,6 +62,7 @@ select {
62
62
  color: var(--colorText);
63
63
  cursor: pointer;
64
64
  outline: 0;
65
+ border-radius: 6px;
65
66
 
66
67
  &:enabled {
67
68
  box-shadow: var(--boxShadow1);
@@ -83,7 +84,7 @@ menu {
83
84
  display: flex;
84
85
  width: 100%;
85
86
  align-items: flex-end;
86
- padding: 12px 16px;
87
+ padding: 16px;
87
88
  border-bottom: 1px solid rgba(127, 127, 127, 0.1);
88
89
  background: var(--colorHeaderBackground);
89
90
  box-shadow: var(--boxShadow1);
@@ -111,6 +112,7 @@ menu {
111
112
  margin-top: 2px;
112
113
  font-size: 11px;
113
114
  background: var(--colorComboBoxHeaderBackground);
115
+ border-radius: 6px;
114
116
  }
115
117
 
116
118
  input[type=url] {
@@ -148,7 +150,7 @@ menu {
148
150
  main {
149
151
  display: flex;
150
152
  align-items: flex-start;
151
- margin-top: 48px;
153
+ margin-top: 56px;
152
154
 
153
155
  > table {
154
156
  border-collapse: collapse;
@@ -199,7 +201,7 @@ main {
199
201
  display: inline-block;
200
202
  width: 280px;
201
203
  padding: 8px 6px;
202
- border-radius: 0;
204
+ border-radius: 6px;
203
205
  color: var(--colorAccent);
204
206
  text-decoration: none;
205
207
 
@@ -218,7 +220,6 @@ main {
218
220
  padding: 8px 1px;
219
221
  border: 0;
220
222
  border-left: 3px solid transparent;
221
- border-radius: 0;
222
223
  text-align: right;
223
224
  direction: rtl;
224
225
  text-overflow: ellipsis;
package/src/Dashboard.js CHANGED
@@ -175,8 +175,7 @@ function ResetButton() {
175
175
  .then(init)
176
176
  .catch(console.error)
177
177
  }
178
- }, Strings.reset)
179
- )
178
+ }, Strings.reset))
180
179
  }
181
180
 
182
181
 
@@ -299,7 +298,6 @@ function MockSelector({ broker }) {
299
298
  .catch(console.error)
300
299
  }
301
300
 
302
-
303
301
  function className(defaultIsSelected, status) {
304
302
  return cssClass(
305
303
  CSS.MockSelector,
@@ -2,7 +2,7 @@
2
2
  <svg version="1.1" viewBox="0 0 570 100" xmlns="http://www.w3.org/2000/svg">
3
3
  <style>
4
4
  :root { --color: #000000; }
5
- @media (prefers-color-scheme: light) { :root { --color: #444 } }
5
+ @media (prefers-color-scheme: light) { :root { --color: #555 } }
6
6
  @media (prefers-color-scheme: dark) { :root { --color: #eee } }
7
7
  path { fill: var(--color) }
8
8
  </style>
@@ -17,12 +17,12 @@ export function sendJSON(response, payload) {
17
17
  response.end(JSON.stringify(payload))
18
18
  }
19
19
 
20
- export function sendFile(response, file) {
21
- if (!isFile(file))
20
+ export function sendFile(response, filePath) {
21
+ if (!isFile(filePath))
22
22
  sendNotFound(response)
23
23
  else {
24
- response.setHeader('Content-Type', mimeFor(file))
25
- response.end(read(file))
24
+ response.setHeader('Content-Type', mimeFor(filePath))
25
+ response.end(read(filePath))
26
26
  }
27
27
  }
28
28
 
@@ -26,7 +26,12 @@ after(() => {
26
26
 
27
27
  export function testPixels(testFileName, options = {}) {
28
28
  options.beforeSuite = async () => await mockaton.reset()
29
- options.viewports ??= [{ width: 1024, height: 800 }]
29
+ options.viewports ??= [{
30
+ width: 1024,
31
+ height: 800,
32
+ deviceScaleFactor: 1.5 // for better screenshots
33
+ }]
30
34
  options.colorSchemes ??= ['light', 'dark']
35
+ options.screenshotOptions ??= {}
31
36
  _testPixels(page, testFileName, MOCKATON_ADDR + '/mockaton', 'body', options)
32
37
  }