Improve forgot-await detection by tracking async calls#216
Merged
Conversation
Member
gerardo-rodriguez
left a comment
There was a problem hiding this comment.
Reviewing this now. Gotta love the tests, they are always the most helpful to understand the intent of the changes. 🙂
gerardo-rodriguez
approved these changes
Aug 19, 2021
Member
gerardo-rodriguez
left a comment
There was a problem hiding this comment.
LGTM! I didn't see anything that obviously jumped out at me. Great work, @calebeby! 🎉
Merged
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.
When @spaceninja and I were working on some tests, we found a bug where the forgot-await detection didn't work:
This is because the current implementation usually only works if the call with
awaitmissing is the last call inside withBrowser, because it depends on Jest's feature of listening for unhandled promise rejections.This PR reimplements the forgot-await detection. Now it is centralized, and it works differently. It works by keeping track of all async calls that are started inside
withBrowser. WhenwithBrowserfinishes, it checks to see if any of the calls did not finish yet. If the developer remembered to useawaiton all the calls, then all the calls should have already finished, so nothing happens. If the developer forgotawaiton one or more of the calls,withBrowsercan see that, and throw the error.This does not handle the case where the call that is missing
awaitexecutes fast enough that it finishes before the rest of the things inwithBrowser.Review with whitespace changes turned off, otherwise the diff is a lot bigger than it needs to be