-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
responseType=blob + string support #109
base: master
Are you sure you want to change the base?
Conversation
In order to support the `whatwg-fetch` polyfill which sets `responseType='blob'` for every request, create a new Blob when the responseType is `blob` and the body is a string. Added integration tests for `whatwg-fetch` Fixed proxy tests that are failing because the remote services response have changed. `reqres.in` and `httpbin.com` have changed their behavior. Fix those for a working test suite again. Typescript definitions needed some updates in order to pass. Upgraded Typescript to 4.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hi @statianzo!
Thanks for all the cleanup! Couple minor things to fix and I'm 👍
@@ -3,6 +3,7 @@ import MockProgressEvent from './MockProgressEvent'; | |||
import MockXMLHttpRequest from './MockXMLHttpRequest'; | |||
import {MockRequest} from '.'; | |||
import {MockError} from './MockError'; | |||
import {isExportDeclaration} from 'typescript'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import looks unused, was it intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably VSCode being overzealous about auto-imports. I'll get it removed.
@@ -162,7 +162,7 @@ export default class MockXMLHttpRequest extends MockXMLHttpRequestEventTarget | |||
|
|||
if (this.responseType === 'blob' && typeof body === 'string') { | |||
try { | |||
throw notImplementedError; | |||
return new Blob([body], {type: 'text/plain'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Blob
provided by whatwg-fetch
? Should we continue throwing the error when Blob
isn't defined? Not sure if you can think of a clever way to test each case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whatwg-fetch doesn't provide Blob. If Blob isn't defined, an error will get thrown and fall back to the return null
behavior of the catch
. Returning null is the same behavior as when throw notImplementedError
was there.
@@ -22,7 +22,8 @@ export default function( | |||
const xhr: XMLHttpRequest = new XHRMock.RealXMLHttpRequest(); | |||
|
|||
// TODO: reject with the correct type of error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably get rid of the TODO:
now? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
Anything else needed for this? |
In order to support the
whatwg-fetch
polyfill which setsresponseType='blob'
for every request, create a new Blobwhen the responseType is
blob
and the body is a string.Added integration tests for
whatwg-fetch
Fixed proxy tests that are failing because the remote services response
have changed.
reqres.in
andhttpbin.com
have changed their behavior.Fix those for a working test suite again.
Typescript definitions needed some updates in order to pass. Upgraded
Typescript to 4.0.