-
Hi there, I have a set of Vitest tests which test API responses from an ExpressJS app that I'm running. My tests run by sending a fetch request to a set of ExpressJS endpoint, eg
If I run the tests everything works as expected for checking the API response. However if I try and run a coverage check against my codebase I'm not able to generate any sensible outputs. So in the case above I'd expect to see some coverage for
I'm suspect that this is because my tests are simply sending fetch requests off to my API, and so the coverage testing doesn't know to look for action within the Has anyone attempted something similar with Vite and have any suggestions? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
How is the API started? Could you set up an example project for this? |
Beta Was this translation helpful? Give feedback.
-
Maybe another option is to look at There is a blog post which outlines this sort of approach but with jest (instead of Vitest) and supertest. |
Beta Was this translation helpful? Give feedback.
globalSetup
runs in a main process whilesetupFiles
runs in a same runtime as your test code, which is where coverage is taken. So you may trysetupFiles
, but its setup/teardown runs for each test file, so you might need to adjust your test structure.Or as you noticed you could use
supertest
, which is a wrapper to launch server (inside test code) and write an request/response assertion in an opinionated manner, but I think what happens at lower level isn't so different from your style of runningapp.listen
manually and writing assertion usingfetch
directly.