timeout error when testing fetch with nock
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
- on the right hand side choose the "Shell" tab
- run
npm install - 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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
anyone home?
It would be nice to see some response here
Could you convert the repl.it repro to Github repository or Stackblitz?
Unfortunately having the same problem. Some details can be found here.
I have the same problem.
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.
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.
@hi-ogawa was kind enough to do that: https://stackblitz.com/edit/vitest-dev-vitest-khkmge?file=test%2Fnock.test.ts
@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?