vitest icon indicating copy to clipboard operation
vitest copied to clipboard

timeout error when testing fetch with nock

Open rburgst opened this issue 3 years ago • 9 comments

Describe the bug

when mocking network requests with nock then vitest produces a timeout where jest works without problems. Any help would be appreciated

Reproduction

https://replit.com/@rburgst/vitest-nock-problem?v=1 https://stackblitz.com/edit/vitest-dev-vitest-khkmge?file=test%2Fnock.test.ts

  1. on the right hand side choose the "Shell" tab
  2. run npm install
  3. run npm test

expected

the test should succeed and log the fetch result

actual

the test times out after 5s

System Info

System:
    OS: Linux 5.19 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 AMD EPYC 7B12
    Memory: 34.90 GB / 62.79 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.12.1 - /nix/store/dj805sw07vvpbxx39c8g67x8qddg0ikw-nodejs-18.12.1/bin/node
    Yarn: 1.22.19 - /nix/store/zdcnqq55qi214j46zgw2qa1jp4dpdf2m-yarn-1.22.19/bin/yarn
    npm: 8.19.2 - /nix/store/dj805sw07vvpbxx39c8g67x8qddg0ikw-nodejs-18.12.1/bin/npm
  npmPackages:
    vite: ^4.3.9 => 4.3.9 
    vitest: ^0.32.2 => 0.32.2

Used Package Manager

yarn

Validations

rburgst avatar Jun 19 '23 17:06 rburgst

anyone home?

rburgst avatar Jun 27 '23 08:06 rburgst

It would be nice to see some response here

VelizarDemirev avatar Oct 04 '23 13:10 VelizarDemirev

Could you convert the repl.it repro to Github repository or Stackblitz?

AriPerkkio avatar Oct 04 '23 18:10 AriPerkkio

Unfortunately having the same problem. Some details can be found here.

panzerdp avatar Dec 25 '23 12:12 panzerdp

I have the same problem.

PiotrBryla avatar Feb 28 '24 14:02 PiotrBryla

I'm not familiar with nock but it looks like they don't have a stable support with fetch yet:

  • https://github.com/nock/nock/issues/2397

With the latest stable (13.5.4), it doesn't timeout anymore but it looks like an error from nock: (EDIT: actually this times out when running it locally on my PC. error might be only on stackblitz) https://stackblitz.com/edit/vitest-dev-vitest-khkmge?file=test%2Fnock.test.ts

Then, I tested with beta (14.0.0-beta.4) and this one looks working for me: https://stackblitz.com/edit/vitest-dev-vitest-htb8gx?file=test%2Fnock.test.ts

I'm not sure how Jest has made it work, but I don't think there's anything actionable from Vitest for this issue. Please provide a reproduction if anyone on this issue sees something different from the examples I made on stackblitz above.

hi-ogawa avatar Feb 29 '24 06:02 hi-ogawa

Hello @rburgst. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

github-actions avatar Feb 29 '24 06:02 github-actions

@hi-ogawa was kind enough to do that: https://stackblitz.com/edit/vitest-dev-vitest-khkmge?file=test%2Fnock.test.ts

rburgst avatar Feb 29 '24 08:02 rburgst

@rburgst I think this error is simply due to nock's limitation in v13. That's why I wrote that there's nothing actionable from Vitest side. Can you try v14 (beta) to see if it works for you?

hi-ogawa avatar Feb 29 '24 09:02 hi-ogawa