mockaton 8.2.1 → 8.2.3

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 (43) hide show
  1. package/README.md +5 -9
  2. package/package.json +1 -1
  3. package/.editorconfig +0 -11
  4. package/README-dashboard-dark.png +0 -0
  5. package/README-dashboard-light.png +0 -0
  6. package/sample-mocks/api/user/avatar.GET.200.png +0 -0
  7. package/sample-mocks/api/user/edit-name.PATCH.200.json +0 -3
  8. package/sample-mocks/api/user/edit-name.PATCH.422.json +0 -3
  9. package/sample-mocks/api/user/friends.GET.200.json +0 -3
  10. package/sample-mocks/api/user/friends.GET.204.json +0 -4
  11. package/sample-mocks/api/user/friends.GET.500.txt +0 -7
  12. package/sample-mocks/api/user/likes.GET.200.js +0 -9
  13. package/sample-mocks/api/user/links.GET.200.js +0 -9
  14. package/sample-mocks/api/user/logout.POST.200.json +0 -1
  15. package/sample-mocks/api/user/typescript-scores-full.GET.200.ts +0 -9
  16. package/sample-mocks/api/user/typescript-scores.GET.200.ts +0 -6
  17. package/sample-mocks/api/user/videos(all variants).GET.200.json +0 -13
  18. package/sample-mocks/api/user/videos(default).GET.200.json +0 -13
  19. package/sample-mocks/api/user/videos(verified)(another comment).GET.200.json +0 -13
  20. package/sample-mocks/api/user/yaml-fruits.GET.200.yml +0 -5
  21. package/sample-mocks/api/user.GET.200.json +0 -4
  22. package/sample-mocks/api/video/[id].GET.200.json +0 -4
  23. package/sample-mocks/api/video/stat/[stat-id]/[video-id].GET.200.json +0 -3
  24. package/sample-mocks/api/video/stat/[stat-id]/all-videos?limit=[limit].GET.200.json +0 -4
  25. package/sample-static/another-entry/index.html +0 -35
  26. package/sample-static/assets/video.mp4 +0 -0
  27. package/sample-static/index.html +0 -37
  28. package/ui-tests/_setup.js +0 -37
  29. package/ui-tests/bulk-select.test.js +0 -10
  30. package/ui-tests/bulk-select.vp1024x800.dark.gold.png +0 -0
  31. package/ui-tests/bulk-select.vp1024x800.light.gold.png +0 -0
  32. package/ui-tests/initial-dashboard-state.test.js +0 -4
  33. package/ui-tests/initial-dashboard-state.vp1024x800.dark.gold.png +0 -0
  34. package/ui-tests/initial-dashboard-state.vp1024x800.light.gold.png +0 -0
  35. package/ui-tests/payload-viewer-formats-json.test.js +0 -9
  36. package/ui-tests/payload-viewer-formats-json.vp1024x800.dark.gold.png +0 -0
  37. package/ui-tests/payload-viewer-formats-json.vp1024x800.light.gold.png +0 -0
  38. package/ui-tests/payload-viewer-renders-images.test.js +0 -9
  39. package/ui-tests/payload-viewer-renders-images.vp1024x800.dark.gold.png +0 -0
  40. package/ui-tests/payload-viewer-renders-images.vp1024x800.light.gold.png +0 -0
  41. package/ui-tests/select-mock-variant.test.js +0 -10
  42. package/ui-tests/select-mock-variant.vp1024x800.dark.gold.png +0 -0
  43. package/ui-tests/select-mock-variant.vp1024x800.light.gold.png +0 -0
package/README.md CHANGED
@@ -127,24 +127,20 @@ 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
-
131
- export default function optionalName(request, response) {
130
+ export default function requestCounter(request, response) {
132
131
  globalThis.myDatabase ??= { count: 0 }
133
132
  globalThis.myDatabase.count++
134
-
135
- // Optinally, you can override these two:
136
- repsonse.statusCode = 200
137
- response.setHeader('Content-Type', 'application/json')
138
-
139
- return JSON.stringify({ a: 1 })
133
+ return JSON.stringify({
134
+ count: globalThis.myDatabase.count
135
+ })
140
136
  }
141
137
  ```
142
138
 
143
139
  If you need to serve a static `.js` file, put it in your
144
140
  `Config.staticDir` without the mock filename convention.
145
141
 
146
- This example will echo back the request body concatenated with another fixture.
147
142
  ```js
143
+ // This example will echo the request body concatenated with another fixture.
148
144
  // api/color.POST.201.js
149
145
 
150
146
  import colors from './colors.json' with { type: 'json' }
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.1",
5
+ "version": "8.2.3",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/.editorconfig DELETED
@@ -1,11 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- indent_size = 2
7
- indent_style = tab
8
- insert_final_newline = true
9
-
10
- [*.md]
11
- indent_style = space
Binary file
Binary file
@@ -1,3 +0,0 @@
1
- {
2
- "renamed": "OK"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "msg": "Validation Error"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "_": "This is an exact path (i.e. /api/user/friends)"
3
- }
@@ -1,4 +0,0 @@
1
- {
2
- "_": "An example response of a user without friends. Uses HTTP Status: 204 - No Content",
3
- "friends": []
4
- }
@@ -1,7 +0,0 @@
1
- This is a plain text response for (/api/friends).
2
-
3
- In this case, it’s for mocking up a 500 - Internal Server Error.
4
-
5
- This file could have been empty, or some JSON if it had a `.json` extension.
6
-
7
- By the way, on initialization an 500 is auto-generated for routes that don’t have a 500.
@@ -1,9 +0,0 @@
1
- // You can write JSON responses in JavaScript.
2
- // You can export an: Object, Array, or String
3
-
4
- export default [
5
- { id: 0 },
6
- { id: 1 },
7
- { id: 2 },
8
- ]
9
-
@@ -1,9 +0,0 @@
1
- // You can write JSON responses in JavaScript as a function.
2
- // Must return a String and they should NOT call `response.end()`
3
-
4
- export default function (req, response) {
5
- return JSON.stringify([
6
- 'http://example.com/foo',
7
- 'http://example.com/bar'
8
- ], null, 2)
9
- }
@@ -1,9 +0,0 @@
1
- import scores from './typescript-scores.GET.200'
2
-
3
- export default [
4
- ...scores,
5
- { id: 103 },
6
- { id: 104 },
7
- { id: 105 },
8
- ]
9
-
@@ -1,6 +0,0 @@
1
- export default [
2
- { id: 100 },
3
- { id: 101 },
4
- { id: 102 },
5
- ]
6
-
@@ -1,13 +0,0 @@
1
- {
2
- "_": "This file has a comment: `(assorted)`. i.e. the route is /api/user/videos",
3
- "videos": [
4
- {
5
- "url": "https://example.com/1",
6
- "verified": true
7
- },
8
- {
9
- "url": "https://example.com/2",
10
- "verified": false
11
- }
12
- ]
13
- }
@@ -1,13 +0,0 @@
1
- {
2
- "_": "This file has a comment: `(default)`. Which makes the file with comment: (all variants) not to win",
3
- "videos": [
4
- {
5
- "url": "https://example.com/1",
6
- "verified": false
7
- },
8
- {
9
- "url": "https://example.com/2",
10
- "verified": false
11
- }
12
- ]
13
- }
@@ -1,13 +0,0 @@
1
- {
2
- "_": "This file has two comments: `(entirely verified)` and `(another comment)`. i.e. the route is /api/user/videos",
3
- "videos": [
4
- {
5
- "url": "https://example.com/1",
6
- "verified": true
7
- },
8
- {
9
- "url": "https://example.com/2",
10
- "verified": true
11
- }
12
- ]
13
- }
@@ -1,5 +0,0 @@
1
- fruits:
2
- apple
3
- banana
4
- orange
5
-
@@ -1,4 +0,0 @@
1
- {
2
- "_": "This mock is for /api/user",
3
- "name": "John"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "_": "This route has a dynamic param `<id>`. i.e. /api/video/123",
3
- "url": "https://example.com/123"
4
- }
@@ -1,3 +0,0 @@
1
- {
2
- "_": "Two Dynamic Params. i.e. /api/video/stat/VIEWS/123"
3
- }
@@ -1,4 +0,0 @@
1
- {
2
- "_": "Example filename with a query string. BTW, it doesn't work on Windows, because '?' is an illegal character. At any rate, the full query string is ignored.",
3
- "data": []
4
- }
@@ -1,35 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta content="width=device-width" name="viewport">
6
- <link rel="icon" href="data:">
7
- <title>Another Entry Point</title>
8
- </head>
9
- <body>
10
- <h1>Another Entry Point</h1>
11
-
12
- <h2>/api/user</h2>
13
- <pre></pre>
14
- <script>
15
- (async () => {
16
- let output = ''
17
- try {
18
- const response = await fetch('/api/user')
19
- if (response.ok) {
20
- const json = await response.json()
21
- output = JSON.stringify(json, null, 2)
22
- }
23
- else
24
- throw response.status
25
- }
26
- catch (error) {
27
- output = 'Error: ' + error
28
- }
29
- finally {
30
- document.querySelector('pre').innerText = output
31
- }
32
- })()
33
- </script>
34
- </body>
35
- </html>
Binary file
@@ -1,37 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta content="width=device-width" name="viewport">
6
- <link rel="icon" href="data:">
7
- <title>Title</title>
8
- </head>
9
- <body>
10
- <h1>Welcome!</h1>
11
- <video src="assets/video.mp4" width="720" controls></video>
12
-
13
- <h2>/api/user</h2>
14
- <pre></pre>
15
-
16
- <script>
17
- (async () => {
18
- let output = ''
19
- try {
20
- const response = await fetch('/api/user')
21
- if (response.ok) {
22
- const json = await response.json()
23
- output = JSON.stringify(json, null, 2)
24
- }
25
- else
26
- throw response.status
27
- }
28
- catch (error) {
29
- output = 'Error: ' + error
30
- }
31
- finally {
32
- document.querySelector('pre').innerText = output
33
- }
34
- })()
35
- </script>
36
- </body>
37
- </html>
@@ -1,37 +0,0 @@
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 ??= [{
30
- width: 1024,
31
- height: 800,
32
- deviceScaleFactor: 1.5 // for better screenshots
33
- }]
34
- options.colorSchemes ??= ['light', 'dark']
35
- options.screenshotOptions ??= {}
36
- _testPixels(page, testFileName, MOCKATON_ADDR + '/mockaton', 'body', options)
37
- }
@@ -1,10 +0,0 @@
1
- import { testPixels } from './_setup.js'
2
-
3
-
4
- testPixels(import.meta.filename, {
5
- async setup(page) {
6
- const qaId = 'BulkSelector'
7
- const target = '(Mockaton 500)'
8
- await page.select(`select[data-qaid="${qaId}"]`, target)
9
- }
10
- })
@@ -1,4 +0,0 @@
1
- import { testPixels } from './_setup.js'
2
-
3
-
4
- testPixels(import.meta.filename)
@@ -1,9 +0,0 @@
1
- import { testPixels } from './_setup.js'
2
-
3
-
4
- testPixels(import.meta.filename, {
5
- async setup(page) {
6
- const linkText = '/api/user'
7
- await page.locator(`a ::-p-text(${linkText})`).click()
8
- }
9
- })
@@ -1,9 +0,0 @@
1
- import { testPixels } from './_setup.js'
2
-
3
-
4
- testPixels(import.meta.filename, {
5
- async setup(page) {
6
- const linkText = '/api/user/avatar'
7
- await page.locator(`a ::-p-text(${linkText})`).click()
8
- }
9
- })
@@ -1,10 +0,0 @@
1
- import { testPixels } from './_setup.js'
2
-
3
-
4
- testPixels(import.meta.filename, {
5
- async setup(page) {
6
- const qaId = '/api/user/friends'
7
- const target = 'api/user/friends.GET.204.json'
8
- await page.select(`select[data-qaid="${qaId}"]`, target)
9
- }
10
- })