-
Notifications
You must be signed in to change notification settings - Fork 179
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
fetch-mock Response.body is not always a stream in Node.js #609
Comments
fluggo
pushed a commit
to fluggo/fetch-mock
that referenced
this issue
May 15, 2021
The WhatWG fetch spec requires that Body.body (and therefore Response.body) is always a readable stream, but it doesn't always happen that way in Node. This seems to be because ResponseBuilder tries to fetch the stream module from fetchMock, but it looks in the wrong place. Fixes wheresrhys#609
fluggo
pushed a commit
to fluggo/fetch-mock
that referenced
this issue
May 15, 2021
The WhatWG fetch spec requires that Body.body (and therefore Response.body) is always a readable stream, but it doesn't always happen that way in Node. This seems to be because ResponseBuilder tries to fetch the stream module from fetchMock, but it looks in the wrong place. Fixes wheresrhys#609
fluggo
pushed a commit
to fluggo/fetch-mock
that referenced
this issue
May 15, 2021
The WhatWG fetch spec requires that Body.body (and therefore Response.body) is always a readable stream, but it doesn't always happen that way in Node. This seems to be because ResponseBuilder tries to fetch the stream module from fetchMock, but it looks in the wrong place. Fixes wheresrhys#609
Workaround: const stream = require('stream');
const _baseResponseBuilder = require('fetch-mock/cjs/lib/response-builder');
require.cache[require.resolve('fetch-mock/cjs/lib/response-builder')] = {
..._baseResponseBuilder,
exports: (options) => _baseResponseBuilder({ ...options, Stream: stream }),
};
const nodeFetch = require('node-fetch');
// and so forth |
in node-fetch@v3 the res.body is normalized into a node readable stream or null |
Should not be a problem any more in fetch-mock@10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WhatWG fetch API spec requires that Body.body is of type ReadableStream. node-fetch interprets the standard as requiring a Node.js Readable stream. fetch-mock returns a Buffer if anything other than a Readable is given to the Response object.
In Node:
...causes:
This appears to be a bug in the ResponseBuilder, I have a patch.
The text was updated successfully, but these errors were encountered: