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 extension 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:
import { defineFixture } from "kizlo/test"
export const blogFixture = defineFixture({
name: "blog",
plugins: ["wordpress-seo"], // wp.org slug, zip URL, or a local { path }
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
},
})Register it on local WordPress for both kizlo dev and kizlo test:
import { defineConfig } from "kizlo/config"
import { blogFixture } from "./fixtures/blog"
export default defineConfig({
dev: { local: true, fixtures: [blogFixture] },
test: { local: true, fixtures: [blogFixture] },
})