🐛

Flaky Test Debugger

Diagnose and fix intermittently failing tests

prompt template
Help me fix this flaky test:

**Test code:**
```
[PASTE_TEST_CODE]
```

**Behavior:** [BEHAVIOR — e.g., "passes locally, fails in CI 30% of the time"]
**Error when it fails:** [ERROR_MESSAGE]

Investigate these common causes of flaky tests:
1. **Timing issues** — race conditions, missing awaits, setTimeout reliance
2. **Test isolation** — shared state between tests, missing cleanup
3. **Non-deterministic data** — random values, Date.now(), UUIDs in assertions
4. **Environment differences** — CI vs local (timezone, locale, resources)
5. **External dependencies** — network calls, database state, file system
6. **Order dependency** — test relies on another test running first

For each applicable cause:
- Explain why it causes flakiness
- Provide the specific fix
- Show a before/after code comparison

Also suggest how to add a retry-proof test for the same behavior.

How to Use This Prompt

  1. 1Copy the prompt template above
  2. 2Paste into Claude, ChatGPT, or Cursor
  3. 3Replace [bracketed placeholders] with your specific project details
  4. 4Iterate on the AI output to refine and customize the results