-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
Vitest 1.0.2 with happy-dom and msw + axios results in TypeError: #1180
Comments
Found this same issue. Been trying to have a workaround but no success so far. Got to downgrade vitest |
I've been checking this issue, and it seems MSW relies on browser API https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream completely. They may need to validate the response for the node version too. Something like this: this.logger.info("mocked response has body, streaming...");
const responseBody = response.body;
const readNextResponseBodyChunk = async (reader) => {
const { value, done } = await reader.read();
if (done) {
this.logger.info("response body stream done!");
finalizeResponse();
return;
}
if (value) {
this.logger.info("read response body chunk:", value);
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
this.trigger("progress", {
loaded: this.responseBuffer.byteLength,
total: totalResponseBodyLength
});
}
readNextResponseBodyChunk(reader);
};
const readStreamReadable = async () => {
for await (const value of responseBody) {
this.logger.info("read response body chunk:", value);
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
this.trigger("progress", {
loaded: this.responseBuffer.byteLength,
total: totalResponseBodyLength
});
}
this.logger.info("response body stream done!");
finalizeResponse();
}
// HERE! 👇
if (responseBody instanceof ReadableStream) {
const reader = response.body.getReader();
readNextResponseBodyChunk(reader);
} else if (responseBody instanceof Stream.Readable) {
readStreamReadable();
} This is the file But TBH I think I am trying to migrate the fetch to use |
…uest.body used by window.fetch(). The previous implementation used the Node.js Stream.Readable class, which is not fully spec compliant.
Describe the bug
Vitest 1.0.2 made a fix for happy-dom where it respects happy-dom's
Request
andResponse
. That unfortunately broke my tests: vitest-dev/vitest#4730.Here's the error message:
Maybe I'm using it wrong, but I'm not sure. I'd rather stick to happy-dom than use jsdom, but if this can't be fixed I guess I'll have to.
To Reproduce
Steps to reproduce the behavior:
vitest run
Expected behavior
I expect not to get a TypeError and the call to the url via msw to be executed.
Additional context
The project is using latest version for msw, axios, happy-dom and vitest.
The text was updated successfully, but these errors were encountered: