From 6a01265ff68b3d57b2baef1325be188239ad7d77 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 6 Sep 2016 10:34:08 -0400 Subject: [PATCH 1/2] superagent: req.responseType, res.xhr --- superagent/superagent-tests.ts | 12 +++++++++++- superagent/superagent.d.ts | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/superagent/superagent-tests.ts b/superagent/superagent-tests.ts index 237cbdeda1c2b8..a91914eaae0e40 100644 --- a/superagent/superagent-tests.ts +++ b/superagent/superagent-tests.ts @@ -5,6 +5,7 @@ import * as request from 'superagent'; import * as fs from 'fs'; +import * as assert from 'assert'; // Examples taken from https://github.com/visionmedia/superagent/blob/gh-pages/docs/index.md // and https://github.com/visionmedia/superagent/blob/master/Readme.md @@ -302,4 +303,13 @@ request request .get('/search') .then((response) => {}) - .catch((error) => {}); \ No newline at end of file + .catch((error) => {}); + +// Requesting binary data. +// adapted from: https://github.com/visionmedia/superagent/blob/v2.0.0/test/client/request.js#L110 +request + .get('/blob') + .responseType('blob') + .end(function(err, res){ + assert.deepEqual(res.xhr.response instanceof Blob, true); + }); diff --git a/superagent/superagent.d.ts b/superagent/superagent.d.ts index 1d89adeb6ba9c8..c41847775c4bfa 100644 --- a/superagent/superagent.d.ts +++ b/superagent/superagent.d.ts @@ -77,6 +77,7 @@ declare module "superagent" { notAcceptable: boolean; notFound: boolean; forbidden: boolean; + xhr: XMLHttpRequest; get(header: string): string; } @@ -96,6 +97,7 @@ declare module "superagent" { pipe(stream: NodeJS.WritableStream, options?: Object): stream.Writable; query(val: Object): this; redirects(n: number): this; + responseType(type: string): this; send(data: string): this; send(data: Object): this; send(): this; From f105740dced564894ee5a12c36fce6a82af9a849 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 12 Sep 2016 08:45:01 -0400 Subject: [PATCH 2/2] superagent: updates for feedback on #11055 --- superagent/superagent-tests.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/superagent/superagent-tests.ts b/superagent/superagent-tests.ts index a91914eaae0e40..283244ac85e641 100644 --- a/superagent/superagent-tests.ts +++ b/superagent/superagent-tests.ts @@ -310,6 +310,7 @@ request request .get('/blob') .responseType('blob') - .end(function(err, res){ - assert.deepEqual(res.xhr.response instanceof Blob, true); + .end(function (err, res) { + assert(res.xhr instanceof XMLHttpRequest) + assert(res.xhr.response instanceof Blob); });