GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - dkhproject/auto-mock: Zero-dependency Node.js CLI HTTP proxy recorder, offline API replay server, and chaos testing simulator.

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
bin
bin
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
package.json
package.json
 
 

Repository files navigation

auto-mock — Zero-Dependency API Proxy Recorder, Offline Replay & Chaos Simulator

Stop maintaining brittle hand-written API mocks and fighting flaky upstream staging servers. auto-mock records real HTTP traffic once into deterministic .automock/ snapshots and replays it completely offline — with recorded latency playback, random error injection, and zero external dependencies.

Node.js >= 18 Zero Dependencies License: MIT

Installation & Quickstart

Require Node.js >= 18.0.0. Run immediately with npx or install globally:

# Record upstream API traffic directly with npx
npx @dkhproject/auto-mock record https://api.example.com --port 4000

# Replay recorded snapshots offline with npx
npx @dkhproject/auto-mock replay --port 4000

# Or install globally
npm install -g @dkhproject/auto-mock
auto-mock --help

Why auto-mock?

Capability auto-mock Manual JSON Mocks In-Process Interceptors (MSW / Nock) Heavy Mock Servers (WireMock / Hoverfly)
Zero external dependencies (npx-ready) ✅ ✅ ❌ ❌ (JVM / Go binary)
Language-agnostic local HTTP proxy ✅ ❌ ❌ (JS/TS only) ✅
Automatic record & deterministic replay ✅ ❌ Manual setup ✅
Realistic recorded latency + chaos simulation ✅ ❌ Custom handlers Partial / Paid
Per-request override headers (x-automock-*) ✅ ❌ ❌ ❌

Features

  • Zero external dependencies: Built strictly on Node.js built-in modules (http, https, fs, path, crypto, url).
  • Deterministic snapshots: Keys fixtures on HTTP method, pathname, canonicalized query string, and SHA-256 request body hash.
  • Lossless text & binary capture: Stores UTF-8 text inline and binary/compressed payloads as base64, while stripping RFC hop-by-hop headers.
  • Offline replay: Serves saved .automock/ responses without network access and returns clear 404 JSON diagnostics on unrecorded routes.
  • Time-travel & chaos simulation: Replays captured latency (--realistic-latency), injects fixed or jittered delays (--latency), simulates random failures (--fail-rate, --fail-status), and honors per-request override headers (x-automock-delay, x-automock-status).
  • Fixture management & colored logs: Inspect or wipe snapshots with list and clean, and follow color-coded [REC], [HIT], [CHAOS], and [MISS] logs (respecting NO_COLOR).

Workflow

1. Record real upstream traffic

Start the recording proxy pointing at your upstream API (default port 4000):

npx @dkhproject/auto-mock record https://api.example.com --port 4000

Send requests to http://127.0.0.1:4000/... instead of https://api.example.com/.... Each response is forwarded transparently and persisted inside .automock/.

2. Replay completely offline

Shut down your upstream server (or disconnect from the network) and start auto-mock in replay mode:

npx @dkhproject/auto-mock replay --port 4000

Matching requests are served directly from .automock/. Unrecorded requests return HTTP 404 with JSON details:

{
  "error": "Fixture not found",
  "message": "No recorded fixture matches this request. Run `auto-mock record <targetUrl>` first to record it.",
  "request": {
    "method": "GET",
    "pathname": "/missing",
    "query": "",
    "expectedFixture": "GET_missing_..."
  }
}

Time-Travel & Chaos Simulator

Simulate real-world network latency and upstream outages during replay mode:

Flag Description Example
--realistic-latency Delay each response by the exact latencyMs captured when recorded auto-mock replay --realistic-latency
--latency <ms|min-max> Add a fixed delay (ms) or uniform random jitter (min-max) auto-mock replay --latency 500-2000
--fail-rate <0-1> Randomly fail requests with probability between 0 and 1 auto-mock replay --fail-rate 0.25
--fail-status <code> HTTP status code returned on simulated failures (default 500) auto-mock replay --fail-rate 0.2 --fail-status 503

Example simulating slow, flaky upstream behavior:

auto-mock replay --port 4000 --realistic-latency --latency 200-800 --fail-rate 0.1 --fail-status 503

Simulated failures return:

{
  "error": "Simulated failure via auto-mock",
  "status": 503
}

Per-Request Override Headers

Integration tests can trigger delays or error codes on demand for individual requests without restarting the proxy:

  • x-automock-delay: <ms|min-max> — Overrides CLI latency flags for that single request.
  • x-automock-status: <code> — Forces a specific status code (>= 400 returns the simulated error JSON payload; < 400 overrides the replayed status code).
# Inject a 1500ms delay on a single call
curl -H "x-automock-delay: 1500" http://127.0.0.1:4000/api/users

# Force a 429 rate-limit response on demand
curl -i -H "x-automock-status: 429" http://127.0.0.1:4000/api/users

Fixture Management (list & clean)

Inspect all recorded snapshots in .automock/ (or pass --dir <path>):

auto-mock list

Example output:

METHOD  PATH                        STATUS  LATENCY  SNAPSHOT FILE
------  --------------------------  ------  -------  -----------------------------------------
GET     /api/users?active=true      200     42ms     GET_api_users_3a91c0d4e2f81b09.json
POST    /api/users                  201     18ms     POST_api_users_94b71a02c51d440a.json

2 fixture(s) in /path/to/project/.automock

Delete all saved fixture files:

auto-mock clean

Terminal Output

Each request emits a concise log line tagged by outcome:

[REC]   GET /api/users?active=true -> 200 (42ms)
[REC]   POST /api/users -> 201 (18ms)
[HIT]   GET /api/users?active=true -> 200 (1ms)
[CHAOS] GET /api/users?active=true -> 503 (412ms)
[MISS]  GET /api/missing -> 404 (0ms)
  • [REC] (cyan) — Recorded from upstream in record mode
  • [HIT] (green) — Served from .automock/ in replay mode
  • [CHAOS] (magenta) — Delayed or failed via chaos simulation or override headers
  • [MISS] (yellow) — No matching snapshot found (404)

ANSI colors are automatically enabled in interactive TTYs and disabled when NO_COLOR is set (per no-color.org).

Fixture Format

Each file in .automock/ stores deterministic request keys alongside the captured response:

{
  "request": {
    "method": "GET",
    "pathname": "/api/users",
    "query": "active=true&role=admin",
    "bodyHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
  },
  "statusCode": 200,
  "statusMessage": "OK",
  "headers": {
    "content-type": "application/json"
  },
  "latencyMs": 18,
  "bodyEncoding": "utf8",
  "body": "{\"users\":[\"alice\",\"bob\"]}",
  "recordedAt": "2026-11-24T06:30:00.000Z"
}

Testing

Run the built-in node:test suite:

npm test

About

Zero-dependency Node.js CLI HTTP proxy recorder, offline API replay server, and chaos testing simulator.

Topics

api-mockingchaos-testingclidevtoolshttp-proxymock-servernodejsoffline-testingopen-sourcezero-dependencies

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.