Automated workflow for running tests and fixing failures systematically. Use when implementing the mandatory test workflow or fixing code quality issues...
Systematic workflow for running tests and fixing failures. This is the implementation of the mandatory code quality workflow.
Use this workflow when:
cd embedded-components; yarn formatcd embedded-components; yarn testAuto-fix formatting issues first:
cd embedded-components
yarn format
This automatically fixes:
Execute all tests in the project:
cd embedded-components
yarn test
This runs:
Categorize failures by type:
TypeScript Errors:
Formatting Errors:
Linting Errors:
Test Failures:
Fix in this order:
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
Re-run complete test suite:
cd embedded-components
yarn test
Repeat steps 3-5 until all tests pass.
// ❌ Error: Parameter 'value' implicitly has an 'any' type
const formatValue = (value) => value.toString();
// ✅ Fix: Add type annotation
const formatValue = (value: number): string => value.toString();
// ❌ Error: Type 'string' is not assignable to type 'number'
const age: number = "25";
// ✅ Fix: Use correct type or convert
const age: number = 25;
// or
const age: number = parseInt("25", 10);
// ❌ Error: Replace `"` with `'`
const name = "John";
// ✅ Fix: Auto-fixed by yarn format
const name = 'John';
// ❌ Error: 'unused' is assigned but never used
const unused = "value";
const used = "other";
// ✅ Fix: Remove or use it
const used = "other";
// or
const unused = "value";
console.log(unused);
// ❌ Error: React Hook useEffect has a missing dependency: 'userId'
useEffect(() => {
fetchUser(userId);
}, []);
// ✅ Fix: Add dependency
useEffect(() => {
fetchUser(userId);
}, [userId]);
// ❌ Failure: expected 5 to equal 4
test("adds numbers", () => {
expect(add(2, 2)).toBe(5);
});
// ✅ Fix: Correct assertion or implementation
test("adds numbers", () => {
expect(add(2, 2)).toBe(4);
});
// ❌ Error: Timeout - Async callback was not invoked within timeout
test("loads data", () => {
renderComponent();
expect(screen.getByText("Data")).toBeInTheDocument();
});
// ✅ Fix: Use waitFor for async operations
test("loads data", async () => {
renderComponent();
await waitFor(() => {
expect(screen.getByText("Data")).toBeInTheDocument();
});
});
// ❌ Error: Mock from previous test affecting current test
test("test 1", () => {
server.use(http.get("/api/data", () => HttpResponse.json({ id: 1 })));
// test assertions
});
test("test 2", () => {
// Still using mock from test 1
// test assertions
});
// ✅ Fix: Reset handlers in renderComponent or beforeEach
beforeEach(() => {
server.resetHandlers();
});
# 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
# Watch mode for rapid iteration
cd embedded-components
yarn test:watch ComponentName.test.tsx
# More detailed output
cd embedded-components
yarn test --verbose
# Generate coverage report
cd embedded-components
yarn test:coverage
# View report
start coverage/index.html
Create a PowerShell script to automate fixes:
# fix-issues.ps1
cd embedded-components
Write-Host "Formatting code..." -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
}
# 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
# 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
Note: Always run yarn format first to ensure code is properly formatted before running tests.
cd embedded-components
yarn cache clean
Remove-Item -Recurse -Force node_modules
yarn install
# Find process using port
netstat -ano | findstr :3000
# Kill process
taskkill /PID <PID> /F
$env:NODE_OPTIONS="--max-old-space-size=4096"
cd embedded-components
yarn test
For detailed instructions, examples, and troubleshooting:
AGENTS.md - Complete workflow documentation.github/skills/code-quality-workflow/ for quality gates.github/skills/component-testing/ for testing patternsAGENTS.md for complete workflow documentation