-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
FormData with file is not setting boundary when running in jsdom env #5672
Comments
|
Ok, thanks. |
Technically overwriting globals back to nodejs is possible, but I feel the purpose of jsdom environment is questionable at this point. // this works because jsdom doesn't provide `Request` and it's coming from NodeJs/undici
async function restoreNodeGlobals() {
const nodeGlobals: any = {};
{
const request = new Request("https://test.local", {
method: "POST",
headers: {
"content-type": "application/x-www-form-urlencoded",
},
});
const formData = await request.formData();
nodeGlobals.FormData = formData.constructor;
}
{
const request = new Request("https://test.local", {
method: "POST",
});
const blob = await request.blob();
nodeGlobals.Blob = blob.constructor;
}
Object.assign(globalThis, nodeGlobals);
} FYI, the similar issue has been discussed in #4043 |
Describe the bug
Hi,
when trying to send a FormData request that includes a file on a test that is using
jsdom
,seems like the request is not adding the content-length properly (as happens automatically on the browser/Node.js)
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-lqr5xr?file=test%2Fbasic.test.ts,vite.config.ts,package.json,package-lock.json&initialPath=__vitest__/
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: