getKizloTestInstance
Wire a Kizlo instance against seeded test WordPress for integration tests.
getKizloTestInstance builds a Kizlo instance wired to running test WordPress, with admin credentials read from the
seeded test connection artifact and the adapter mocks in place. Call your
procedures directly through its client to test what they do
against real WordPress responses.
Parameters
getKizloTestInstance(options?)options.extensions
The extensions to register on the test instance, the same array you
pass to createKizlo. Their namespaces appear on the returned client.
Omit it to test only the core routes.
Returns
A KizloTestInstance, a createKizlo instance pre-configured for tests:
- Credentials come from seeded test WordPress (the admin user), read from the
.kizlo/test.jsonconnection artifact thatkizlo testwrites, so it must be provisioned first. - Adapters are mocked:
geo,auth(resolves the seeded user), andcaptcha(accepts test tokens). The logger is restricted towarnanderror.
Call procedures through instance.client. Use .call(...) to get the value back, or its typed error thrown. That
is the quickest check of a procedure's behavior.
Examples
An integration test reading a seeded post:
import { beforeAll, expect, test } from "vitest"
import { getKizloTestInstance, type KizloTestInstance } from "kizlo/test"
let kizlo: KizloTestInstance
beforeAll(() => {
kizlo = getKizloTestInstance()
})
test("reads a seeded post by slug", async () => {
const post = await kizlo.client.posts.get.call({ params: { identifier: "hello-world-test" } })
expect(post.slug).toBe("hello-world-test")
})With an extension registered so its namespace is testable:
import { getKizloTestInstance } from "kizlo/test"
import { reviews } from "../src/lib/kizlo/server/reviews"
const kizlo = getKizloTestInstance({ extensions: [reviews()] })
const list = await kizlo.client.reviews.list.call()