/harness-claude:test-factory-patternsfrom harness-claude
Generates maintainable test data using factory functions, builder patterns, and faker.js for unit, integration, and snapshot tests.
Claude never picks this skill on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /harness-claude:test-factory-patterns still runs it.
What the skill costs in Claude's context, stage by stage
No description Claude Code can read, so Claude's list leaves it out: only you can start it.
SKILL.md joins the conversation and stays.
Build maintainable test data using factory functions, builders, and faker.js
function createUser(overrides?: Partial<User>): User {
return {
id: crypto.randomUUID(),
name: 'Test User',
email: `user-${crypto.randomUUID().slice(0, 8)}@test.com`,
role: 'user',
createdAt: new Date(),
...overrides,
};
}
// Usage
const admin = createUser({ role: 'admin', name: 'Admin' });
const alice = createUser({ name: 'Alice' });
import { faker } from '@faker-js/faker';
function createUser(overrides?: Partial<User>): User {
return {
id: faker.string.uuid(),
name: faker.person.fullName(),
email: faker.internet.email(),
role: 'user',
avatar: faker.image.avatar(),
createdAt: faker.date.past(),
...overrides,
};
}
class UserBuilder {
private data: Partial<User> = {};
withName(name: string): this {
this.data.name = name;
return this;
}
withRole(role: Role): this {
this.data.role = role;
return this;
}
withEmail(email: string): this {
this.data.email = email;
return this;
}
asAdmin(): this {
this.data.role = 'admin';
return this;
}
build(): User {
return createUser(this.data);
}
}
// Usage
const admin = new UserBuilder().withName('Alice').asAdmin().build();
function createPost(
overrides?: Partial<Post> & { author?: Partial<User> }
): Post & { author: User } {
const author = createUser(overrides?.author);
return {
id: crypto.randomUUID(),
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(3),
authorId: author.id,
published: false,
createdAt: new Date(),
...overrides,
author,
};
}
function createUsers(count: number, overrides?: Partial<User>): User[] {
return Array.from({ length: count }, () => createUser(overrides));
}
const tenAdmins = createUsers(10, { role: 'admin' });
faker.seed(42); // Same seed = same data every run
function createDeterministicUser(): User {
return createUser(); // Always generates the same sequence
}
async function createDbUser(prisma: PrismaClient, overrides?: Partial<User>) {
const data = createUser(overrides);
return prisma.user.create({
data: {
email: data.email,
name: data.name,
role: data.role,
},
});
}
// In tests
const user = await createDbUser(prisma, { role: 'admin' });
// test/factories/index.ts
export { createUser, createUsers, UserBuilder } from './user-factory';
export { createPost, createPosts } from './post-factory';
export { createOrder } from './order-factory';
Test factories centralize test data creation, providing consistent defaults while allowing per-test customization. They eliminate the "copy-paste test setup" anti-pattern.
Factory vs fixture vs seed:
Faker.js tips:
faker.seed(n) makes all subsequent calls deterministic — use for reproducible testsfaker.helpers.arrayElement(['a', 'b', 'c']) picks randomly from a listfaker.helpers.multiple(fn, { count: 5 }) generates multiple valuesFactory design principles:
Trade-offs:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeRead when SKILL.md points to them.
793 skills in this plugin
/a11y-aria-patternsARIA Patterns> Apply ARIA roles, states, and properties correctly to enhance assistive technology support for custom widgets/a11y-color-contrastColor Contrast and Color Independence> Ensure sufficient color contrast ratios and never use color as the sole means of conveying information/a11y-form-patternsAccessible Form Patterns> Build accessible forms with proper labeling, grouped controls, inline validation, and clear error communicationOther plugins' skills for the same job