Docs
Functions

defineFixture

Author a typed test/dev fixture with seed data plus the plugins it depends on.

defineFixture authors a fixture: the serializable test layer an integration ships alongside its live code. A fixture bundles a seed function that creates known records over the typed WordPress client with the plugins that content depends on. Pass fixtures to a config's dev/test stacks, or to getKizloTestInstance, to provision a consistent world.

Parameters

defineFixture(fixture)

fixture is a Fixture: its seed/cleanup functions, the plugins it needs, and the name its seeded handles are stored under.

Returns

The same fixture object, unchanged. defineFixture is an identity function that exists only to attach types and give you inference and autocomplete while authoring.

Examples

A fixture that installs a plugin and seeds one post:

fixtures/blog.ts
import { defineFixture } from "kizlo/test"

export const blogFixture = defineFixture({
  name: "blog",
  plugins: [
    { name: "wordpress-seo", source: "wordpress-seo", version: "26.3" },
  ],
  async seed(ctx) {
    const post = await ctx.service.posts.create({
      slug: "hello-world-test",
      title: "Hello World Test",
      status: "publish",
      author: ctx.adminId,
    })
    if (post.error) throw post.error

    return { postId: post.data.id } // a live handle a test reads back, not a snapshot
  },
})

Use a bare wp.org slug when the fixture should track its newest release. Use the object form with version when the stack must install the same release after every reset. A zip URL pins itself, so it does not need version.

Register it on local WordPress for both kizlo dev and kizlo test:

kizlo.config.ts
import { defineConfig } from "kizlo/config"
import { blogFixture } from "./fixtures/blog"

export default defineConfig({
  dev: { local: true, fixtures: [blogFixture] },
  test: { local: true, fixtures: [blogFixture] },
})

On this page