condition-based-waiting

Replace arbitrary timeouts with condition polling in test suites.

Updated Oct 28, 2025
One-click install
npx skills add https://github.com/AlabamaMike/copilot-agents --skill condition-based-waiting-alabamamike
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/AlabamaMike/copilot-agents/tree/main/.codex/superpowers/skills/condition-based-waiting
Command: npx skills add https://github.com/AlabamaMike/copilot-agents --skill condition-based-waiting-alabamamike

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Flaky tests often rely on arbitrary setTimeout or sleep calls, guessing at timing. This creates race conditions, leading to inconsistent pass/fail results, especially under load or in CI. This skill replaces these unreliable delays with condition-based polling, ensuring tests wait for actual state changes, making them robust and reliable.

Core Features & Use Cases

  • Reliable Async Testing: Replaces arbitrary timeouts with polling for specific conditions.
  • Flaky Test Elimination: Prevents race conditions and inconsistent test failures.
  • Generic Polling Function: Provides a reusable waitFor utility for various conditions (events, state, counts, file existence).
  • Use Case: If your UI tests are intermittently failing due to elements not being ready, use this skill to implement waitFor functions that poll for the element's visibility or state, making your tests stable.

Quick Start

Use the condition-based-waiting skill to refactor the 'user-login.test.ts' file, replacing setTimeout calls with condition-based waits for UI elements.

Frequently Asked Questions about condition-based-waiting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix flaky tests caused by timing issues and race conditions?

Replace arbitrary timeouts with condition-based polling to eliminate flaky tests. Instead of guessing delays with setTimeout, poll for actual state changes—like UI element visibility, event counts, or file availability—ensuring tests wait reliably for the condition to be met before proceeding.

What's the difference between using setTimeout and condition-based waiting in test suites?

Condition-based waiting polls for specific state changes rather than waiting a fixed duration. setTimeout creates race conditions under load; polling detects the actual moment a condition is satisfied, making tests consistent and eliminating intermittent failures.

Can I use condition-based polling for async workflows beyond UI testing?

Yes. Condition-based polling works for any async scenario: waiting for events, state transitions, array length changes, file availability, or complex predicates. A generic waitFor utility with customizable conditions and timeout handles diverse workflows and test contexts.

How do I implement waitFor helpers for events and state in my tests?

Use a generic polling loop with timeout that accepts predicates and error descriptions. Domain-specific helpers like waitForEvent, waitForEventCount, and waitForEventMatch wrap this core logic, letting you express common conditions declaratively without rebuilding polling logic.

What happens if a condition isn't met before the timeout in condition-based waiting?

The waitFor function returns after the timeout expires with a customizable error description. This prevents tests from hanging indefinitely while providing clear feedback about which condition failed and why, aiding diagnosis of timing or state issues.

Do I need a testing framework to use condition-based waiting?

No framework dependency is required. Condition-based waiting is a generic polling pattern applicable to any test suite or async workflow. Implement waitFor as a utility function and adapt it to your existing testing setup, whether Jest, Mocha, or custom runners.