Skip to content

Conversation

@nukeop
Copy link

@nukeop nukeop commented Jun 28, 2024

Hi, I ended up needing some utils to test my ink program properly, so I thought I might as well submit them here: waitFor, and renderHook. They're designed to resemble their React Testing Library counterparts.

I also added a test using them both, and added documentation to the readme.

Unfortunately, waitFor won't work with ava assertions, because as far as I can tell, once an assertion fails, that's it for the test. And using this function, you just keep waiting in a loop and check every now and then if your assertion passes. It works with jest's expect though, and it works if you simply pass an error-throwing function then use t.pass() at the end of the test, so that's what I did.

I hope this will help others using this library. Let me know if I can improve anything.

nyatinte added a commit to nyatinte/ccexp that referenced this pull request Jul 27, 2025
Implement waitFor utility based on ink-testing-library PR #27 to eliminate flaky E2E tests.
This addresses issue #59 by replacing fixed delay() calls with condition-based polling.

Changes:
- Add waitFor function to test-utils.ts with configurable timeout and interval
- Add waitForContent/waitForNotContent helpers to test-interaction-helpers.ts
- Replace all delay() calls in test files with appropriate waitFor patterns
- Improve test reliability for large file sets (100 files) with extended timeouts
- Add proper error handling for missing directories during test cleanup
- Adjust timing expectations in tests to handle CI environment variability

The waitFor implementation polls a condition function at regular intervals until it passes
or times out, providing more reliable async testing than fixed delays.

@see vadimdemedes/ink-testing-library#27
nyatinte added a commit to nyatinte/ccexp that referenced this pull request Jul 29, 2025
* refactor: replace delay() calls with waitFor pattern across tests

Implement waitFor utility based on ink-testing-library PR #27 to eliminate flaky E2E tests.
This addresses issue #59 by replacing fixed delay() calls with condition-based polling.

Changes:
- Add waitFor function to test-utils.ts with configurable timeout and interval
- Add waitForContent/waitForNotContent helpers to test-interaction-helpers.ts
- Replace all delay() calls in test files with appropriate waitFor patterns
- Improve test reliability for large file sets (100 files) with extended timeouts
- Add proper error handling for missing directories during test cleanup
- Adjust timing expectations in tests to handle CI environment variability

The waitFor implementation polls a condition function at regular intervals until it passes
or times out, providing more reliable async testing than fixed delays.

@see vadimdemedes/ink-testing-library#27

* test: clean up timing-dependent tests and E2E test suites

Remove flaky timing-dependent tests from waitFor implementation and
reorganize E2E tests to focus on actually testable user behaviors.

Changes:
- Remove timing-dependent waitFor tests that check internal implementation
- Keep only essential waitFor behavior tests (timeout, error handling)
- Remove 5 skipped E2E tests that cannot work due to test environment limitations
- Convert ESC key test to focus on search clearing (testable behavior)
- Clean up debug comments and workarounds from E2E tests
- Simplify main E2E test to focus on launch, search, and navigation

The menu interaction tests are skipped due to ink-testing-library not
supporting focus management. These features are tested at component level
instead (MenuActions.test.tsx).

* fix: correct waitFor usage and remove dead code per PR review

- Replace empty waitFor callbacks with proper condition checking in ThemedConfirmInput tests
- Use delay() instead of waitFor for negative testing in useFileNavigation test
- Remove unused typeKeys function and its test from test-keyboard-helpers

These changes address review feedback on PR #61 to ensure waitFor is used correctly
for polling conditions rather than as a simple delay replacement.

* refactor: improve test readability with constants and clearer comments

- Extract hardcoded timeout value (50ms) to WAIT_FOR_CALLBACK_TIMEOUT constant
- Add detailed comments explaining double waitForEffects() calls for React StrictMode
- Improve maintainability by centralizing timeout configuration

These changes address additional review feedback on PR #61 to enhance test clarity
and maintainability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant