| name | test-and-fix-workflow |
| description | Automated workflow for running tests and fixing failures systematically. Use when implementing the mandatory test workflow or fixing code quality issues. Keywords - testing, debugging, workflow, failures, systematic fixes. |
| compatibility | Requires yarn, embedded-components workspace |
| metadata | {"version":"2.0.0","author":"jpmorgan-payments","lastUpdated":"2025-12-24","priority":"high"} |
Test and Fix Workflow
Overview
Systematic workflow for running tests and fixing failures. This is the implementation of the mandatory code quality workflow.
Workflow Steps
1. Run Test Suite
Execute all tests in the project:
cd embedded-components
yarn test
This runs:
- Type checking (TypeScript)
- Format checking (Prettier)
- Linting (ESLint)
- Unit tests (Vitest)
2. Analyze Failures
Categorize failures by type:
TypeScript Errors:
- Type mismatches
- Missing type definitions
- Import errors
- Interface violations
Formatting Errors:
- Indentation issues
- Quote style violations
- Line break problems
- Trailing comma issues
Linting Errors:
- Unused variables
- Missing dependencies
- Code style violations
- Best practice violations
Test Failures:
- Assertion failures
- Mock issues
- Timeout errors
- Component rendering failures
3. Prioritize Fixes
Fix in this order:
- TypeScript errors - Must be fixed first (blocking)
- Formatting errors - Auto-fixable
- Linting errors - Most auto-fixable
- Test failures - Requires analysis
4. Fix Issues Systematically
For TypeScript Errors:
# Check types
cd embedded-components
yarn typecheck
# Fix type issues in code
# Then re-check
yarn typecheck
For Formatting Errors:
# Auto-fix all formatting
cd embedded-components
yarn format
# Verify
yarn format:check
For Linting Errors:
# Auto-fix linting
cd embedded-components
yarn lint:fix
# Verify
yarn lint
For Test Failures:
# Run specific test file
cd embedded-components
yarn test ComponentName.test.tsx
# Run in watch mode for debugging
yarn test:watch ComponentName.test.tsx
# Fix test or implementation
# Re-run tests
yarn test
5. Verify All Fixes
Re-run complete test suite:
cd embedded-components
yarn test
6. Iterate Until Green
Repeat steps 3-5 until all tests pass.
Common Failure Patterns
TypeScript: Missing Type
const formatValue = (value) => value.toString();
const formatValue = (value: number): string => value.toString();
TypeScript: Type Mismatch
const age: number = "25";
const age: number = 25;
const age: number = parseInt("25", 10);
Formatting: Inconsistent Quotes
const name = "John";
const name = 'John';
Linting: Unused Variable
const unused = "value";
const used = "other";
const used = "other";
const unused = "value";
console.log(unused);
Linting: Missing useEffect Dependencies
useEffect(() => {
fetchUser(userId);
}, []);
useEffect(() => {
fetchUser(userId);
}, [userId]);
Test: Assertion Failure
test("adds numbers", () => {
expect(add(2, 2)).toBe(5);
});
test("adds numbers", () => {
expect(add(2, 2)).toBe(4);
});
Test: Async Timeout
test("loads data", () => {
renderComponent();
expect(screen.getByText("Data")).toBeInTheDocument();
});
test("loads data", async () => {
renderComponent();
await waitFor(() => {
expect(screen.getByText("Data")).toBeInTheDocument();
});
});
Test: Mock Not Reset
test("test 1", () => {
server.use(http.get("/api/data", () => HttpResponse.json({ id: 1 })));
});
test("test 2", () => {
});
beforeEach(() => {
server.resetHandlers();
});
Debugging Strategies
Isolate the Issue
# Run single test file
cd embedded-components
yarn test ComponentName.test.tsx
# Run single test
yarn test ComponentName.test.tsx -t "specific test name"
# Run type check only
yarn typecheck
# Run linter only
yarn lint
Use Watch Mode
# Watch mode for rapid iteration
cd embedded-components
yarn test:watch ComponentName.test.tsx
Verbose Output
# More detailed output
cd embedded-components
yarn test --verbose
Coverage Report
# Generate coverage report
cd embedded-components
yarn test:coverage
# View report
start coverage/index.html
Quick Fix Script
Create a PowerShell script to automate fixes:
# fix-issues.ps1
cd embedded-components
Write-Host "Fixing formatting..." -ForegroundColor Yellow
yarn format
Write-Host "Fixing linting..." -ForegroundColor Yellow
yarn lint:fix
Write-Host "Running tests..." -ForegroundColor Yellow
yarn test
if ($LASTEXITCODE -eq 0) {
Write-Host "All tests passed!" -ForegroundColor Green
} else {
Write-Host "Some tests failed. Review output above." -ForegroundColor Red
}
Best Practices
- Fix one issue at a time - Don't batch unrelated fixes
- Verify each fix - Run tests after each fix
- Commit working code - Commit after all tests pass
- Don't skip failures - Address all issues before committing
- Use auto-fix first - Let tools fix what they can
- Document complex fixes - Add comments for non-obvious fixes
- Update tests if needed - Ensure tests reflect requirements
Time-Saving Tips
# Chain auto-fixes
cd embedded-components
yarn format; yarn lint:fix
# Check specific file quickly
yarn typecheck src/components/ComponentName.tsx
# Run related tests only
yarn test ComponentName
# Keep tests running in watch mode
yarn test:watch
Integration with Git
# Complete workflow before commit
cd embedded-components
yarn format; yarn lint:fix; yarn test
# If all pass, commit
cd ..
git add embedded-components
git commit -m "fix: resolve test failures"
git push
Troubleshooting
Cache Issues
cd embedded-components
yarn cache clean
Remove-Item -Recurse -Force node_modules
yarn install
Port Conflicts
# Find process using port
netstat -ano | findstr :3000
# Kill process
taskkill /PID <PID> /F
Memory Issues
$env:NODE_OPTIONS="--max-old-space-size=4096"
cd embedded-components
yarn test
References
- See
.github/copilot/skills/code-quality-workflow/ for quality gates
- See
.github/copilot/skills/component-testing/ for testing patterns
- See
.github/copilot/prompts/run-tests-and-fix.md for detailed prompt