mockaton 6.4.4 → 6.4.6
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 +8 -3
- package/Tests.js +6 -4
- package/package.json +1 -1
- package/src/Api.js +5 -5
- package/src/Dashboard.css +3 -5
- package/src/Dashboard.js +1 -1
- package/src/mockaton-logo.svg +4 -0
- package/src/utils/http-response.js +1 -7
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
<img src="src/mockaton-logo.svg" alt="Mockaton Logo" width="210" style="margin-top: 30px"/>
|
|
2
|
+
|
|
2
3
|
_Mockaton_ is a mock server for developing and testing frontends.
|
|
3
4
|
|
|
4
5
|
It scans a given directory for files following a specific
|
|
@@ -327,10 +328,14 @@ fetch(addr + '/mockaton/fallback', {
|
|
|
327
328
|
|
|
328
329
|
### Reset
|
|
329
330
|
Re-initialize the collection. So if you added or removed mocks they
|
|
330
|
-
will be considered. The selected mocks, cookies, and delays
|
|
331
|
-
back to default
|
|
331
|
+
will be considered. The selected mocks, cookies, and delays go
|
|
332
|
+
back to default, but `Config.proxyFalllback` is not affected.
|
|
332
333
|
```js
|
|
333
334
|
fetch(addr + '/mockaton/reset', {
|
|
334
335
|
method: 'PATCH'
|
|
335
336
|
})
|
|
336
337
|
```
|
|
338
|
+
|
|
339
|
+
## TODO
|
|
340
|
+
- Dashboard. List `staticDir` and indicate if it’s overriding some mock.
|
|
341
|
+
- Refactor Tests
|
package/Tests.js
CHANGED
|
@@ -165,7 +165,7 @@ async function runTests() {
|
|
|
165
165
|
'api/alternative(comment-2).GET.200.json',
|
|
166
166
|
JSON.stringify({ comment: 2 }))
|
|
167
167
|
|
|
168
|
-
await
|
|
168
|
+
await testBadRequestWhenUpdatingNonExistingMockAlternative()
|
|
169
169
|
|
|
170
170
|
await testAutogenerates500(
|
|
171
171
|
'/api/alternative',
|
|
@@ -288,13 +288,15 @@ async function testItUpdatesDelayAndFile(url, file, expectedBody) {
|
|
|
288
288
|
})
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
async function
|
|
291
|
+
async function testBadRequestWhenUpdatingNonExistingMockAlternative() {
|
|
292
292
|
await it('There are mocks for /api/the-route but not this one', async () => {
|
|
293
|
+
const missingFile = 'api/the-route(non-existing-variant).GET.200.json'
|
|
293
294
|
const res = await request(API.edit, {
|
|
294
295
|
method: 'PATCH',
|
|
295
|
-
body: JSON.stringify({ [DF.file]:
|
|
296
|
+
body: JSON.stringify({ [DF.file]: missingFile })
|
|
296
297
|
})
|
|
297
|
-
equal(res.status,
|
|
298
|
+
equal(res.status, 400)
|
|
299
|
+
equal(await res.text(), `Missing Mock: ${missingFile}`)
|
|
298
300
|
})
|
|
299
301
|
}
|
|
300
302
|
|
package/package.json
CHANGED
package/src/Api.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Config } from './Config.js'
|
|
|
9
9
|
import { DF, API } from './ApiConstants.js'
|
|
10
10
|
import { parseJSON } from './utils/http-request.js'
|
|
11
11
|
import * as mockBrokersCollection from './mockBrokersCollection.js'
|
|
12
|
-
import { sendOK, sendBadRequest, sendJSON, sendFile
|
|
12
|
+
import { sendOK, sendBadRequest, sendJSON, sendFile } from './utils/http-response.js'
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
export const apiGetRequests = new Map([
|
|
@@ -18,6 +18,7 @@ export const apiGetRequests = new Map([
|
|
|
18
18
|
['/Dashboard.js', serveDashboardAsset],
|
|
19
19
|
['/Dashboard.css', serveDashboardAsset],
|
|
20
20
|
['/ApiConstants.js', serveDashboardAsset],
|
|
21
|
+
['/mockaton-logo.svg', serveDashboardAsset],
|
|
21
22
|
[API.mocks, listMockBrokers],
|
|
22
23
|
[API.cookies, listCookies],
|
|
23
24
|
[API.comments, listComments]
|
|
@@ -59,10 +60,9 @@ async function updateBroker(req, response) {
|
|
|
59
60
|
const body = await parseJSON(req)
|
|
60
61
|
const file = body[DF.file]
|
|
61
62
|
const broker = mockBrokersCollection.getBrokerByFilename(file)
|
|
62
|
-
if (!broker || !broker.mockExists(file))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
63
|
+
if (!broker || !broker.mockExists(file))
|
|
64
|
+
throw `Missing Mock: ${file}`
|
|
65
|
+
|
|
66
66
|
if (DF.delayed in body)
|
|
67
67
|
broker.updateDelay(body[DF.delayed])
|
|
68
68
|
broker.updateFile(file)
|
package/src/Dashboard.css
CHANGED
|
@@ -63,10 +63,8 @@ menu {
|
|
|
63
63
|
margin-bottom: 12px;
|
|
64
64
|
gap: 14px;
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
margin:
|
|
68
|
-
margin-right: 12px;
|
|
69
|
-
font-size: 26px;
|
|
66
|
+
img {
|
|
67
|
+
margin-right: 16px;
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
label {
|
|
@@ -107,7 +105,7 @@ menu {
|
|
|
107
105
|
top: 0;
|
|
108
106
|
width: 50%;
|
|
109
107
|
margin-left: 16px;
|
|
110
|
-
|
|
108
|
+
|
|
111
109
|
h2 {
|
|
112
110
|
padding-top: 20px;
|
|
113
111
|
}
|
package/src/Dashboard.js
CHANGED
|
@@ -54,7 +54,7 @@ function DevPanel(brokersByMethod, cookies, comments) {
|
|
|
54
54
|
return (
|
|
55
55
|
r('div', null,
|
|
56
56
|
r('menu', null,
|
|
57
|
-
r('
|
|
57
|
+
r('img', { src: 'mockaton-logo.svg', width: 160 }),
|
|
58
58
|
r(CookieSelector, { list: cookies }),
|
|
59
59
|
r(BulkSelector, { comments }),
|
|
60
60
|
r(ResetButton)),
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg version="1.1" viewBox="0 0 570 100" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<path d="m77 0.27c2.7 0 6 1.3 9.1 2.6 2.9 1.1 4.2 3.3 4.2 6.5v84c0 3.8-2.4 5.8-7.2 5.8s-7.2-2-7.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-6.7 5.8s-6.7-2-6.7-5.8v-48c0-2.1-0.66-4.1-2-6.1" aria-label="Mockaton"/>
|
|
4
|
+
</svg>
|
|
@@ -51,7 +51,7 @@ export async function sendPartialContent(response, range, file) {
|
|
|
51
51
|
export function sendBadRequest(response, error) {
|
|
52
52
|
console.error(error)
|
|
53
53
|
response.statusCode = 400
|
|
54
|
-
response.end()
|
|
54
|
+
response.end(error)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function sendNotFound(response) {
|
|
@@ -59,12 +59,6 @@ export function sendNotFound(response) {
|
|
|
59
59
|
response.end()
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export function sendUnprocessableContent(response, error) {
|
|
63
|
-
console.error(error)
|
|
64
|
-
response.statusCode = 422
|
|
65
|
-
response.end()
|
|
66
|
-
}
|
|
67
|
-
|
|
68
62
|
export function sendInternalServerError(response, error) {
|
|
69
63
|
console.error(error)
|
|
70
64
|
response.statusCode = 500
|