From c69b6a7d326f075b5c0bd4bb628a0feddea44ff8 Mon Sep 17 00:00:00 2001 From: Logan LaFollette Date: Wed, 23 Mar 2022 13:04:32 -0500 Subject: [PATCH 1/2] add blob support to passthrough requests --- src/create-passthrough.ts | 2 +- test/passthrough_test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/create-passthrough.ts b/src/create-passthrough.ts index 0ed7d9a..1a40c29 100644 --- a/src/create-passthrough.ts +++ b/src/create-passthrough.ts @@ -25,7 +25,7 @@ export function createPassthrough(fakeXHR, nativeXMLHttpRequest) { fakeXHR.password ); - if (fakeXHR.responseType === 'arraybuffer') { + if (fakeXHR.responseType === 'arraybuffer' || fakeXHR.responseType === 'blob') { lifecycleProps = ['readyState', 'response', 'status', 'statusText']; xhr.responseType = fakeXHR.responseType; } diff --git a/test/passthrough_test.js b/test/passthrough_test.js index b7d6277..5274bf9 100644 --- a/test/passthrough_test.js +++ b/test/passthrough_test.js @@ -112,6 +112,40 @@ describe('passthrough requests', function (config) { } ); + it( + 'asynchronous request with pass-through and ' + + 'blob as responseType', + function(assert) { + var pretender = this.pretender; + var done = assert.async(); + + 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(); + done(); + } + }; + } + pretender._nativeXMLHttpRequest = testXHR; + + pretender.get('/some/path', pretender.passthrough); + + var xhr = new window.XMLHttpRequest(); + xhr.open('GET', '/some/path'); + xhr.responseType = 'blob'; + xhr.send(); + } + ); + it('synchronous request has timeout=0, withCredentials and onprogress event', function (assert) { var pretender = this.pretender; var done = assert.async(); From ac5a0f55eb8ea8713ca1368a2cf3a832b224cff5 Mon Sep 17 00:00:00 2001 From: Logan LaFollette Date: Wed, 23 Mar 2022 13:12:11 -0500 Subject: [PATCH 2/2] remove QUnit from test --- test/passthrough_test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/passthrough_test.js b/test/passthrough_test.js index 5274bf9..eb33e8e 100644 --- a/test/passthrough_test.js +++ b/test/passthrough_test.js @@ -130,7 +130,6 @@ describe('passthrough requests', function (config) { apply: function(xhr, argument) { assert.equal(xhr.responseType, 'blob'); this.pretender.resolve(xhr); - QUnit.start(); done(); } };