# @n8n-probe/mock-http

> HTTP mocking helpers and presets for testing n8n nodes that call external APIs

Latest version **0.1.0** (published 2026-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @n8n-probe/mock-http
pnpm add @n8n-probe/mock-http
yarn add @n8n-probe/mock-http
bun add @n8n-probe/mock-http
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2026-09-14 |
| First published | 2026-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 53.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mihaelaa |
| Keywords | n8n, testing, http, msw, mock |

## Links

- npm: https://www.npmjs.com/package/@n8n-probe/mock-http
- Repository: https://github.com/MihaelaAghirculesei/n8n-probe
- Homepage: https://github.com/MihaelaAghirculesei/n8n-probe/tree/main/packages/mock-http#readme
- npm.io page: https://npm.io/package/@n8n-probe/mock-http

## Dependencies (3)

- [msw](https://npm.io/package/msw.md) ^2.15.0
- [axios](https://npm.io/package/axios.md) ^1.20.0
- [@n8n-probe/core](https://npm.io/package/@n8n-probe/core.md) ^0.1.0

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [interceptpilot-mcp](https://npm.io/package/interceptpilot-mcp.md) — 0 weekly downloads
- [fakeforge-br](https://npm.io/package/fakeforge-br.md) — 0 weekly downloads
- [screenframe3d](https://npm.io/package/screenframe3d.md) — 0 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2026-09-14

## README

# @n8n-probe/mock-http

HTTP mocking for n8n nodes that call external APIs, built on
[MSW](https://mswjs.io) for the fast in-process tier and
[`testcontainers`](https://testcontainers.com) + WireMock for the opt-in
real-server tier.

```ts
import {
  setupMswForTest,
  mockApi,
  presets,
  createMockHttpExecuteFunctions,
} from '@n8n-probe/mock-http';
import { MyHttpNode } from '../nodes/MyHttpNode/MyHttpNode.node';

const server = setupMswForTest();

it('reads a user from the API', async () => {
  server.use(...mockApi().get('https://api.example.com/users/1').reply(200, { id: 1 }).handlers());

  const ctx = createMockHttpExecuteFunctions({
    input: [{ json: {} }],
    params: { url: 'https://api.example.com/users/1' },
  });
  const out = await new MyHttpNode().execute.call(ctx);

  expect(out[0][0].json).toEqual({ id: 1 });
});
```

## MSW tier (part of `pnpm test`)

- **`setupMswForTest(handlers?)`** — one shared server per test file, wired to
  `beforeAll` / `afterEach` / `afterAll`. An unmatched request fails the test
  (`onUnhandledRequest: 'error'`) instead of hanging or hitting the network.
  Returns the server for per-case `server.use(...)`.
- **`mockApi()`** — fluent handler builder:
  `mockApi().get(url).reply(200, body).post(url2).reply(201).handlers()`.
  `body`: `string` → text, `ArrayBuffer` / typed array → binary, anything else →
  JSON, omitted → empty.
- **`presets`** — ready-made handlers for the failure modes node authors get
  wrong: `rateLimited(path)` (429 + `Retry-After: 1`), `timeout(path)` (never
  settles — set a bounded request `timeout`), `flakyThenSuccess(path, n, body?)`
  (503 for the first `n` calls, then 200).
- **`createMockHttpExecuteFunctions(options?)`** — `@n8n-probe/core`'s mock
  context with `helpers.httpRequest` wired to a real axios client, so a node's
  outbound calls are actually intercepted. Same options as
  `createMockExecuteFunctions`.
- **`performHttpRequest(node, options)`** — the axios-backed
  `helpers.httpRequest` stand-in on its own. Maps the common `IHttpRequestOptions`
  fields; a non-2xx response (unless `ignoreHttpStatusErrors`) or a transport
  failure is thrown as `NodeApiError`.

## WireMock tier (opt-in, needs Docker — `pnpm test:e2e:full`)

- **`startWireMock({ mappingsDir?, image? })`** — boots `wiremock/wiremock` via
  `testcontainers` and returns `{ baseUrl, stop() }`. Use it for reusable stub
  mappings, latency and fault injection, or cross-language contract stubs.
  `testcontainers` is an optional peer dependency. Always `await stop()`.

MSW vs WireMock: MSW is in-process, millisecond-fast and needs no Docker — use it
for the default suite. WireMock is a real HTTP server in a container — use it when
the stubs must be shared across teams or languages, or when you need realistic
network behaviour (latency, connection resets, proxying, record & replay).

---

Part of [n8n-probe](../../README.md). Not affiliated with n8n GmbH.

---
_Source: https://npm.io/package/@n8n-probe/mock-http · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
