Skip to content
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

Intercepting a FormData request containing a File causes a timeout for node >20 #2415

Open
4 tasks done
pkawula opened this issue Jan 16, 2025 · 2 comments
Open
4 tasks done
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@pkawula
Copy link

pkawula commented Jan 16, 2025

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

v22.11.0

Reproduction repository

https://github.com/pkawula/msw-node-22-fail

Reproduction steps

Clone the provided repository and use node 20 or 22, then run npm i && npm t.

As an example I'm attaching screenshots from:

  1. Node 18.17.1
Image
  1. Node 20.14.0
Image
  1. Node 22.11.0
Image

Current behavior

Tests are failing with timeout

Expected behavior

Tests should pass.

@pkawula pkawula added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Jan 16, 2025
@kettanaito
Copy link
Member

Hi, @pkawula. Thanks for reporting this.

My hunch tells me this is either a bug in Undici or in JSDOM (we don't officially support JSOM and I highly encourage developers to migrate from it).

For triage, can you please try installing undici explicitly, grabbing their FormData directly, and using it in tests? Does that make any difference? There were some issues around FormData in the past, but I trust they have been resolved and should be available in v22.

As the next step, you can try updating to v23 and see if the issue is still there (perhaps there was a bugfix that wasn't backported, although those are rare).

@thenick775
Copy link

thenick775 commented Feb 2, 2025

+1

I'm seeing this on node 23.7.0 and 22.13.1, where 20.12.1 works just fine.

  http.post(
    `${gbaServerLocationPlaceholder}/api/save/upload`,
    async ({ request }) => {
      console.log('before formdata');
      const formData = await request.formData(); // never makes it past here
      console.log('after formdata');
      const save = formData.get('save') as File;
      const saveName = save.name;

      await delay();

      return new HttpResponse(null, { status: saveName == '400' ? 400 : 200 });
    }
  ),
"jsdom": "^26.0.0",
"msw": "^2.7.0",

Edit: the only thing that made this work on higher node versions was adding this to my setup.ts:

import 'blob-polyfill';

after installing:

npm i -D blob-polyfill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

No branches or pull requests

3 participants