Flaky Test & Async Timing Race Condition Debugger
Fix nondeterministic test failures, unhandled async promises, and race conditions in Playwright, Jest, or Vitest.
Interactive Prompt Playground
{{TEST_CODE}}{{FAILURE_LOG}}{{FRAMEWORK}}You are a Test Automation Lead specializing in resolving flaky CI test suites.
Flaky Test Code:
```typescript
it('should display success banner after submitting form', async () => {
render(<RegistrationForm />);
fireEvent.change(screen.getByLabelText(/email/i), { target: { value: '[email protected]' } });
fireEvent.click(screen.getByRole('button', { name: /register/i }));
// Flaky sleep wait:
await new Promise(r => setTimeout(r, 500));
expect(screen.getByText(/account created/i)).toBeInTheDocument();
});
```
Test Failure Log & Error:
```
TestingLibraryElementError: Unable to find an element with the text: /account created/i.
Fails 1 out of every 5 CI runs on GitHub Actions runners under high CPU load.
```
Test Framework & Environment: Vitest + React Testing Library (React 19)
Diagnose and resolve the nondeterminism:
1. **Flakiness Vector Identification**:
- Find race conditions, arbitrary `sleep/timeout` calls, shared state between tests, unawaited promises, or timezone/locale assumptions.
2. **Deterministic Synchronization Pattern**:
- Replace arbitrary timers with explicit condition polling (e.g. `waitFor`, `expect.poll`, or auto-retrying assertions).
3. **Test Isolation & Mock Teardown**:
- Ensure database resets, mock restores, and fake timers are cleanly reset in `beforeEach` / `afterEach`.
4. **Refactored Deterministic Test**:
- Provide the rock-solid, 100% reliable test implementation.How to Use This Prompt
- Paste your flaky test code and CI error output.
- Specify your test runner (Playwright, Jest, Vitest, Cypress).
- Get a deterministic, fast, zero-flakiness refactor.
Engineering Tips & Best Practices
- Never use hardcoded sleep in tests; use waitFor or findBy which poll the DOM with a timeout.
What This Prompt Inspects
Key failure modes, design principles, and quality standards evaluated during execution.
No Arbitrary Sleep
Eliminates setTimeout/sleep in favor of event-driven auto-retrying assertions.
State Isolation
Guarantees tests do not leak database records or DOM state across runs.
Network Synchronization
Waits explicitly for network responses before asserting UI changes.
SprintKit Workflow Integrations
Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.
Related Prompts
Explore related developer prompts in this workflow domain.
Unit Test Suite Generator with Edge Cases
Generate comprehensive, mutation-tested unit tests with AAA pattern, boundary cases, and proper mock boundaries.
GitHub Actions CI/CD Pipeline & Caching Optimizer
Speed up slow GitHub Actions workflows with dependency caching, matrix parallelization, and security secrets.
Next.js App Router & React Server Components Review
Review Next.js 14/15 App Router code for RSC boundaries, data fetching waterfalls, caching, and hydration safety.