Goal: Run unit tests for all changed files and their related test files.
-
Get changed files
- Run
git diff --name-only --diff-filter=ACMRfor all changes (staged + unstaged) - Filter for
.js,.jsx,.ts,.tsxfiles - Display list
- Run
-
Find test files
- Check if file is already a test file (contains
.test.) - For source files, find related tests:
{basename}.test.{ext} - Exclude snapshots (
.snap) - Collect unique test files
- Flag any
toMatchSnapshot()calls found — these are banned; note them for migration to explicit assertions ortoMatchInlineSnapshot()
- Check if file is already a test file (contains
-
Run tests
- Execute
yarn jestwith all found test files - Run without coverage
- Capture results
- Execute
-
Report & fix
- Show pass/fail summary
- If failures: Analyze → Fix issues → Re-run tests
- Continue until all pass
- Changed files identified
- Test files found
- Tests executed
- All tests pass
- Issues fixed and re-tested if needed
- Analyze failures → Isolate issues → Fix (implementation/mocks/tests) → Re-run → Repeat until pass
yarn jest <filename> # Run test file
yarn jest <filename> -t "test name" # Run specific test by name
yarn jest <filename> --no-coverage # Faster execution (skip coverage)
yarn jest <filename> --verbose # Detailed output for debuggingAll tests pass • No errors/timeouts • All changed files tested