Create waitFor and renderHook utility functions#27
Open
nukeop wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I ended up needing some utils to test my ink program properly, so I thought I might as well submit them here:
waitFor, andrenderHook. 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,
waitForwon'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'sexpectthough, and it works if you simply pass an error-throwing function then uset.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.