Trying out Vitest

Trying out Vitest
Photo by Alex / Unsplash

For our Shopify Apps at work, we have a fantastic PHP test suite for each one, using PestPHP to power them and we maintain 90% coverage. One of the gaps though is Javascript testing. We've had a couple of issues come up recently that no Pest test would catch it, but if we had front-end tests, then we would've caught them.

So I started looking around, admittedly, I'd never heard of Vitest before, but given all of our apps use Vite, it seemed like the most natural fit! I integrated it into one of our apps and had Cursor go through the whole code and come up with a set of high level tests, which would catch the couple of Javascript issues we'd previously had.

After a bit of back and forth, I had what I'd consider a decent Javascript testing suite! Writing tests in Vitest isn't too different from Pest, they both use the it() syntax, I did dabble with coverage for Vitest using a tool called V8, but I ended up disabling it for now.

Last thing to do was get Vitest to run as part of our CI/CD pipeline. As it was fairly new to us, I opted to not have it affect our coverage report and left that purely for our Pest test suites. We'll most likely only lean for Vitest when we need to test something that is mission critical and Pest can't test it.