qa-test-generate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseqa-test-generate
qa-test-generate
Produce runnable Vitest unit tests and Playwright E2E specs from BDD test cases and scaffold code.
根据BDD测试用例和脚手架代码生成可运行的Vitest单元测试和Playwright端到端(E2E)测试规格。
Context Files
上下文文件
- - Tech stack context (CRITICAL -- determines test frameworks, runners, patterns)
$JAAN_CONTEXT_DIR/tech.md- Uses sections: ,
#current-stack,#frameworks,#constraints#patterns
- Uses sections:
- - Project configuration
$JAAN_CONTEXT_DIR/config.md - - Output template
$JAAN_TEMPLATES_DIR/jaan-to:qa-test-generate.template.md - - Past lessons (loaded in Pre-Execution)
$JAAN_LEARN_DIR/jaan-to:qa-test-generate.learn.md - Research: - playwright-bdd, jest-cucumber, tag routing, test data factories, MSW, Vitest workspaces, CI execution
$JAAN_OUTPUTS_DIR/research/71-qa-bdd-gherkin-test-code-generation.md - - Language resolution protocol
${CLAUDE_PLUGIN_ROOT}/docs/extending/language-protocol.md
- - 技术栈上下文(至关重要——决定测试框架、运行器和模式)
$JAAN_CONTEXT_DIR/tech.md- 使用的章节:、
#current-stack、#frameworks、#constraints#patterns
- 使用的章节:
- - 项目配置
$JAAN_CONTEXT_DIR/config.md - - 输出模板
$JAAN_TEMPLATES_DIR/jaan-to:qa-test-generate.template.md - - 过往经验(预执行阶段加载)
$JAAN_LEARN_DIR/jaan-to:qa-test-generate.learn.md - 研究资料:- playwright-bdd、jest-cucumber、标签路由、测试数据工厂、MSW、Vitest工作区、CI执行
$JAAN_OUTPUTS_DIR/research/71-qa-bdd-gherkin-test-code-generation.md - - 语言解析协议
${CLAUDE_PLUGIN_ROOT}/docs/extending/language-protocol.md
Input
输入
Upstream Artifacts: $ARGUMENTS
Accepts 1-3 file paths or descriptions:
- qa-test-cases (REQUIRED) -- Path to BDD/Gherkin test cases output (from )
/jaan-to:qa-test-cases - backend-scaffold OR frontend-scaffold (REQUIRED) -- Path to scaffold output (from or
/jaan-to:backend-scaffold)/jaan-to:frontend-scaffold - backend-api-contract (optional) -- Path to OpenAPI YAML (from ) for MSW handler generation and API assertion data
/jaan-to:backend-api-contract - backend-service-implement (optional) -- Path to filled service files for deeper unit test generation
- Empty -- Interactive wizard prompting for each artifact
IMPORTANT: The input above is your starting point. Determine mode and proceed accordingly.
上游工件:$ARGUMENTS
接受1-3个文件路径或描述:
- qa-test-cases(必填)—— BDD/Gherkin测试用例输出的路径(来自)
/jaan-to:qa-test-cases - backend-scaffold 或 frontend-scaffold(必填)—— 脚手架输出的路径(来自或
/jaan-to:backend-scaffold)/jaan-to:frontend-scaffold - backend-api-contract(可选)—— OpenAPI YAML文件路径(来自),用于生成MSW处理器和API断言数据
/jaan-to:backend-api-contract - backend-service-implement(可选)—— 已填充的服务文件路径,用于生成更深度的单元测试
- 空值—— 交互式向导,会提示输入每个工件
重要提示:以上输入是你的起点,请确定模式并继续执行。
Pre-Execution Protocol
预执行协议
MANDATORY — Read and execute ALL steps in:
Skill name:
Execute: Step 0 (Init Guard) → A (Load Lessons) → B (Resolve Template) → C (Offer Template Seeding)
${CLAUDE_PLUGIN_ROOT}/docs/extending/pre-execution-protocol.mdqa-test-generateAlso read the comprehensive research document:
$JAAN_OUTPUTS_DIR/research/71-qa-bdd-gherkin-test-code-generation.mdThis provides:
- BDD-to-assertion mapping patterns: Cucumber.js classic, jest-cucumber binding, playwright-bdd decorator (Section 1)
- Test data factory generation with Fishery and @anatine/zod-mock (Section 2)
- MSW mock handler generation from OpenAPI contracts (Section 3)
- Vitest workspace configuration for BDD test separation (Section 4)
- Playwright configuration for BDD with playwright-bdd (Section 5)
- Tag-based test routing architecture (Section 6)
- Coverage target strategies and tiered model (Section 7)
- Fixture management and centralized architecture (Section 8)
- Database seeding for integration tests (Section 9)
- CI-friendly execution with GitHub Actions (Section 10)
Also read context files if available:
- -- Know the tech stack for framework-specific test generation
$JAAN_CONTEXT_DIR/tech.md
If files do not exist, continue without them.
强制要求 — 阅读并执行以下路径中的所有步骤:
技能名称:
执行步骤:步骤0(初始化校验)→ A(加载过往经验)→ B(解析模板)→ C(提供模板填充)
${CLAUDE_PLUGIN_ROOT}/docs/extending/pre-execution-protocol.mdqa-test-generate同时请阅读完整的研究文档:
$JAAN_OUTPUTS_DIR/research/71-qa-bdd-gherkin-test-code-generation.md该文档包含:
- BDD到断言的映射模式:Cucumber.js经典模式、jest-cucumber绑定、playwright-bdd装饰器(第1节)
- 使用Fishery和@anatine/zod-mock生成测试数据工厂(第2节)
- 根据OpenAPI契约生成MSW模拟处理器(第3节)
- 用于BDD测试分离的Vitest工作区配置(第4节)
- 结合playwright-bdd的Playwright配置(第5节)
- 基于标签的测试路由架构(第6节)
- 覆盖率目标策略和分层模型(第7节)
- 夹具管理和集中式架构(第8节)
- 用于集成测试的数据库填充(第9节)
- 适配GitHub Actions的CI友好型执行(第10节)
如果上下文文件可用,请阅读:
- — 了解技术栈,以便生成框架特定的测试
$JAAN_CONTEXT_DIR/tech.md
如果文件不存在,可跳过继续执行。
Language Settings
语言设置
Read and apply language protocol:
Override field for this skill:
${CLAUDE_PLUGIN_ROOT}/docs/extending/language-protocol.mdlanguage_qa-test-generateLanguage exception: Generated code output (variable names, code blocks, test files, config files) is NOT affected by this setting and remains in the project's programming language.
阅读并应用语言协议:
本技能的覆盖字段:
${CLAUDE_PLUGIN_ROOT}/docs/extending/language-protocol.mdlanguage_qa-test-generate语言例外:生成的代码输出(变量名、代码块、测试文件、配置文件)不受此设置影响,将保持项目的编程语言。
PHASE 1: Analysis (Read-Only)
阶段1:分析(只读)
Thinking Mode
思考模式
ultrathink
Use extended reasoning for:
- Parsing BDD scenarios and mapping @tags to test tiers
- Analyzing scaffold code to identify testable units
- Planning test data factory structure from schemas
- Designing MSW handler strategy from API contract
- Mapping Given/When/Then to Vitest assertions and Playwright actions
深度思考
使用扩展推理来完成:
- 解析BDD场景并将@tags映射到测试层级
- 分析脚手架代码以识别可测试单元
- 根据规划设计测试数据工厂结构
- 根据API契约设计MSW处理器策略
- 将Given/When/Then步骤映射到Vitest断言和Playwright操作
Step 1: Validate & Parse Inputs
步骤1:验证并解析输入
For each provided path:
qa-test-cases (REQUIRED):
- Read the BDD/Gherkin test cases markdown
- Extract all blocks with
Feature:@tags - Parse each extracting Given/When/Then steps
Scenario: - Build tag inventory: count of @smoke, @e2e, @unit, @integration, @boundary, @edge-case, etc.
- Extract concrete test data values from steps
backend-scaffold OR frontend-scaffold (REQUIRED):
- Read scaffold output files
- Extract service layer functions (unit test targets)
- Extract route handlers (integration test targets)
- Extract component files (frontend hook/component test targets)
- Identify validation schemas (Zod, yup, or similar)
backend-api-contract (optional):
- Read OpenAPI YAML/JSON
- Extract endpoint paths, methods, request/response schemas
- Map to MSW handler generation targets
- Extract example request/response payloads for assertions
backend-service-implement (optional):
- Read filled service files
- Identify business logic branches for deeper unit tests
- Extract dependency injection points for mocking
Present input summary:
INPUT SUMMARY
-------------------------------------------------------------
Sources Found: {list of found artifacts}
Sources Missing: {list with impact assessment}
BDD Scenarios: {total count}
@smoke: {count}
@unit: {count}
@integration: {count}
@e2e: {count}
@boundary: {count}
@edge-case: {count}
Testable Code Units:
Services: {count from scaffold}
Routes/Handlers: {count from scaffold}
Components/Hooks: {count if frontend}
Schemas: {count}
API Endpoints: {count from contract, or "N/A"}对于每个提供的路径:
qa-test-cases(必填):
- 读取BDD/Gherkin测试用例的Markdown文件
- 提取所有带的
@tags块Feature: - 解析每个,提取Given/When/Then步骤
Scenario: - 构建标签清单:统计@smoke、@e2e、@unit、@integration、@boundary、@edge-case等标签的数量
- 从步骤中提取具体的测试数据值
backend-scaffold 或 frontend-scaffold(必填):
- 读取脚手架输出文件
- 提取服务层函数(单元测试目标)
- 提取路由处理器(集成测试目标)
- 提取组件文件(前端钩子/组件测试目标)
- 识别验证模式(Zod、yup或类似工具)
backend-api-contract(可选):
- 读取OpenAPI YAML/JSON文件
- 提取端点路径、方法、请求/响应模式
- 映射到MSW处理器生成目标
- 提取示例请求/响应负载用于断言
backend-service-implement(可选):
- 读取已填充的服务文件
- 识别业务逻辑分支以生成更深度的单元测试
- 提取依赖注入点用于模拟
展示输入摘要:
输入摘要
-------------------------------------------------------------
已找到的来源: {已找到的工件列表}
缺失的来源: {带影响评估的列表}
BDD场景数量: {总数量}
@smoke: {数量}
@unit: {数量}
@integration: {数量}
@e2e: {数量}
@boundary: {数量}
@edge-case: {数量}
可测试代码单元:
服务: {来自脚手架的数量}
路由/处理器: {来自脚手架的数量}
组件/钩子: {如果是前端则统计数量}
验证模式: {数量}
API端点: {来自契约的数量,或“不适用”}Step 2: Detect Test Framework Preferences
步骤2:检测测试框架偏好
Read for test framework detection:
$JAAN_CONTEXT_DIR/tech.md- Extract test runner from (default: Vitest for unit/integration, Playwright for E2E)
#frameworks - Extract existing test setup patterns
- Check for existing factory libraries (Fishery, faker.js)
- Check for existing mock libraries (MSW, nock)
If tech.md missing or incomplete, use AskUserQuestion:
- "Which test runner for unit/integration tests?" -- Options: "Vitest" (default), "Jest", "Other"
- "Which E2E framework?" -- Options: "Playwright" (default), "Cypress", "Other"
- "Any existing test data libraries?" -- Options: "Fishery", "@anatine/zod-mock", "faker.js only", "None"
- "Any existing API mocking?" -- Options: "MSW", "nock", "None"
读取以检测测试框架:
$JAAN_CONTEXT_DIR/tech.md- 从中提取测试运行器(默认:单元/集成测试用Vitest,E2E测试用Playwright)
#frameworks - 提取现有的测试设置模式
- 检查是否存在现有的工厂库(Fishery、faker.js)
- 检查是否存在现有的模拟库(MSW、nock)
如果tech.md缺失或不完整,使用AskUserQuestion:
- “单元/集成测试使用哪个测试运行器?” — 选项:“Vitest”(默认)、“Jest”、“其他”
- “E2E测试使用哪个框架?” — 选项:“Playwright”(默认)、“Cypress”、“其他”
- 是否有现有的测试数据库?” — 选项:“Fishery”、“@anatine/zod-mock”、“仅faker.js”、“无”
- “是否有现有的API模拟工具?” — 选项:“MSW”、“nock”、“无”
Step 3: Map Tags to Test Tiers (Research Section 6)
步骤3:将标签映射到测试层级(研究第6节)
Route BDD scenarios to test tiers based on tag taxonomy.
Reference: Seesection "Detailed Tag Routing Map" for the full tag-to-tier routing table with target descriptions.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
根据标签分类法将BDD场景路由到测试层级。
参考:请参阅中的“详细标签路由映射”部分,获取完整的标签到层级的路由表及目标说明。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
Step 4: Plan Test Generation Inventory
步骤4:规划测试生成清单
Calculate totals and present plan:
TEST GENERATION PLAN
-------------------------------------------------------------
Config Files:
- vitest.config.ts (workspace with unit + integration)
- playwright.config.ts (with playwright-bdd)
- test/setup/unit.ts (MSW server setup)
- test/setup/integration.ts (DB + MSW setup)
- test/mocks/server.ts (MSW server instance)
- test/mocks/handlers.ts (auto-generated from API contract)
Test Data:
- test/factories/{entity}.factory.ts ({count} factories)
- test/fixtures/db-seed.ts (DB seeding scenarios)
- test/utils/test-utils.ts (shared test helpers)
Unit Tests ({count} files):
{list of service.test.ts and hook.test.ts files}
Integration Tests ({count} files):
{list of integration.test.ts files}
E2E Tests ({count} files):
{list of Playwright .spec.ts files per user flow}
Coverage Targets:
- Unit: 80% line, 70% branch
- Integration: 60% line
- E2E: 100% of acceptance criteria scenarios
- BDD: All Given/When/Then steps mapped to assertions计算总数并展示计划:
测试生成计划
-------------------------------------------------------------
配置文件:
- vitest.config.ts(包含单元+集成测试的工作区)
- playwright.config.ts(结合playwright-bdd)
- test/setup/unit.ts(MSW服务器设置)
- test/setup/integration.ts(数据库+MSW设置)
- test/mocks/server.ts(MSW服务器实例)
- test/mocks/handlers.ts(根据API契约自动生成)
测试数据:
- test/factories/{entity}.factory.ts({数量}个工厂)
- test/fixtures/db-seed.ts(数据库填充场景)
- test/utils/test-utils.ts(共享测试工具)
单元测试({数量}个文件):
{service.test.ts和hook.test.ts文件列表}
集成测试({数量}个文件):
{integration.test.ts文件列表}
E2E测试({数量}个文件):
{每个用户流对应的Playwright .spec.ts文件列表}
覆盖率目标:
- 单元测试:80%行覆盖率,70%分支覆盖率
- 集成测试:60%行覆盖率
- E2E测试:100%验收标准场景覆盖率
- BDD:所有Given/When/Then步骤都映射到断言HARD STOP -- Human Review Check
强制暂停 -- 人工审核检查
Show complete plan before generating:
FINAL CONFIRMATION
-------------------------------------------------------------
Source Artifacts:
- qa-test-cases: {path}
- scaffold: {path}
- api-contract: {path or "N/A"}
Test Framework Stack:
- Unit/Integration: {Vitest/Jest}
- E2E: {Playwright/Cypress}
- BDD Binding: {jest-cucumber adapted for Vitest / playwright-bdd}
- Mocking: {MSW / nock}
- Factories: {Fishery + @anatine/zod-mock / faker.js}
Output Folder: $JAAN_OUTPUTS_DIR/qa/test-generate/{id}-{slug}/
Total Files: {count}
Files to Generate:
Config: {count} files (vitest.config.ts, playwright.config.ts, setup files)
Factories: {count} files (test data factories + db-seed)
Unit Tests: {count} files ({total_scenarios} scenarios)
Integration: {count} files ({total_scenarios} scenarios)
E2E Tests: {count} files ({total_scenarios} scenarios)
Utilities: {count} files (test-utils, msw-handlers)Use AskUserQuestion:
- Question: "Proceed with test file generation?"
- Header: "Generate Tests"
- Options:
- "Yes" -- Generate all test files
- "No" -- Cancel
- "Edit" -- Let me revise the scope or framework choices
Do NOT proceed to Phase 2 without explicit approval.
在生成前展示完整计划:
最终确认
-------------------------------------------------------------
来源工件:
- qa-test-cases:{路径}
- 脚手架:{路径}
- api-contract:{路径或“不适用”}
测试技术栈:
- 单元/集成测试:{Vitest/Jest}
- E2E测试:{Playwright/Cypress}
- BDD绑定:{适配Vitest的jest-cucumber / playwright-bdd}
- 模拟工具:{MSW / nock}
- 工厂库:{Fishery + @anatine/zod-mock / faker.js}
输出文件夹:$JAAN_OUTPUTS_DIR/qa/test-generate/{id}-{slug}/
总文件数:{数量}
待生成的文件:
配置文件: {数量}个(vitest.config.ts、playwright.config.ts、设置文件)
工厂文件: {数量}个(测试数据工厂+数据库填充)
单元测试: {数量}个文件({总场景数}个场景)
集成测试: {数量}个文件({总场景数}个场景)
E2E测试: {数量}个文件({总场景数}个场景)
工具类: {数量}个文件(test-utils、msw-handlers)使用AskUserQuestion:
- 问题:“是否继续生成测试文件?”
- 标题:“生成测试”
- 选项:
- “是” — 生成所有测试文件
- “否” — 取消
- “编辑” — 让我修改范围或框架选择
未获得明确批准前,不得进入阶段2。
PHASE 2: Generation (Write Phase)
阶段2:生成(写入阶段)
Step 5: Generate Config Files
步骤5:生成配置文件
Reference: Seesection "Config Generation Specifications" for Vitest workspace, Playwright, and setup file configurations.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
参考:请参阅中的“配置生成规范”部分,获取Vitest工作区、Playwright和设置文件的配置说明。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
Step 6: Generate Test Data Layer
步骤6:生成测试数据层
Reference: Seesection "Test Data Layer Patterns" for factory, MSW handler, DB seed, and test utility generation patterns.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
参考:请参阅中的“测试数据层模式”部分,获取工厂、MSW处理器、数据库填充和测试工具的生成模式。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
Step 7: Generate Unit Tests
步骤7:生成单元测试
For each BDD scenario tagged @unit, @smoke (unit portion), @boundary, @negative (unit portion):
对于每个标记为@unit、@smoke(单元测试部分)、@boundary、@negative(单元测试部分)的BDD场景:
7.1 Convert Given/When/Then to Vitest Assertions
7.1 将Given/When/Then转换为Vitest断言
Map each BDD scenario to a Vitest describe/it block using jest-cucumber binding pattern adapted for Vitest.
Reference: Seesection "BDD Binding Code Templates" for the feature-scoped step definition code template.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
使用适配Vitest的jest-cucumber绑定模式,将每个BDD场景映射到Vitest的describe/it块。
参考:请参阅中的“BDD绑定代码模板”部分,获取功能范围的步骤定义代码模板。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
7.2 Service Unit Tests
7.2 服务单元测试
For each service function in scaffold:
- Import service and create test file
- Mock dependencies (Prisma, external APIs) using
vi.mock() - Map BDD Given steps to mock setup
- Map BDD When steps to service function calls
- Map BDD Then steps to assertions
expect() - Include boundary value tests from @boundary scenarios
- Include error handling tests from @negative scenarios
对于脚手架中的每个服务函数:
- 导入服务并创建测试文件
- 使用模拟依赖(Prisma、外部API等)
vi.mock() - 将BDD的Given步骤映射到模拟设置
- 将BDD的When步骤映射到服务函数调用
- 将BDD的Then步骤映射到断言
expect() - 包含来自@boundary场景的边界值测试
- 包含来自@negative场景的错误处理测试
7.3 Hook/Component Tests (Frontend)
7.3 钩子/组件测试(前端)
If frontend-scaffold provided:
- Generate React hook tests using from @testing-library/react
renderHook - Generate component tests using from @testing-library/react
render - Mock API calls with MSW handlers
- Map BDD UI scenarios to component assertions
如果提供了frontend-scaffold:
- 使用@testing-library/react的生成React钩子测试
renderHook - 使用@testing-library/react的生成组件测试
render - 使用MSW处理器模拟API调用
- 将BDD的UI场景映射到组件断言
Step 8: Generate Integration Tests
步骤8:生成集成测试
For each BDD scenario tagged @integration, @api:
Reference: Seesection "Integration Test Patterns" for API and service integration test generation patterns.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
对于每个标记为@integration、@api的BDD场景:
参考:请参阅中的“集成测试模式”部分,获取API和服务集成测试的生成模式。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
Step 9: Generate E2E Tests
步骤9:生成E2E测试
For each BDD scenario tagged @e2e, @smoke (E2E portion), @mobile:
对于每个标记为@e2e、@smoke(E2E部分)、@mobile的BDD场景:
9.1 Playwright BDD Specs (Research Section 5)
9.1 Playwright BDD规格(研究第5节)
Generate step definitions using playwright-bdd's pattern with Given/When/Then mapped to Playwright page actions.
createBddReference: Seesection "Playwright BDD Step Templates" for the playwright-bdd step definition code template.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
Reference: Seesection "E2E Page Object Patterns" for page object generation and fixture composition patterns.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
使用playwright-bdd的模式生成步骤定义,将Given/When/Then映射到Playwright页面操作。
createBdd参考:请参阅中的“Playwright BDD步骤模板”部分,获取playwright-bdd的步骤定义代码模板。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
参考:请参阅中的“E2E页面对象模式”部分,获取页面对象生成和夹具组合模式。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
Step 10: Quality Check
步骤10:质量检查
Before preview, validate generated tests against all quality criteria.
Reference: Seesection "Quality Check Checklist" for the full validation checklist (completeness, test data, configuration, code quality).${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
If any check fails, fix before proceeding.
在预览前,根据所有质量标准验证生成的测试。
参考:请参阅中的“质量检查清单”部分,获取完整的验证清单(完整性、测试数据、配置、代码质量)。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
如果任何检查不通过,请在继续前修复问题。
Step 11: Preview & Approval
步骤11:预览与批准
11.1 Generate Output Metadata
11.1 生成输出元数据
bash
source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/id-generator.sh"
SUBDOMAIN_DIR="$JAAN_OUTPUTS_DIR/qa/test-generate"
mkdir -p "$SUBDOMAIN_DIR"
NEXT_ID=$(generate_next_id "$SUBDOMAIN_DIR")Generate slug:
- Extract feature name from primary BDD test case title
- Convert to lowercase-kebab-case
- Max 50 characters
bash
source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/id-generator.sh"
SUBDOMAIN_DIR="$JAAN_OUTPUTS_DIR/qa/test-generate"
mkdir -p "$SUBDOMAIN_DIR"
NEXT_ID=$(generate_next_id "$SUBDOMAIN_DIR")生成slug:
- 从主BDD测试用例标题中提取功能名称
- 转换为小写短横线格式
- 最多50个字符
11.2 Generate Executive Summary
11.2 生成执行摘要
Template:
Runnable test suite for {feature_name} generated from {scenario_count} BDD scenarios
and {scaffold_type} scaffold code. Includes {unit_count} Vitest unit tests,
{integration_count} integration tests, and {e2e_count} Playwright E2E specs.
Test infrastructure: {factory_count} data factories, MSW mock handlers,
Vitest workspace config, and Playwright BDD config. Coverage targets:
80% line (unit), 60% line (integration), 100% scenario (E2E).模板:
为{feature_name}生成的可运行测试套件,基于{scenario_count}个BDD场景
和{scaffold_type}脚手架代码。包含{unit_count}个Vitest单元测试、
{integration_count}个集成测试和{e2e_count}个Playwright E2E测试规格。
测试基础设施:{factory_count}个数据工厂、MSW模拟处理器、
Vitest工作区配置和Playwright BDD配置。覆盖率目标:
单元测试80%行覆盖率,集成测试60%行覆盖率,E2E测试100%场景覆盖率。11.3 Show Preview
11.3 展示预览
OUTPUT PREVIEW
-------------------------------------------------------------
ID: {NEXT_ID}
Folder: $JAAN_OUTPUTS_DIR/qa/test-generate/{NEXT_ID}-{slug}/
Files:
{NEXT_ID}-{slug}.md (Test strategy + coverage map)
config/
vitest.config.ts (Workspace config)
playwright.config.ts (BDD + projects config)
setup/unit.ts (MSW lifecycle)
setup/integration.ts (DB + MSW setup)
mocks/server.ts (MSW server)
mocks/handlers.ts (Auto-generated handlers)
test-utils.ts (Shared helpers + matchers)
unit/
{service-name}.test.ts ({n} scenarios)
...
integration/
{resource-name}.integration.test.ts ({n} scenarios)
...
e2e/
{flow-name}.spec.ts ({n} scenarios)
steps/{feature}.steps.ts (Step definitions)
steps/fixtures.ts (Page object fixtures)
pages/{page}.page.ts (Page objects)
fixtures/
factories/{entity}.factory.ts ({n} factories)
db-seed.ts (Seed scenarios)
[Show first unit test file as preview snippet]
[Show first E2E step definition as preview snippet]Use AskUserQuestion:
- Question: "Write test files to output?"
- Header: "Write Files"
- Options:
- "Yes" -- Write all files
- "No" -- Cancel
- "Refine" -- Make adjustments first
输出预览
-------------------------------------------------------------
ID: {NEXT_ID}
文件夹: $JAAN_OUTPUTS_DIR/qa/test-generate/{NEXT_ID}-{slug}/
文件列表:
{NEXT_ID}-{slug}.md (测试策略+覆盖率映射)
config/
vitest.config.ts (工作区配置)
playwright.config.ts (BDD + 项目配置)
setup/unit.ts (MSW生命周期)
setup/integration.ts (数据库 + MSW设置)
mocks/server.ts (MSW服务器)
mocks/handlers.ts (自动生成的处理器)
test-utils.ts (共享工具 + 匹配器)
unit/
{service-name}.test.ts ({n}个场景)
...
integration/
{resource-name}.integration.test.ts ({n}个场景)
...
e2e/
{flow-name}.spec.ts ({n}个场景)
steps/{feature}.steps.ts (步骤定义)
steps/fixtures.ts (页面对象夹具)
pages/{page}.page.ts (页面对象)
fixtures/
factories/{entity}.factory.ts ({n}个工厂)
db-seed.ts (填充场景)
[展示第一个单元测试文件的预览片段]
[展示第一个E2E步骤定义的预览片段]使用AskUserQuestion:
- 问题:“是否将测试文件写入输出目录?”
- 标题:“写入文件”
- 选项:
- “是” — 写入所有文件
- “否” — 取消
- “优化” — 先进行调整
Step 12: Write Output Files
步骤12:写入输出文件
If approved:
如果获得批准:
12.1 Create Folder
12.1 创建文件夹
bash
OUTPUT_FOLDER="$JAAN_OUTPUTS_DIR/qa/test-generate/${NEXT_ID}-${slug}"
mkdir -p "$OUTPUT_FOLDER"
mkdir -p "$OUTPUT_FOLDER/config/setup"
mkdir -p "$OUTPUT_FOLDER/config/mocks"
mkdir -p "$OUTPUT_FOLDER/unit"
mkdir -p "$OUTPUT_FOLDER/integration"
mkdir -p "$OUTPUT_FOLDER/e2e/steps"
mkdir -p "$OUTPUT_FOLDER/e2e/pages"
mkdir -p "$OUTPUT_FOLDER/fixtures/factories"bash
OUTPUT_FOLDER="$JAAN_OUTPUTS_DIR/qa/test-generate/${NEXT_ID}-${slug}"
mkdir -p "$OUTPUT_FOLDER"
mkdir -p "$OUTPUT_FOLDER/config/setup"
mkdir -p "$OUTPUT_FOLDER/config/mocks"
mkdir -p "$OUTPUT_FOLDER/unit"
mkdir -p "$OUTPUT_FOLDER/integration"
mkdir -p "$OUTPUT_FOLDER/e2e/steps"
mkdir -p "$OUTPUT_FOLDER/e2e/pages"
mkdir -p "$OUTPUT_FOLDER/fixtures/factories"12.2 Write Main Document
12.2 写入主文档
Path:
$OUTPUT_FOLDER/${NEXT_ID}-${slug}.mdUse template from:
$JAAN_TEMPLATES_DIR/jaan-to:qa-test-generate.template.mdFill sections:
- Title, Executive Summary
- Test Strategy (tag routing, tier mapping)
- Coverage Map (BDD scenario -> test file mapping)
- Framework Configuration Summary
- Test Data Strategy
- CI Execution Guide
- Metadata
路径:
$OUTPUT_FOLDER/${NEXT_ID}-${slug}.md使用模板:
$JAAN_TEMPLATES_DIR/jaan-to:qa-test-generate.template.md填充章节:
- 标题、执行摘要
- 测试策略(标签路由、层级映射)
- 覆盖率映射(BDD场景 -> 测试文件映射)
- 框架配置摘要
- 测试数据策略
- CI执行指南
- 元数据
12.3 Write Config Files
12.3 写入配置文件
Write all configuration and setup files to
$OUTPUT_FOLDER/config/将所有配置和设置文件写入
$OUTPUT_FOLDER/config/12.4 Write Unit Tests
12.4 写入单元测试
Write all unit test files to
$OUTPUT_FOLDER/unit/将所有单元测试文件写入
$OUTPUT_FOLDER/unit/12.5 Write Integration Tests
12.5 写入集成测试
Write all integration test files to
$OUTPUT_FOLDER/integration/将所有集成测试文件写入
$OUTPUT_FOLDER/integration/12.6 Write E2E Tests
12.6 写入E2E测试
Write all E2E test files to
$OUTPUT_FOLDER/e2e/将所有E2E测试文件写入
$OUTPUT_FOLDER/e2e/12.7 Write Fixtures
12.7 写入夹具
Write all factory and seed files to
$OUTPUT_FOLDER/fixtures/将所有工厂和填充文件写入
$OUTPUT_FOLDER/fixtures/12.8 Update Index
12.8 更新索引
bash
source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/index-updater.sh"
add_to_index \
"$SUBDOMAIN_DIR/README.md" \
"$NEXT_ID" \
"${NEXT_ID}-${slug}" \
"{Feature Name} Test Suite" \
"{Executive Summary}"bash
source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/index-updater.sh"
add_to_index \
"$SUBDOMAIN_DIR/README.md" \
"$NEXT_ID" \
"${NEXT_ID}-${slug}" \
"{功能名称}测试套件" \
"{执行摘要}"12.9 Confirm Completion
12.9 确认完成
TEST SUITE GENERATED
-------------------------------------------------------------
ID: {NEXT_ID}
Folder: $JAAN_OUTPUTS_DIR/qa/test-generate/{NEXT_ID}-{slug}/
Index: Updated $JAAN_OUTPUTS_DIR/qa/test-generate/README.md
Total Files: {count}
Config: {count}
Unit Tests: {count} ({scenario_count} scenarios)
Integration: {count} ({scenario_count} scenarios)
E2E Tests: {count} ({scenario_count} scenarios)
Fixtures: {count} ({factory_count} factories)
Coverage Targets:
Unit: 80% line, 70% branch
Integration: 60% line
E2E: 100% of acceptance criteria测试套件已生成
-------------------------------------------------------------
ID: {NEXT_ID}
文件夹: $JAAN_OUTPUTS_DIR/qa/test-generate/{NEXT_ID}-{slug}/
索引: 已更新$JAAN_OUTPUTS_DIR/qa/test-generate/README.md
总文件数: {count}
配置文件: {count}
单元测试: {count} ({scenario_count}个场景)
集成测试: {count} ({scenario_count}个场景)
E2E测试: {count} ({scenario_count}个场景)
夹具文件: {count} ({factory_count}个工厂)
覆盖率目标:
单元测试: 80%行覆盖率,70%分支覆盖率
集成测试: 60%行覆盖率
E2E测试: 100%验收标准覆盖率Step 13: Suggest Next Actions
步骤13:建议后续操作
Test suite generated successfully!Next Steps:
- Copy test files to your project's
directorytest/- Run
to add test dependencies (vitest, playwright, fishery, msw, etc.)npm install- Run
to execute unit testsnpx vitest run --workspace=unit- Run
to execute E2E testsnpx playwright test- Run
to review test quality (when available)/jaan-to:qa-test-review- See the main document for full CI integration guide
测试套件生成成功!后续步骤:
- 将测试文件复制到项目的
目录test/- 运行
安装测试依赖(vitest、playwright、fishery、msw等)npm install- 运行
执行单元测试npx vitest run --workspace=unit- 运行
执行E2E测试npx playwright test- 运行
审核测试质量(可用时)/jaan-to:qa-test-review- 请参阅主文档获取完整的CI集成指南
Step 14: Capture Feedback
步骤14:收集反馈
Use AskUserQuestion:
- Question: "How did the test generation turn out?"
- Header: "Feedback"
- Options:
- "Perfect!" -- Done
- "Needs fixes" -- What should I improve?
- "Learn from this" -- Capture a lesson for future runs
If "Learn from this": Run
/jaan-to:learn-add qa-test-generate "{feedback}"Reference: Seesection "Key Generation Rules" for BDD-to-assertion mapping table, tag-to-tier routing, test data factory and MSW handler patterns, and anti-patterns to avoid.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
使用AskUserQuestion:
- 问题:“测试生成结果如何?”
- 标题:“反馈”
- 选项:
- “完美!” — 完成
- “需要修复” — 我需要改进哪些方面?
- “从中学习” — 为未来的执行记录经验
如果选择“从中学习”:运行
/jaan-to:learn-add qa-test-generate "{反馈内容}"参考:请参阅中的“关键生成规则”部分,获取BDD到断言的映射表、标签到层级的路由、测试数据工厂和MSW处理器模式,以及需要避免的反模式。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
Skill Alignment
技能对齐
- Two-phase workflow with HARD STOP for human approval
- Multi-stack support via detection
tech.md - Template-driven output structure
- Output to standardized path
$JAAN_OUTPUTS_DIR
- 包含人工批准环节的两阶段工作流
- 通过检测支持多技术栈
tech.md - 基于模板的输出结构
- 输出到标准化的路径
$JAAN_OUTPUTS_DIR
Definition of Done
完成定义
Reference: Seesection "Definition of Done Checklist" for the complete checklist.${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md
参考:请参阅中的“完成定义清单”部分,获取完整的检查清单。${CLAUDE_PLUGIN_ROOT}/docs/extending/qa-test-generate-reference.md