I'm experiencing a problem while running tests on my Express backend using Axios for making requests and Vitest for test execution. Here are the details:
- I have my backend running on localhost, port 3000, using Express.
- I am using Vitest for testing various endpoints that I have implemented.
- The issue arises when I add more test cases in my test files. Initially, when I run the tests for the first time, everything works fine.
- However, after adding more tests and saving them, my vitest tests restart (as expected) but throw the following error:
Serialized Error: Object {
"address": "::1",
"code": "ECONNREFUSED",
"config": Object {
"adapter": [Array],
"baseURL": "http://localhost:3000/api/users"
...
If I restart my Vitest server using my script for Vitest npm run test, the first test case works again, but the problem comes up again when I add more tests.
I have checked the Axios configuration, but everything seems to be in order. Additionally, if I make a fetch request to the endpoints from a file separate from my vitest test file customers.test.js, everything works normally.
Thanks in advance for any help you can offer!