Add frame-driven waitFor utility#30
Open
greatestape wants to merge 1 commit into
Open
Conversation
Emit a 'frame' event from Stdout and Stderr whenever a new frame is written. Add a waitFor function, returned from render(), that listens for these events and re-checks the assertion on each frame. Unlike polling-based approaches (setInterval), this detects output changes instantly — at the moment stdout.write() is called — with no intermediate timer that can be delayed by event loop congestion. This addresses the CI flakiness pattern where polling timers get stretched under CPU load, causing tests to time out even though the component's output was already available. Closes vadimdemedes#22 Usage: const {lastFrame, waitFor} = render(<MyComponent />); await waitFor(() => { if (lastFrame() !== 'expected output') { throw new Error('not yet'); } });
4fe54e1 to
6a59c9b
Compare
Collaborator
|
A few things:
|
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.
This introduces a
waitForfunction similar to the one in the react testing library.I think it's convenient because it should guarantee that we don't miss frames, and it might make tests faster.
Arguably addresses #22
Usage:
One big caveat: as you can see in the change,
waitForisn't compatible with AVA tests. As I understand it this is because AVA stores test failures and reports them later, so the "keep trying until assertions pass or timeout" pattern doesn't work.