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.
Parameters
Section titled “Parameters”policy
Section titled “policy”The policy instance to test.
options?
Section titled “options?”Optional upstream, path, and gateway name.
Returns
Section titled “Returns”An object with request(), app, and the adapter used.
adapter
Section titled “adapter”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()
Section titled “request()”request: (
reqPath,init?) =>Response|Promise<Response>
Make a test request through the policy pipeline.
Parameters
Section titled “Parameters”reqPath
Section titled “reqPath”string
RequestInit<CfProperties<unknown>>
Returns
Section titled “Returns”Response | Promise<Response>
Example
Section titled “Example”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();});