Testing infrastructure

stubfetch

Deterministic, in-process fake HTTP APIs for testing agents and tools. Swap real network calls for canned responses — GitHub, Stripe, OpenAI, S3, Slack, and more — with recording, replay, eval scenarios, and chaos injection built in.

npm install stubfetch
7+
Presets
0
Runtime deps
MIT
Licensed
import { GhostEnv, github, stripe } from "stubfetch";

const env = new GhostEnv({
  seed: 42,
  providers: [
    github({ issues: [{ repo: "acme/api", title: "Bug" }] }),
    stripe({ customers: [{ email: "[email protected]" }] }),
  ],
});

// Same shape as globalThis.fetch
const res = await env.fetch(
  "https://api.github.com/repos/acme/api/issues"
);
console.log(await res.json()); // [{ title: "Bug", ... }]

// Inspect calls
console.log(env.wasCalled("github")); // true

Presets

Drop-in API fakes

github

Issues, pull requests, repos — GitHub REST API shape

stripe

Customers, charges, subscriptions

openai / anthropic

Chat completions and messages API

postgres / s3 / slack

db().query(), object storage, Web API

Capabilities

Beyond basic mocking

Zero network calls

All responses are generated in-process from a deterministic seed — no live APIs, no flaky tests.

Recording & replay

calls(), wasCalled(), exportRecordingJSON / Markdown / HAR. Replay canned fixtures in order.

Eval scenarios

defineScenario + runEval let you script and score agent behaviour across repeatable test runs.

Chaos injection

chaos: { minLatencyMs, failureRate } — inject latency and random failures to test resilience.

Ready to build?

Read the full documentation to get started with stubfetch.

Read the docs