vitest-dev / vitest-dev/vitest

form data file name not being preserved through a request in jsdom

Open
#9,260 1 comment 0 reactions 1 assignee View on GitHub

@sheremet-va is already working on this.

Since Jan 5, 2026.

pending triage
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

When a file name is given to a File object and attached to a Request through a FormData object, the file name given is lost.

I've tracked the issue down to this line of code

https://github.com/vitest-dev/vitest/blob/a8ad1297070427bc83b886a9f1ac8dcdc484c616/packages/vitest/src/integrations/env/jsdom.ts#L303

where it doesn't copy over the file name if there is one. It is likely that this line was intended to only execute this code for Blobs, but File is a subclass of Blob.

https://github.com/vitest-dev/vitest/blob/a8ad1297070427bc83b886a9f1ac8dcdc484c616/packages/vitest/src/integrations/env/jsdom.ts#L292

Reproduction
test("file name preserves through a request", async () => {
    const fileName = "my-doc.pdf"
    const file = new File([new Uint8Array(1_024)], fileName, {
        type: "application/pdf",
    })
    const formData = new FormData()
    formData.append("file", file, fileName)
    const request = new Request("http://example.com", {
        body: formData,
        method: "POST",
    })
    const result = await request.formData()
    expect(result.get("file").name).toEqual(fileName)
})
System Info
System:
    OS: Linux 5.15 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (8) x64 AMD EPYC 7R13 Processor
    Memory: 27.18 GB / 30.67 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 24.12.0 - /home/coder/.nvm/versions/node/v24.12.0/bin/node
    npm: 11.6.2 - /home/coder/.nvm/versions/node/v24.12.0/bin/npm
  npmPackages:
    @vitejs/plugin-react: ^5.1.2 => 5.1.2 
    @vitest/coverage-v8: ^4.0.15 => 4.0.15 
    vite: ^7.2.7 => 7.3.0 
    vitest: ^4.0.15 => 4.0.15
Used Package Manager

npm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.