Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

statianzo
Copy link

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.

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.
Copy link
Owner

@jameslnewell jameslnewell left a 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';
Copy link
Owner

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?

Copy link
Author

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'});
Copy link
Owner

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?

Copy link
Author

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
Copy link
Owner

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? 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

@statianzo
Copy link
Author

Anything else needed for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants