Plugin Testing Helpers
Utilities for writing tests against OpenVesper plugins without running a real LLM or gateway.
Importing
import {
mockRuntime,
expectTool,
mockFetch,
} from "@openvesper/plugin-sdk/testing";mockRuntime()
import myPlugin from "../src/index.js";
test("crypto_price returns BTC price", async () => {
const runtime = mockRuntime();
runtime.registerPlugin(myPlugin);
const result = await runtime.callTool("crypto_price", { symbol: "BTC" });
expectTool(result).toSucceed().toReturnData((d: any) => typeof d.price === "number");
expect(runtime.getCallCount("crypto_price")).toBe(1);
});expectTool() assertions
expectTool(result)
.toSucceed()
.toReturnData((d: any) => d.score > 50)
.toHaveDataMatching({ status: "active" });
expectTool(badResult)
.toFail()
.toFailWith(/rate limit/i);mockFetch() โ intercept HTTP
const restore = mockFetch(async (url) => {
if (url.includes("api.coingecko.com")) {
return { ok: true, json: async () => ({ bitcoin: { usd: 100000 } }) };
}
return { ok: false, status: 404 };
});
// ... run tests ...
restore();withEnv() โ scoped env vars
await runtime.withEnv({ HELIUS_API_KEY: "test" }, async () => {
const result = await runtime.callTool("solana_balance", { address });
expectTool(result).toSucceed();
});