Testing
Both how this repo is tested and what it ships for testing your webhook wiring.
Interactive tools (the self-hosted webhook.site / simulator)
Section titled “Interactive tools (the self-hosted webhook.site / simulator)”No hosted bins, no accounts — the equivalents of webhook.site, Svix Play, and the Standard Webhooks simulator, run locally:
| Tool | What it does |
|---|---|
xtandard-webhooks listen [--port n] [--secret whsec_…] [--status code] |
A local inspecting receiver. Pretty-prints every incoming webhook (headers, body); with --secret it verifies the signature and shows a VERIFIED/FAILED badge, answering 401 on failure so a sender walks its retry path. Point an endpoint’s URL at http://localhost:4000. |
xtandard-webhooks sign --secret whsec_… --data '<json>' [--id] [--timestamp] [--url] |
The signature playground: builds a fully signed Standard Webhooks request and prints the headers + body — plus a ready-to-run curl when --url is given. Paste into https://www.standardwebhooks.com/simulate to cross-check. |
| Panel Request inspector | On a delivery’s detail page, expand “Request” to see the exact signed request that delivery sends (method, URL, all headers incl. webhook-signature, body) with a Copy-as-curl button. Backed by GET /api/applications/:app/deliveries/:id/request. |
The loop for a receiver developer: xtandard-webhooks listen --secret <your secret>, point an endpoint at it, publish (or hit “Send example”), and read the verified events as they arrive. To reproduce a specific signed request by hand, use sign.
Testing your app: @xtandard/webhooks/testing
Section titled “Testing your app: @xtandard/webhooks/testing”import { createTestWebhooks, createTestReceiver, drainDeliveries,} from "@xtandard/webhooks/testing";import { test, expect } from "bun:test"; // or vitest
test("shipping an order emits order.shipped", async () => { const { core, dispatcher } = createTestWebhooks(); await core.createApplication({ key: "acme" }); await core.upsertEventType({ name: "order.shipped" }); const endpoint = await core.createEndpoint("acme", { url: "http://127.0.0.1:9/tmp" }); const secret = (await core.getSecrets("acme", endpoint.id))[0]!.secret;
const receiver = await createTestReceiver({ secret, failFirst: 1 }); // exercise a retry await core.updateEndpoint("acme", endpoint.id, { url: receiver.url });
await shipOrder(core, "o_1"); // your code, calling core.publish(...) await drainDeliveries(dispatcher);
expect(receiver.received[0]).toMatchObject({ type: "order.shipped" }); await receiver.close();});createTestWebhooks()— in-memory core + a not started dispatcher (no timers), defaulting to an all-immediate retry schedule so failure paths drain in a fewtick()s.createTestReceiver({ secret?, failFirst?, status? })— a real local HTTP server; withsecretit verifies each request (invalid → 401) and collects parsed envelopes inreceived;failFirst: nfails the first n requests to exercise retries.requestsholds every raw request either way.drainDeliveries(dispatcher, maxTicks?)— tick until a pass makes no attempts.
No timers, no sleeps, no network flakiness: the dispatcher’s tick() exists precisely to be the deterministic test surface.
How this repo is tested
Section titled “How this repo is tested”| Layer | Where | Notes |
|---|---|---|
| unit + integration | test/*.test.ts via vp test run (vitest) |
flat dir; retry: 2 absorbs live-backend scheduling flakes |
| Bun-runtime-only | test/*.bun.test.ts via bun test |
bun:sqlite, libsql, CLI serve |
| storage conformance | test/storage-contract.ts |
one battery, every adapter; incl. due-index ordering + claimDue semantics |
| live backends | env-gated: REDIS_URL, POSTGRES_URL, MONGO_URL, MYSQL_URL |
always-on locally via pglite for postgres/drizzle-pg; CI runs service containers |
| browser e2e | e2e/ via Playwright |
boots the standalone app with the built UI |
| coverage | vp test run --coverage, thresholds 92/85/90/92 |
enforced in CI only |
Conventions worth copying:
- Injectable clock — the core takes
now: () => number; tests advance a fake clock instead of sleeping (retry schedules, lease expiry, rotation grace, retention ages). - Injectable fetch — the dispatcher takes
fetch;test/fixtures.tsprovidesfakeFetch(respond)capturing every request for wire-contract assertions (headers, signatures verify, body bytes stable). - No timer assertions — everything drives
tick();start()/stop()get exactly one smoke test. - UI logic policy — pure functions in
src/ui/lib/*are unit-tested; no jsdom/component tests; everything visual goes through Playwright.
Local gate (also the pre-push hook): bun run check && bun run test && bun run test:bun.