Skip to content

createPolicyTestHarness

createPolicyTestHarness(policy, options?): object

Defined in: src/policies/sdk/testing.ts:55

Create a minimal test app with a single policy, error handling, gateway context injection, and a configurable upstream.

Policy

The policy instance to test.

PolicyTestHarnessOptions

Optional upstream, path, and gateway name.

An object with request(), app, and the adapter used.

adapter: TestAdapter

The adapter used by the harness. Call adapter.waitAll() to await background tasks.

app: Hono<BlankEnv, BlankSchema, "/">

The underlying Hono app for advanced test scenarios.

request: (reqPath, init?) => Response | Promise<Response>

Make a test request through the policy pipeline.

string

RequestInit<CfProperties<unknown>>

Response | Promise<Response>

import { createPolicyTestHarness } from "@homegrower-club/stoma/policies";
import { myPolicy } from "./my-policy";
const { request, adapter } = createPolicyTestHarness(myPolicy({ max: 10 }));
it("should allow valid requests", async () => {
const res = await request("/test");
expect(res.status).toBe(200);
// Await any background work (e.g. waitUntil)
await adapter.waitAll();
});