generate-factory
БесплатноБез исполняемых скриптовНе проверенAuto-generate test data factories from schemas, types, or models. Use when creating test data infrastructure, setting up fixtures, or reducing test setup…
Об этом скилле
Generate Factory Skill
Purpose
Auto-generate test data factories from database schemas, TypeScript interfaces, or model definitions. Factories produce realistic test data using Faker.js patterns, reducing test setup time by 60%.
Research Foundation
| Pattern | Source | Reference |
|---|---|---|
| Factory Pattern | ThoughtBot | FactoryBot |
| Faker.js | Open Source | fakerjs.dev |
| Test Data Management | ISTQB | CT-TAS Test Automation Strategy |
| Synthetic Data | Tonic.ai | Faker Best Practices |
When This Skill Applies
- User needs to create test data factories
- Setting up test infrastructure for new project
- Existing tests use hard-coded data
- Schema/model changes require test data updates
- Need realistic but deterministic test data
Trigger Phrases
| Natural Language | Action |
|---|---|
| "Generate factory for User model" | Create user factory |
| "Create test data factories" | Generate factories for all models |
| "Add faker to tests" | Integrate faker with existing tests |
| "Make test data realistic" | Convert hard-coded to factory |
| "Generate fixtures from schema" | Schema-aware factory generation |
Factory Concepts
Factory vs Fixture vs Mock
| Type | Purpose | When to Use |
|---|---|---|
| Factory | Generate dynamic test data | When you need many variations |
| Fixture | Static, predefined data | When exact values matter |
| Mock | Fake external dependencies | When isolating units |
Factory Features
// Basic factory
const user = userFactory.build();
// { id: 'uuid-1', name: 'John Doe', email: '[email protected]' }
// With overrides
const admin = userFactory.build({ role: 'admin' });
// { id: 'uuid-2', name: 'Jane Doe', email: '[email protected]', role: 'admin' }
// Build multiple
const users = userFactory.buildList(5);
// Array of 5 users
// With traits
const inactiveUser = userFactory.build({}, { trait: 'inactive' });
// { id: 'uuid-3', ..., status: 'inactive', deactivatedAt: Date }
// With relationships
const userWithOrders = userFactory.build({}, { with: ['orders'] });
// { id: 'uuid-4', ..., orders: [{ id: 'order-1', ... }] }
Generation Process
1. Analyze Source
Detect schema/type from:
- TypeScript interfaces
- Prisma schema
- JSON Schema
- Database migrations
- OpenAPI specs
// Input: TypeScript interface
interface User {
id: string;
name: string;
email: string;
age: number;
role: 'admin' | 'user' | 'guest';
createdAt: Date;
preferences?: UserPreferences;
}
2. Map Types to Faker
const TYPE_MAPPING = {
// Primitives
'string': 'faker.string.alphanumeric(10)',
'number': 'faker.number.int({ min: 0, max: 100 })',
'boolean': 'faker.datatype.boolean()',
'Date': 'faker.date.past()',
// Named fields (semantic mapping)
'id': 'faker.string.uuid()',
'name': 'faker.person.fullName()',
'email': 'faker.internet.email()',
'phone': 'faker.phone.number()',
'address': 'faker.location.streetAddress()',
'age': 'faker.number.int({ min: 18, max: 80 })',
'createdAt': 'faker.date.past()',
'updatedAt': 'faker.date.recent()',
// Enums
'role': 'faker.helpers.arrayElement(["admin", "user", "guest"])',
};
3. Generate Factory
// Generated: factories/user.factory.ts
import { faker } from '@faker-js/faker';
import type { User } from '../types';
export const userFactory = {
/**
* Build a single User with optional overrides
*/
build: (overrides: Partial<User> = {}): User => ({
id: faker.string.uuid(),
name: faker.person.fullName(),
email: faker.internet.email(),
age: faker.number.int({ min: 18, max: 80 }),
role: faker.helpers.arrayElement(['admin', 'user', 'guest']),
createdAt: faker.date.past(),
...overrides,
}),
/**
* Build multiple Users
*/
buildList: (count: number, overrides: Partial<User> = {}): User[] =>
Array.from({ length: count }, () => userFactory.build(overrides)),
/**
* Traits for common variations
*/
traits: {
admin: { role: 'admin' as const },
inactive: {
status: 'inactive',
deactivatedAt: faker.date.past(),
},
newUser: {
createdAt: faker.date.recent(),
},
},
/**
* Build with trait
*/
buildWithTrait: (trait: keyof typeof userFactory.traits, overrides: Partial<User> = {}): User =>
userFactory.build({ ...userFactory.traits[trait], ...overrides }),
};
4. Generate Related Factories
For entities with relationships:
// factories/order.factory.ts
import { faker } from '@faker-js/faker';
import { userFactory } from './user.factory';
export const orderFactory = {
build: (overrides = {}) => ({
id: faker.string.uuid(),
userId: faker.string.uuid(),
items: [],
total: faker
Установить generate-factory в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл generate-factory?
Auto-generate test data factories from schemas, types, or models. Use when creating test data infrastructure, setting up fixtures, or reducing test setup boilerplate.
Как установить скилл generate-factory?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл generate-factory запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic