Update packages

This commit is contained in:
Timothy Gu 2016-11-23 11:30:01 -08:00
parent 31bc2835dd
commit a355664e64
3 changed files with 29 additions and 37 deletions

3
.nycrc
View File

@ -1,7 +1,4 @@
{
"include": [
"src/*.js"
],
"require": [
"babel-register"
],

View File

@ -31,26 +31,26 @@
},
"homepage": "https://github.com/bitinn/node-fetch",
"devDependencies": {
"babel-plugin-istanbul": "^2.0.1",
"babel-plugin-istanbul": "^3.0.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.16.0",
"babel-register": "^6.16.3",
"bluebird": "^3.3.4",
"chai": "^3.5.0",
"chai-as-promised": "^5.2.0",
"chai-as-promised": "^6.0.0",
"chai-iterator": "^1.1.1",
"codecov": "^1.0.1",
"cross-env": "2.0.1",
"cross-env": "^3.1.3",
"form-data": ">=1.0.0",
"mocha": "^2.1.0",
"nyc": "^8.3.0",
"mocha": "^3.1.2",
"nyc": "^10.0.0",
"parted": "^0.1.1",
"promise": "^7.1.1",
"resumer": "0.0.0",
"rollup": "^0.36.4",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-node-resolve": "^2.0.0",
"whatwg-url": "^3.0.0"
"whatwg-url": "^4.0.0"
},
"dependencies": {
"babel-runtime": "^6.11.6",

View File

@ -1039,53 +1039,36 @@ describe(`node-fetch with FOLLOW_SPEC = ${defaultFollowSpec}`, () => {
});
});
it('should allow piping response body as stream', function(done) {
it('should allow piping response body as stream', function() {
url = `${base}hello`;
fetch(url).then(res => {
return fetch(url).then(res => {
expect(res.body).to.be.an.instanceof(stream.Transform);
res.body.on('data', chunk => {
return streamToPromise(res.body, chunk => {
if (chunk === null) {
return;
}
expect(chunk.toString()).to.equal('world');
});
res.body.on('end', () => {
done();
});
});
});
it('should allow cloning a response, and use both as stream', function(done) {
it('should allow cloning a response, and use both as stream', function() {
url = `${base}hello`;
return fetch(url).then(res => {
let counter = 0;
const r1 = res.clone();
expect(res.body).to.be.an.instanceof(stream.Transform);
expect(r1.body).to.be.an.instanceof(stream.Transform);
res.body.on('data', chunk => {
const dataHandler = chunk => {
if (chunk === null) {
return;
}
expect(chunk.toString()).to.equal('world');
});
res.body.on('end', () => {
counter++;
if (counter == 2) {
done();
}
});
r1.body.on('data', chunk => {
if (chunk === null) {
return;
}
expect(chunk.toString()).to.equal('world');
});
r1.body.on('end', () => {
counter++;
if (counter == 2) {
done();
}
});
};
return Promise.all([
streamToPromise(res.body, dataHandler),
streamToPromise(r1.body, dataHandler)
]);
});
});
@ -1698,3 +1681,15 @@ describe(`node-fetch with FOLLOW_SPEC = ${defaultFollowSpec}`, () => {
});
});
function streamToPromise(stream, dataHandler) {
return new Promise((resolve, reject) => {
stream.on('data', (...args) => {
Promise.resolve()
.then(() => dataHandler(...args))
.catch(reject);
});
stream.on('end', resolve);
stream.on('error', reject);
});
}