Motivation
Deterministic and Comprehensive States
Sometimes the flow you need to test is too difficult to reproduce from the actual backend.
- Demo edge cases to PMs, Design, and clients
- Set up screenshot tests (see pixaton-tests/ in the repo)
- Spot inadvertent regressions during development. For example, the demo app in this repo has a list of colors containing all of their possible states. This way you’ll indirectly notice if something broke.
Benefits
Standalone Demo Server (Docker)
You can demo your app by compiling the frontend and putting
its built assets in config.staticDir. For example, this
repo includes a demo which builds and runs a docker container.
git clone https://github.com/ericfortis/mockaton.git --depth 1
cd mockaton/demo-app-vite
make run-standalone-demo
- App: http://localhost:4040
- Dashboard: http://localhost:4040/mockaton
Testing Scenarios that Would Otherwise be Skipped
- Trigger dynamic states on an API. For example, for polled alerts or notifications.
- Testing retries, you can change an endpoint from a 500 to a 200 on the fly.
- Simulate errors on third-party APIs, or on your project’s backend.
- Generate dynamic responses. Use Node’s HTTP handlers (see function mocks below). So you can, e.g.:
- have an in-memory database
- read from disk
- read query string
- pretty much anything you can do with a normal backend request handler
Privacy and Security
- Does not write to disk. Except when you select ✅ Save Mocks for scraping mocks from a backend
- Does not initiate network connections (no logs, no telemetry)
- Does not hijack your HTTP client
- Auditable
- Organized and small. 4 KLoC (half is UI and tests)
- Zero dependencies. No runtime and no build packages.
Benefits of Mocking APIs in General
The section above highlights benefits specific to Mockaton. There are more, but in general here are some benefits that Mockaton has but other tools have as well:
Works Around Unstable Dev Backends while Developing UIs
- Syncing the database and spinning up dev infrastructure can be complex
- Mitigates progress from being blocked by waiting for APIs
Time Travel
If you commit the mocks to your repo, you don’t have to downgrade backends when checking out long-lived branches or bisecting bugs.