S

Svelte Test Fix Processor

A command template for svelte workflows. Streamlines development with pre-configured patterns and best practices.

CommandClipticssveltev1.0.0MIT
0 views0 copies

Svelte Test Fix Processor

Troubleshoot and fix failing tests in Svelte and SvelteKit projects by analyzing error messages, identifying failure patterns, and applying targeted fixes.

When to Use This Command

Run this command when...

  • Your Svelte component tests are failing and you need systematic diagnosis of the root cause from error messages and stack traces
  • You have flaky tests that pass intermittently and need stabilization through proper async handling, cleanup, or mocking
  • Your test suite broke after a Svelte, SvelteKit, or testing library version upgrade and needs compatibility fixes

Do NOT use this command when...

  • You need to write tests from scratch -- use the test creation command instead
  • Your tests are passing but you want to improve coverage or refactor test structure

Quick Start

# .claude/commands/svelte-test-fix-processor.md # Fix failing Svelte tests Fix tests: $ARGUMENTS
# Run the command claude "svelte-test-fix-processor fix TypeError: Cannot read properties of undefined in UserProfile.test.ts"
Expected output:
- Error analysis with root cause identification
- Missing mock or setup dependency detection
- Code fix for the failing test
- Regression prevention recommendation
- Verification command to confirm the fix

Core Concepts

ConceptDescription
Error ClassificationCategorizing failures as setup, rendering, async, mock, or assertion errors
Flaky Test DetectionIdentifying tests that fail intermittently due to timing or state leaks
Mock DiagnosisDetecting missing or incorrectly configured mocks for SvelteKit modules
Cleanup VerificationEnsuring component cleanup runs between tests to prevent state leaks
Version CompatibilityChecking testing library API changes across version upgrades
Test Fix Pipeline:

  Failing Test + Error Message
       |
  [Classify Error Type]
       |
  +----+----+----+----+
  |    |    |    |    |
 Setup Render Async Mock Assert
  |    |    |    |    |
  [Identify Root Cause]
       |
  [Generate Fix]
       |
  [Verify Fix Passes]
       |
  Stable Test

Configuration

ParameterDefaultDescription
Test RunnerAuto-detectVitest, Jest, or Playwright based on project config
Error SourceTest outputError message, file path, or test name to diagnose
Fix ScopeSingle testWhether to fix one test or scan for similar failures
VerificationRun after fixWhether to execute the test after applying the fix
Regression CheckSuggest guardWhether to recommend preventing similar future failures

Best Practices

  1. Include the full error message -- copy the complete error output including stack trace in your arguments for accurate root cause analysis
  2. Mention recent changes -- if tests broke after an upgrade or refactor, state what changed so the fixer can correlate the failure with the change
  3. Fix one test at a time -- resolve failures individually to understand each root cause rather than applying broad fixes that may mask underlying issues
  4. Check for state leaks -- if multiple tests fail, the first failure may contaminate subsequent tests through leaked state. Fix the first failure first
  5. Update test utilities -- after fixing, check if your test helper functions need the same fix applied to prevent similar failures in future tests

Common Issues

  1. Cannot find module errors -- SvelteKit alias imports ($lib/, $app/) need mock configuration in vitest.config.ts. Add the resolve.alias section matching your svelte.config.js
  2. Component renders but events do not fire -- use await fireEvent and await tick() to ensure Svelte reactive updates complete before asserting on event effects
  3. Tests pass individually but fail together -- state from one test leaks into the next. Add cleanup() calls in afterEach and verify mocks are reset between tests
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates