Agent skill
test-factory-patterns
This skill provides guidance for writing test factories in the Packmind codebase. It should be used when creating or updating factory functions in `**/test/*Factory.ts` files to ensure realistic test data with variety.
Install this agent skill to your Project
npx add-skill https://github.com/PackmindHub/packmind/tree/main/.claude/skills/test-factory-patterns
SKILL.md
Test Factory Patterns
Overview
Test factories create realistic test data with variety. Good factories generate multiple plausible instances and randomly select one, while allowing partial overrides. Poor factories return identical static data every time.
The Pattern
Good Factory Structure
A well-designed factory:
- Defines an array of multiple realistic instances with meaningful, varied content
- Uses
randomIn()to select one instance randomly - Spreads partial overrides to allow customization
import { Factory, randomIn } from '@packmind/test-utils';
import { Entity, createEntityId } from '@packmind/types';
import { v4 as uuidv4 } from 'uuid';
export const entityFactory: Factory<Entity> = (entity?: Partial<Entity>) => {
const entities: Entity[] = [
{
id: createEntityId(uuidv4()),
name: 'Meaningful Name One',
slug: 'meaningful-name-one',
content: `Realistic content that represents actual usage...`,
// ... other fields with realistic values
},
{
id: createEntityId(uuidv4()),
name: 'Different Meaningful Name',
slug: 'different-meaningful-name',
content: `Different realistic content...`,
// ... other fields with different realistic values
},
// Add 3-5 varied instances
];
return {
...randomIn(entities),
...entity,
};
};
Bad Factory Structure (Avoid)
Avoid factories that return identical static data:
// BAD: Always returns the same data
export const entityFactory: Factory<Entity> = (entity?: Partial<Entity>) => {
return {
id: createEntityId(uuidv4()),
name: 'Test Entity', // Static, meaningless
content: 'test content', // Not realistic
...entity,
};
};
Guidelines
Content Quality
- Use realistic, domain-appropriate content (not "test", "foo", "bar")
- Include variety that reflects actual usage patterns
- Make names and slugs consistent with each other
Instance Count
- Include 3-5 varied instances in the array
- Each instance should represent a plausible real-world case
Required Imports
import { Factory, randomIn } from '@packmind/test-utils';
ID Generation
- Always generate fresh UUIDs for IDs using
createXxxId(uuidv4()) - Never hardcode static UUIDs
Override Support
- Always spread partial overrides last:
...entity - This allows tests to customize specific fields while keeping realistic defaults
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
working-with-playground-app
This skill provides guidance for building UI/UX prototypes in the Packmind playground app. It should be used when creating a new prototype, iterating on an existing prototype, or working with files in apps/playground/. Triggers on mentions of "playground", "prototype", or direct work within the apps/playground/ directory.
qa-review
Review a user story implementation against its Example Mapping (EM) specification.
packmind-create-command
Guide for creating reusable commands via the Packmind CLI. This skill should be used when users want to create a new command that captures multi-step workflows, recipes, or task automation for distribution to CoPilot.
doc-audit
Audit Packmind end-user documentation (apps/doc/) for broken links, outdated CLI references, non-existent concepts, misleading information, and missing coverage. Produces a structured markdown report at project root. Use when docs may have drifted from the codebase, before a release, or on a regular cadence.
git-commit-guidelines
Enforce git commit best practices using gitmoji + Conventional Commits format. TRIGGER when creating commits. Ensures quality-gate passes, prevents issue auto-closing (no Close/Fix keywords), includes Co-Authored-By for AI commits, and requires user approval before committing.
internal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).
Didn't find tool you were looking for?