WP-5202 Switch mock-aware requests to real requests before finalizing them #290
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.
Problem
When MockTransports are installed with
fallThrough
enabled, we check to see if each request is mock-aware and if it would be handled by an expectation or a mock handler. If it wouldn't be, we switch it to a real request so that it doesn't get stuck (i.e. "fall-through").Currently, we finalize the request prior to making this check. It turns out that this can have an adverse effect on
MultipartRequests
due to their divergent browser and mock implementations. In the browser, theMultipartRequest
files map acceptsdart:html.File
anddart:html.Blob
instances, but those types cannot be imported in any platform other than the browser. As a result, attempting to finalize the mock-awareMultipartRequest
will fail if either aFile
orBlob
instance is attached because it does not recognize them.Solution
The solution is to switch to a real request (if applicable) prior to finalizing the request, which will avoid the issue altogether if the request isn't destined to be handled by a mock handler or expectation anyway.
Testing
Code Review
@Workiva/web-platform-pp