consolidating-test-setup

Consolidates repeated test setup and teardown into the narrowest shared lifecycle owner.

2.0k|679|Updated Jun 13, 2024
One-click install
npx skills add https://github.com/Comfy-Org/ComfyUI_frontend --skill consolidating-test-setup
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: consolidating-test-setup
Source: https://github.com/Comfy-Org/ComfyUI_frontend/tree/main/.agents/skills/consolidating-test-setup
Command: npx skills add https://github.com/Comfy-Org/ComfyUI_frontend --skill consolidating-test-setup

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Test suites often accumulate duplicated initialization, cleanup, fixtures, and mock configuration across files, making maintenance costly and hiding real test intent. This Skill provides a disciplined workflow to identify genuinely repeated lifecycle behavior and move it to the narrowest shared owner without weakening isolation or hiding scenario-specific state.

Core Features & Use Cases

  • Duplication Analysis: Classifies repeated setup by owned state, lifetime, scope, and intentional differences before treating similar code as duplicates.
  • Runner-Specific Guidance: Ships dedicated references for Vitest (setup files, module mocks, vi.mock hoisting) and Playwright (fixtures, worker scope, global setup/teardown).
  • Safe Migration Workflow: A six-step process (discover, classify, challenge, place, migrate, prove) that removes suspected cargo-cult setup first and validates with full suite runs.
  • Use Case: When dozens of Vitest files repeat the same mock reset and environment setup, use this Skill to determine whether the behavior belongs in vitest.setup.ts, a scoped fixture, or should stay local, then migrate one responsibility at a time.

Quick Start

Ask the AI to consolidate the repeated test setup across the test files in this repository using the consolidating-test-setup workflow.

Frequently Asked Questions about consolidating-test-setup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I consolidate duplicated test setup across test files?

First classify each repeated block by the state it owns, its lifetime, and whether it is an invariant or scenario detail. Then remove it tentatively, run affected suites to find the real contract, and place it in the narrowest owner such as runner configuration, a setup file, or a scoped fixture.

How to share setup code in Vitest without breaking mocks?

Use vitest setupFiles only for invariants that configuration cannot express, and keep test-specific vi.mock calls inside the test module so hoisting works. For shared implementations, use __mocks__ directories with a local vi.mock, and watch for setup files that import the mock target and cache the module.

When should Playwright fixtures own setup instead of global hooks?

Fixtures should own resources that need guaranteed setup and teardown at test or worker scope, while global setup is reserved for run-wide resources. The fixture that creates a resource must release it even when the test fails, and mutable test state stays test-scoped unless broader ownership is proven safe under parallel execution.

Does moving setup to a shared file always reduce duplication?

No. A shared helper only helps if it owns a policy or lifecycle or removes meaningful reader effort; moving identical lines behind a new name is not an improvement. The workflow recommends subtracting suspected cargo-cult setup first and only centralizing after failures reveal the real contract.

Why do tests fail after moving setup into a global setup file?

Failures usually come from scope mismatches, such as shared process state leaking between suites, module mocks being cached before tests reprogram them, or cleanup not running on failure. Run the complete relevant suite rather than targeted tests, since shared lifecycle issues often appear only when unrelated suites run together.