|
| 1 | +# How to Improve Test Coverage to 90%+ |
| 2 | + |
| 3 | +## Current Status |
| 4 | +- **Estimated:** ~251/342 passing (73.4%) |
| 5 | +- **Target:** 308/342 passing (90%) |
| 6 | +- **Gap:** ~57 tests |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## ✅ Already Done |
| 11 | +1. ✅ Fixed 49 sketch tests (dynamic canvas) |
| 12 | +2. ✅ Fixed 9 ledger tests (timeouts) |
| 13 | +3. ✅ Fixed 3 accounting blazor tests (timeouts) |
| 14 | +4. ✅ Increased global timeouts (90s test, 30s expect, 60s navigation) |
| 15 | +5. ✅ Enabled auto-retries (2 attempts per test) |
| 16 | + |
| 17 | +**These changes alone should get us to ~75-80% pass rate!** |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Step-by-Step Action Plan |
| 22 | + |
| 23 | +### **STEP 1: Run Tests & Get Baseline** 🎯 |
| 24 | + |
| 25 | +```bash |
| 26 | +# Terminal 1: Start the application |
| 27 | +./scripts/start.sh |
| 28 | + |
| 29 | +# Terminal 2: Run full test suite |
| 30 | +npm run test:e2e 2>&1 | tee test-run-$(date +%Y%m%d-%H%M%S).txt |
| 31 | +``` |
| 32 | + |
| 33 | +**What to look for:** |
| 34 | +``` |
| 35 | +✔ XXX passed (Xm) |
| 36 | +✖ XX failed (Xm) |
| 37 | +⊘ XX skipped |
| 38 | +``` |
| 39 | + |
| 40 | +**Calculate:** |
| 41 | +- Pass rate = passed / (passed + failed) × 100% |
| 42 | +- Ignore skipped (those are intentional) |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +### **STEP 2: Analyze Failures** 🔍 |
| 47 | + |
| 48 | +Look at the output and categorize failures: |
| 49 | + |
| 50 | +#### A. **Still Timing Out?** |
| 51 | +Pattern: `Test timeout of 90000ms exceeded` |
| 52 | + |
| 53 | +**Fix:** Add longer waits in specific tests |
| 54 | +```typescript |
| 55 | +await expect(element).toBeVisible({ timeout: 60000 }); // 60s instead of 30s |
| 56 | +``` |
| 57 | + |
| 58 | +#### B. **Element Not Found?** |
| 59 | +Pattern: `waiting for selector "..." to be visible` |
| 60 | + |
| 61 | +**Fix:** Add explicit waits |
| 62 | +```typescript |
| 63 | +await page.locator('#element').waitFor({ state: 'visible', timeout: 30000 }); |
| 64 | +``` |
| 65 | + |
| 66 | +#### C. **Navigation Issues?** |
| 67 | +Pattern: `Cannot navigate to...` or `net::ERR_CONNECTION_REFUSED` |
| 68 | + |
| 69 | +**Fix:** Check if backend is running, add delays between navigations |
| 70 | +```typescript |
| 71 | +await page.waitForTimeout(1000); // Give page time to stabilize |
| 72 | +``` |
| 73 | + |
| 74 | +#### D. **Flaky Tests?** |
| 75 | +Pattern: Sometimes pass, sometimes fail |
| 76 | + |
| 77 | +**Fix:** Already enabled retries (2x), but can add specific waits |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +### **STEP 3: Quick Wins** ⚡ |
| 82 | + |
| 83 | +Based on patterns, apply these fixes: |
| 84 | + |
| 85 | +#### A. **Add Global Wait Helper** (5 min) |
| 86 | +```typescript |
| 87 | +// tests/helpers.ts |
| 88 | +export async function waitForPageReady(page: any) { |
| 89 | + await page.waitForLoadState('networkidle'); |
| 90 | + await page.waitForTimeout(500); // Give Blazor time to hydrate |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +#### B. **Add to Common Tests** (10 min) |
| 95 | +```typescript |
| 96 | +test.beforeEach(async ({ page }) => { |
| 97 | + await page.goto('/'); |
| 98 | + await waitForPageReady(page); |
| 99 | +}); |
| 100 | +``` |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +### **STEP 4: Target Specific Test Categories** 🎯 |
| 105 | + |
| 106 | +If certain categories are failing: |
| 107 | + |
| 108 | +#### **Accounting Tests Failing?** |
| 109 | +```bash |
| 110 | +# Run just accounting tests |
| 111 | +npm run test:e2e -- tests/accounting-*.spec.ts --headed |
| 112 | +``` |
| 113 | + |
| 114 | +Watch what's happening - are pages loading slowly? Add waits. |
| 115 | + |
| 116 | +#### **Onboarding Tests Failing?** |
| 117 | +These might be the Blazor @onclick issues (already skipped) |
| 118 | + |
| 119 | +#### **Workflow Tests Failing?** |
| 120 | +These do multi-step operations - might need longer timeouts between steps |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +### **STEP 5: Monitor & Iterate** 🔄 |
| 125 | + |
| 126 | +```bash |
| 127 | +# Run tests multiple times to check for flakiness |
| 128 | +for i in {1..3}; do |
| 129 | + echo "Run $i" |
| 130 | + npm run test:e2e 2>&1 | grep "passed\|failed" |
| 131 | +done |
| 132 | +``` |
| 133 | + |
| 134 | +If pass rate varies significantly, tests are flaky → add retries or waits |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## Quick Reference Commands |
| 139 | + |
| 140 | +### Run All Tests |
| 141 | +```bash |
| 142 | +npm run test:e2e |
| 143 | +``` |
| 144 | + |
| 145 | +### Run Specific Test File |
| 146 | +```bash |
| 147 | +npm run test:e2e -- tests/ui.sketches.spec.ts |
| 148 | +``` |
| 149 | + |
| 150 | +### Run in Headed Mode (See Browser) |
| 151 | +```bash |
| 152 | +npm run test:e2e:headed -- tests/ui.sketches.spec.ts |
| 153 | +``` |
| 154 | + |
| 155 | +### Run Tests Multiple Times |
| 156 | +```bash |
| 157 | +npm run test:e2e -- tests/ui.sketches.spec.ts --repeat-each=3 |
| 158 | +``` |
| 159 | + |
| 160 | +### Generate HTML Report |
| 161 | +```bash |
| 162 | +npx playwright show-report |
| 163 | +``` |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Expected Results After Config Changes |
| 168 | + |
| 169 | +### Before Config Change: |
| 170 | +- ~251/342 passing (73.4%) |
| 171 | + |
| 172 | +### After Config Change (Expected): |
| 173 | +- ~265-275/342 passing (77-80%) |
| 174 | +- +10-20 tests fixed by longer timeouts |
| 175 | + |
| 176 | +### To Reach 90% (308 tests): |
| 177 | +- Need ~35-45 more tests to pass |
| 178 | +- Focus on test-specific fixes |
| 179 | +- Add explicit waits where needed |
| 180 | + |
| 181 | +--- |
| 182 | + |
| 183 | +## Common Fixes |
| 184 | + |
| 185 | +### Pattern 1: Timeout on Specific Element |
| 186 | +```typescript |
| 187 | +// Before |
| 188 | +await expect(page.locator('.my-element')).toBeVisible(); |
| 189 | + |
| 190 | +// After |
| 191 | +await expect(page.locator('.my-element')).toBeVisible({ timeout: 60000 }); |
| 192 | +``` |
| 193 | + |
| 194 | +### Pattern 2: Wait for Network |
| 195 | +```typescript |
| 196 | +await page.waitForLoadState('networkidle'); |
| 197 | +await page.waitForTimeout(1000); // Extra buffer |
| 198 | +``` |
| 199 | + |
| 200 | +### Pattern 3: Wait for Specific State |
| 201 | +```typescript |
| 202 | +await page.waitForSelector('.data-loaded', { timeout: 30000 }); |
| 203 | +``` |
| 204 | + |
| 205 | +### Pattern 4: Retry on Failure |
| 206 | +```typescript |
| 207 | +// Already enabled globally with retries: 2 |
| 208 | +// But can add test-specific: |
| 209 | +test.describe.configure({ retries: 3 }); |
| 210 | +``` |
| 211 | + |
| 212 | +--- |
| 213 | + |
| 214 | +## Monitoring Progress |
| 215 | + |
| 216 | +### Create a baseline file: |
| 217 | +```bash |
| 218 | +npm run test:e2e 2>&1 | grep "passed\|failed\|skipped" > baseline.txt |
| 219 | +``` |
| 220 | + |
| 221 | +### After each fix: |
| 222 | +```bash |
| 223 | +npm run test:e2e 2>&1 | grep "passed\|failed\|skipped" > after-fix.txt |
| 224 | +diff baseline.txt after-fix.txt |
| 225 | +``` |
| 226 | + |
| 227 | +--- |
| 228 | + |
| 229 | +## When You Hit 90% |
| 230 | + |
| 231 | +Celebrate! Then: |
| 232 | + |
| 233 | +1. **Document** any remaining failures (acceptable?) |
| 234 | +2. **Set up CI/CD** to maintain coverage |
| 235 | +3. **Add test coverage badge** to README |
| 236 | +4. **Monitor** for regression |
| 237 | + |
| 238 | +--- |
| 239 | + |
| 240 | +## Need Help? |
| 241 | + |
| 242 | +If specific tests keep failing: |
| 243 | + |
| 244 | +1. Run in headed mode to see what's happening |
| 245 | +2. Add `await page.pause()` to debug |
| 246 | +3. Check browser console for errors |
| 247 | +4. Increase timeout for that specific test |
| 248 | +5. Check if backend is responding (network tab) |
| 249 | + |
| 250 | +--- |
| 251 | + |
| 252 | +## Summary |
| 253 | + |
| 254 | +✅ **Already done:** |
| 255 | +- Global timeout increases |
| 256 | +- 61 tests fixed manually |
| 257 | +- Auto-retry enabled |
| 258 | + |
| 259 | +🎯 **Next steps:** |
| 260 | +1. Run tests → get actual numbers |
| 261 | +2. Analyze failures → find patterns |
| 262 | +3. Apply fixes → test-by-test if needed |
| 263 | +4. Verify → aim for 90%+ |
| 264 | + |
| 265 | +**Estimated time to 90%:** 2-3 hours if failures are timeout-related, longer if logic issues. |
| 266 | + |
| 267 | +Good luck! 🚀 |
0 commit comments