Improve forgot-await detection by tracking async calls #216
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
await
missing 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
. WhenwithBrowser
finishes, it checks to see if any of the calls did not finish yet. If the developer remembered to useawait
on all the calls, then all the calls should have already finished, so nothing happens. If the developer forgotawait
on one or more of the calls,withBrowser
can see that, and throw the error.This does not handle the case where the call that is missing
await
executes 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