Test Runner Hook

Run tests related to changed files before committing

Category:hooks-configs
Type:hook
Difficulty:intermediate
testing
pre-commit
automation
intermediate

Description

Pre-commit hook that runs tests for changed files. Uses test framework's built-in related test detection to only run relevant tests, keeping commits fast while ensuring coverage.

Content

Resource Content
{
  "hooks": {
    "pre-commit": [
      {
        "name": "test-related",
        "command": "npx jest --bail --findRelatedTests",
        "match": "**/*.{js,jsx,ts,tsx}",
        "description": "Run tests related to changed files"
      }
    ]
  }
}