mockaton 9.6.1 → 10.1.0

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 CHANGED
@@ -15,7 +15,7 @@ An HTTP mock server for simulating APIs with minimal setup
15
15
  ## Motivation
16
16
 
17
17
  **No API state should be too hard to test.**
18
- With Mockaton, developers can achieve correctness and increase speed.
18
+ With Mockaton, developers can achieve correctness and speed.
19
19
 
20
20
  ### Correctness
21
21
  - Enables testing of complex scenarios that would otherwise be skipped. e.g.,
@@ -60,9 +60,9 @@ Nonetheless, there’s a programmatic API, which is handy
60
60
  for setting up tests (see **Commander API** section below).
61
61
 
62
62
  <picture>
63
- <source media="(prefers-color-scheme: light)" srcset="pixaton-tests/macos/pic-for-readme.vp810x768.light.gold.png">
64
- <source media="(prefers-color-scheme: dark)" srcset="pixaton-tests/macos/pic-for-readme.vp810x768.dark.gold.png">
65
- <img alt="Mockaton Dashboard" src="pixaton-tests/macos/pic-for-readme.vp810x768.light.gold.png">
63
+ <source media="(prefers-color-scheme: light)" srcset="pixaton-tests/macos/pic-for-readme.vp781x772.light.gold.png">
64
+ <source media="(prefers-color-scheme: dark)" srcset="pixaton-tests/macos/pic-for-readme.vp781x772.dark.gold.png">
65
+ <img alt="Mockaton Dashboard" src="pixaton-tests/macos/pic-for-readme.vp781x772.light.gold.png">
66
66
  </picture>
67
67
 
68
68
 
@@ -174,7 +174,7 @@ Since Mockaton has no dependencies, you can create an executable
174
174
  by linking to `src/cli.js`.
175
175
 
176
176
  ```shell
177
- git clone https://github.com/ericfortis/mockaton.git
177
+ git clone https://github.com/ericfortis/mockaton.git --depth 1
178
178
  ln -s `realpath mockaton/src/cli.js` ~/bin/mockaton # some dir in your $PATH
179
179
  ```
180
180
 
@@ -501,14 +501,12 @@ Defaults to `'normal'`.
501
501
 
502
502
  ```js
503
503
  import { Mockaton } from 'mockaton'
504
- import mockatonConfig from './mockaton.config.js'
504
+ import config from './mockaton.config.js'
505
505
 
506
- const server = Mockaton({
507
- ...mockatonConfig, // Not required, but it’s not read by default.
508
- })
506
+ const server = await Mockaton(
507
+ config // Not required, but it’s not read by default.
508
+ )
509
509
  ```
510
- See [src/cli.js](src/cli.js) or [src/Mockaton.test.js](src/Mockaton.test.js) for more examples.
511
-
512
510
  </details>
513
511
 
514
512
 
@@ -518,7 +516,7 @@ See [src/cli.js](src/cli.js) or [src/Mockaton.test.js](src/Mockaton.test.js) for
518
516
  ## Demo App (Vite + React)
519
517
 
520
518
  ```sh
521
- git clone https://github.com/ericfortis/mockaton.git
519
+ git clone https://github.com/ericfortis/mockaton.git --depth 1
522
520
  cd mockaton/demo-app-vite
523
521
  npm install
524
522
 
package/index.d.ts CHANGED
@@ -45,7 +45,7 @@ interface Config {
45
45
  }
46
46
 
47
47
 
48
- export function Mockaton(options: Partial<Config>): Server | undefined
48
+ export function Mockaton(options: Partial<Config>): Promise<Server | undefined>
49
49
  export function defineConfig(options: Partial<Config>): Partial<Config>
50
50
 
51
51
  export const jsToJsonPlugin: Plugin
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "HTTP Mock Server",
4
4
  "type": "module",
5
- "version": "9.6.1",
5
+ "version": "10.1.0",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
@@ -27,6 +27,6 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "pixaton": "1.1.3",
30
- "puppeteer": "24.19.0"
30
+ "puppeteer": "24.22.3"
31
31
  }
32
32
  }
package/src/Dashboard.css CHANGED
@@ -157,7 +157,7 @@ header {
157
157
  align-items: flex-end;
158
158
  gap: 16px 10px;
159
159
 
160
- @media (max-width: 800px) {
160
+ @media (max-width: 780px) {
161
161
  max-width: 400px;
162
162
  }
163
163
  }
@@ -315,7 +315,7 @@ main {
315
315
  min-width: 0;
316
316
  min-height: 0;
317
317
 
318
- @media (max-width: 800px) {
318
+ @media (max-width: 780px) {
319
319
  flex-direction: column;
320
320
 
321
321
  .Resizer {
@@ -335,6 +335,7 @@ main {
335
335
  padding: 16px;
336
336
  padding-bottom: 0;
337
337
  border-right: 1px solid var(--colorSecondaryActionBorder);
338
+ user-select: none;
338
339
  overflow-y: auto;
339
340
  box-shadow: var(--boxShadow1);
340
341
  }
@@ -437,7 +438,11 @@ table {
437
438
  display: flex;
438
439
 
439
440
  > input {
440
- appearance: none;
441
+ /* For click drag target */
442
+ position: absolute;
443
+ width: 22px;
444
+ height: 22px;
445
+ opacity: 0;
441
446
 
442
447
  &:focus {
443
448
  outline: 0;
package/src/Dashboard.js CHANGED
@@ -98,8 +98,8 @@ const state = {
98
98
  this.groupByMethod = !this.groupByMethod
99
99
  localStorage.setItem('groupByMethod', String(this.groupByMethod))
100
100
  },
101
-
102
- leftSideWidth: undefined,
101
+
102
+ leftSideWidth: undefined
103
103
  }
104
104
 
105
105
  const mockaton = new Commander(window.location.origin)
@@ -459,25 +459,19 @@ function MockSelector({ broker }) {
459
459
 
460
460
  /** @param {{ broker: ClientMockBroker }} props */
461
461
  function DelayRouteToggler({ broker }) {
462
- function onChange() {
462
+ function commit(checked) {
463
463
  const { method, urlMask } = parseFilename(broker.mocks[0])
464
- mockaton.setRouteIsDelayed(method, urlMask, this.checked)
464
+ mockaton.setRouteIsDelayed(method, urlMask, checked)
465
465
  .then(parseError)
466
466
  .catch(onError)
467
467
  }
468
- return (
469
- r('label', {
470
- className: CSS.DelayToggler,
471
- title: Strings.delay
472
- },
473
- r('input', {
474
- type: 'checkbox',
475
- checked: broker.currentMock.delayed,
476
- onChange
477
- }),
478
- TimerIcon()))
468
+ return ClickDragToggler({
469
+ checked: broker.currentMock.delayed,
470
+ commit
471
+ })
479
472
  }
480
473
 
474
+
481
475
  /** @param {{ broker: ClientMockBroker }} props */
482
476
  function InternalServerErrorToggler({ broker }) {
483
477
  function onChange() {
@@ -558,22 +552,15 @@ function StaticFilesList() {
558
552
 
559
553
  /** @param {{ broker: ClientStaticBroker }} props */
560
554
  function DelayStaticRouteToggler({ broker }) {
561
- function onChange() {
562
- mockaton.setStaticRouteIsDelayed(broker.route, this.checked)
555
+ function commit(checked) {
556
+ mockaton.setStaticRouteIsDelayed(broker.route, checked)
563
557
  .then(parseError)
564
558
  .catch(onError)
565
559
  }
566
- return (
567
- r('label', {
568
- className: CSS.DelayToggler,
569
- title: Strings.delay
570
- },
571
- r('input', {
572
- type: 'checkbox',
573
- checked: broker.delayed,
574
- onChange
575
- }),
576
- TimerIcon()))
560
+ return ClickDragToggler({
561
+ checked: broker.delayed,
562
+ commit
563
+ })
577
564
  }
578
565
 
579
566
  /** @param {{ broker: ClientStaticBroker }} props */
@@ -614,6 +601,40 @@ function ProxyStaticToggler({}) { // TODO
614
601
  }
615
602
 
616
603
 
604
+ function ClickDragToggler({ checked, commit }) {
605
+ function onPointerEnter(event) {
606
+ if (event.buttons === 1)
607
+ onPointerDown.call(this)
608
+ }
609
+ function onPointerDown() {
610
+ this.checked = !this.checked
611
+ commit(this.checked)
612
+ }
613
+ function onClick(event) {
614
+ if (event.pointerType === 'mouse')
615
+ event.preventDefault()
616
+ }
617
+ function onChange() {
618
+ commit(this.checked)
619
+ }
620
+ return (
621
+ r('label', {
622
+ className: CSS.DelayToggler,
623
+ title: Strings.delay
624
+ },
625
+ r('input', {
626
+ type: 'checkbox',
627
+ checked,
628
+ onPointerEnter,
629
+ onPointerDown,
630
+ onClick,
631
+ onChange
632
+ }),
633
+ TimerIcon()))
634
+ }
635
+
636
+
637
+
617
638
  function Resizer() {
618
639
  return (
619
640
  r('div', {
@@ -627,8 +648,8 @@ Resizer.panelWidth = 0
627
648
  Resizer.onPointerDown = function (event) {
628
649
  Resizer.initialX = event.clientX
629
650
  Resizer.panelWidth = leftSideRef.current.clientWidth
630
- window.addEventListener('pointerup', Resizer.onUp)
631
- window.addEventListener('pointermove', Resizer.onMove)
651
+ addEventListener('pointerup', Resizer.onUp)
652
+ addEventListener('pointermove', Resizer.onMove)
632
653
  document.body.style.userSelect = 'none'
633
654
  document.body.style.cursor = 'col-resize'
634
655
  }
@@ -641,8 +662,8 @@ Resizer.onMove = function (event) {
641
662
  })
642
663
  }
643
664
  Resizer.onUp = function () {
644
- window.removeEventListener('pointermove', Resizer.onMove)
645
- window.removeEventListener('pointerup', Resizer.onUp)
665
+ removeEventListener('pointermove', Resizer.onMove)
666
+ removeEventListener('pointerup', Resizer.onUp)
646
667
  cancelAnimationFrame(Resizer.raf)
647
668
  Resizer.raf = 0
648
669
  document.body.style.userSelect = 'auto'
package/src/Mockaton.js CHANGED
@@ -15,27 +15,28 @@ import { sendNoContent, sendInternalServerError, sendUnprocessableContent } from
15
15
 
16
16
 
17
17
  export function Mockaton(options) {
18
- setup(options)
19
-
20
- mockBrokerCollection.init()
21
- staticCollection.init()
22
- watchMocksDir()
23
- watchStaticDir()
24
-
25
- const server = createServer(onRequest)
26
-
27
- server.listen(config.port, config.host, function () {
28
- const { address, port } = this.address()
29
- const url = `http://${address}:${port}`
30
- logger.info('Listening', url)
31
- logger.info('Dashboard', url + API.dashboard)
32
- config.onReady(url + API.dashboard)
18
+ return new Promise((resolve, reject) => {
19
+ setup(options)
20
+
21
+ mockBrokerCollection.init()
22
+ staticCollection.init()
23
+ watchMocksDir()
24
+ watchStaticDir()
25
+
26
+ const server = createServer(onRequest)
27
+ server.on('error', reject)
28
+ server.listen(config.port, config.host, () => {
29
+ const { address, port } = server.address()
30
+ const url = `http://${address}:${port}`
31
+ const dashboardUrl = url + API.dashboard
32
+ logger.info('Listening', url)
33
+ logger.info('Dashboard', dashboardUrl)
34
+ config.onReady(dashboardUrl)
35
+ resolve(server)
36
+ })
33
37
  })
34
-
35
- return server
36
38
  }
37
39
 
38
-
39
40
  async function onRequest(req, response) {
40
41
  response.on('error', logger.warn)
41
42
 
package/src/cli.js CHANGED
@@ -36,7 +36,7 @@ catch (error) {
36
36
  }
37
37
 
38
38
 
39
- if (args.version)
39
+ if (args.version)
40
40
  console.log(pkgJSON.version)
41
41
 
42
42
  else if (args.help)
@@ -83,10 +83,7 @@ else {
83
83
  if (args['no-open']) opts.onReady = () => {}
84
84
 
85
85
  try {
86
- Mockaton(opts).on('error', error => {
87
- console.error(error.message)
88
- process.exit(1)
89
- })
86
+ await Mockaton(opts)
90
87
  }
91
88
  catch (err) {
92
89
  console.error(err?.message || err)
package/CHANGELOG.md DELETED
@@ -1,6 +0,0 @@
1
- # Changelog
2
-
3
-
4
- ## 9.0.0 (9/13/25)
5
- - **Breaking change**: Commander GET APIs have been consolidated into `commander.getState()`. These were undocumented APIs, so likely you are not affected.
6
- - `--no-open` new cli flag. Prevents opening dashboard in a browser. (No-ops `config.onReady`)