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

Add blob support to passthrough #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pretender.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ function interceptor(pretender) {

var xhr = fakeXHR._passthroughRequest = new pretender._nativeXMLHttpRequest();

if (fakeXHR.responseType === 'arraybuffer') {
if (fakeXHR.responseType === 'arraybuffer' || fakeXHR.responseType === 'blob') {
lifecycleProps = ['readyState', 'response', 'status', 'statusText'];
xhr.responseType = fakeXHR.responseType;
}

// Use onload if the browser supports it
if ('onload' in xhr) {
if ('onload' in xhr && fakeXHR.responseType !== 'blob') {

Choose a reason for hiding this comment

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

Curious, why wouldn't we want the onload event to be called for responseType === 'blob'?

Copy link
Author

Choose a reason for hiding this comment

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

We were seeing odd behavior in some of our tests where the message was delivered twice. However, this could have been a symptom of something else as I was never able to determine the root cause.

Copy link
Contributor

@stefanpenner stefanpenner Jul 16, 2017

Choose a reason for hiding this comment

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

i would think its an unrelated to system, if so can we remove this? Then we can move forward with merging + releasing this.

evts.push('load');
}

// add progress event for async calls
if (fakeXHR.async && fakeXHR.responseType !== 'arraybuffer') {
if (fakeXHR.async && fakeXHR.responseType !== 'arraybuffer' && fakeXHR.responseType !== 'blob') {
Copy link
Contributor

Choose a reason for hiding this comment

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

why no progress for blob?

evts.push('progress');
}

Expand Down
28 changes: 28 additions & 0 deletions test/passthrough_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ describe('passthrough requests', function(config) {
xhr.send();
});

asyncTest('asynchronous request with pass-through and ' +
'blob as responseType', function(assert) {
var pretender = this.pretender;
function testXHR() {
this.pretender = pretender;
this.open = function() {};
this.setRequestHeader = function() {};
this.upload = {};
this.responseType = '';
this.send = {
pretender: pretender,
apply: function(xhr, argument) {
assert.equal(xhr.responseType, 'blob');
this.pretender.resolve(xhr);
QUnit.start();
}
};
}
pretender._nativeXMLHttpRequest = testXHR;

pretender.get('/some/path', pretender.passthrough);

var xhr = new window.XMLHttpRequest();
xhr.open('GET', '/some/path');
xhr.responseType = 'blob';
xhr.send();
});

asyncTest('synchronous request does not have timeout, withCredentials and onprogress event', function(assert) {
var pretender = this.pretender;
function testXHR() {
Expand Down