condition-based-waiting

Replace arbitrary timeouts with condition-based polling in tests and async workflows.

2|Updated Oct 25, 2025
One-click install
npx skills add https://github.com/robertpelloni/workspace --skill condition-based-waiting-robertpelloni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/robertpelloni/workspace/tree/main/AI_COORDINATION/skills/superpowers-skills-main/skills/testing/condition-based-waiting
Command: npx skills add https://github.com/robertpelloni/workspace --skill condition-based-waiting-robertpelloni

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill addresses the flakiness and unreliability of tests involving asynchronous operations by guiding the implementation of intelligent waiting strategies. Instead of fixed delays, it waits for specific conditions to be met, making tests more stable and efficient.

Core Features & Use Cases

  • Dynamic Waiting: Wait for an element to appear, an API call to complete, or a state change.
  • Timeout Management: Implement graceful timeouts to prevent infinite waits.
  • Use Case: In an end-to-end test, instead of sleep(5), use this skill to implement a wait that polls until a specific UI element is visible or a backend process confirms completion, making the test resilient to varying network conditions.

Quick Start

Implement condition-based waiting in the attached 'e2e_test.js' to wait for the 'data-loaded' element.

Frequently Asked Questions about condition-based-waiting

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

FAQPage Schema
How do I eliminate flaky tests caused by timing issues in async workflows?

Replace fixed timeouts with condition-based waiting that polls for actual state changes. This approach waits for specific conditions—like element visibility or API completion—rather than sleeping arbitrary durations, making tests stable across varying network and system speeds.

What's the difference between sleep delays and condition-based waiting in tests?

Sleep delays pause for a fixed duration regardless of whether the target condition is met, causing flakiness in slow environments. Condition-based waiting continuously checks for the actual condition and returns immediately when satisfied, eliminating unnecessary delays and race conditions.

How do I wait for UI elements or backend processes to complete in end-to-end tests?

Implement polling with helper waiters that check for specific conditions—element visibility, API responses, state changes, or event counts—within a defined timeout. The Skill provides waitFor, waitForEvent, waitForEventCount, and waitForEventMatch helpers to handle these patterns.

Can I use condition-based waiting to handle race conditions in multi-threaded or event-driven tasks?

Yes. Condition-based waiting applies to any async workflow with timing dependencies or race conditions. It works for event-driven state changes, CI pipelines, and multi-threaded tasks by waiting for observable conditions to stabilize rather than guessing durations.

What happens if a condition is never met—does the wait run forever?

No. Condition-based waiting includes timeout management that throws a defined timeout error if the condition isn't met within the specified duration, preventing infinite waits and providing clear failure signals in tests.

Related Skills