M

Monitor Test Validator

Powerful hook for automatically, relevant, tests, after. Includes structured workflows, validation checks, and reusable patterns for testing.

HookClipticstestingv1.0.0MIT
0 views0 copies

Monitor Test Validator

Validates test suites and monitoring configurations after test execution, ensuring tests remain reliable and monitoring coverage stays comprehensive.

When to Use This Hook

Attach this hook when you need to:

  • Verify that test suites maintain minimum coverage thresholds after code changes
  • Validate that monitoring rules have corresponding test coverage
  • Detect flaky tests, missing assertions, and incomplete test setups automatically

Consider alternatives when:

  • Your CI system already runs comprehensive test validation and reporting
  • You prefer to validate tests only at commit or push time, not after every edit

Quick Start

Configuration

name: monitor-test-validator type: hook trigger: PostToolUse category: testing

Example Trigger

# Hook triggers after test files are edited claude> Edit src/__tests__/userService.test.ts # Validator checks the test file for quality issues

Example Output

Test Validator: Analyzing src/__tests__/userService.test.ts
  Assertions per test: avg 2.4 (min: 1) ........... PASS
  Empty test blocks: 0 ............................ PASS
  Skipped tests (.skip): 1 ........................ WARN
  Console.log in tests: 0 ......................... PASS
  Missing afterEach cleanup: detected .............. WARN
Validation complete: 2 warnings

Core Concepts

Validation Checks Overview

AspectDetails
Assertion CountEnsures each test has at least one assertion
Empty TestsDetects it() blocks with no body or only comments
Skipped TestsWarns on .skip or xit that may be forgotten
Cleanup VerificationChecks for missing afterEach/tearDown in tests with setup
Console StatementsFlags console.log left in test files from debugging

Validation Workflow

Test File Modified
       |
  Parse Test Blocks
       |
  ┌────┼────┬────┐
  |    |    |    |
Assert Empty Skip Cleanup
Count  Tests Check Check
  |    |    |    |
  └────┼────┴────┘
       |
  Score Quality
       |
  ┌────┴────┐
  |         |
 Pass    Warnings
  |         |
 Done    Report
         Issues

Configuration

ParameterTypeDefaultDescription
min_assertionsnumber1Minimum assertions required per test block
warn_on_skipbooleantrueWarn when .skip or xit tests are found
check_cleanupbooleantrueVerify cleanup hooks exist when setup hooks are present
max_test_linesnumber50Warn on excessively long individual test blocks
file_patternsstring[]["*.test.*","*.spec.*","test_*.*"]File patterns to validate

Best Practices

  1. Require Meaningful Assertions - A test with zero assertions always passes but tests nothing. Set min_assertions to at least 1 and encourage multiple assertions per test for thorough verification.

  2. Track Skipped Tests - Skipped tests tend to stay skipped forever. The warning reminds the team to either fix and re-enable them or delete them if they are no longer relevant.

  3. Enforce Cleanup Patterns - Tests with beforeEach setup but no afterEach cleanup can leak state between tests, causing intermittent failures. The validator catches this mismatch.

  4. Set Test Size Limits - Individual test blocks over 50 lines are hard to understand and maintain. The validator encourages breaking large tests into smaller, focused tests.

  5. Run on Test Files Only - The validator should only trigger when test files are edited, not production code. Use specific file patterns to avoid unnecessary validation runs.

Common Issues

  1. Custom Assertion Libraries - If your project uses a custom assertion library instead of expect(), the validator may not recognize assertions. Add custom assertion function names to the detection patterns.

  2. Dynamic Test Generation - Tests generated by loops or test.each may appear to have fewer assertions than they actually do. Add support for table-driven test patterns.

  3. False Positives on Utility Files - Test utility files (testHelpers.ts, fixtures.ts) may match test file patterns but do not contain test blocks. Add these to an exclusion list.

Community

Reviews

Write a review

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

Similar Templates