Vitest setup with serverless framework: Node.js Express.js

abdddd

Abdul

Posted on May 16, 2024

Vitest setup with serverless framework: Node.js Express.js

While established testing frameworks like Jest and Mocha have long served the Node.js community, Vitest emerges as a compelling alternative, especially for projects that leverage TypeScript and modern tooling.

Vitest boasts a rich testing ecosystem out of the box, including features like test coverage and optional visual test explorers for enhanced development experience.

In this article i will walk over the setup for vitest with serverless framework for node and express applications.

serverless.yml file configuration for vitest

The serverless.yml file remains almost unchanged, just add an exclude section under package to discard the test files when serverless build is getting created and deployed.

vitest.config.ts file for serverless framework

Vitest.config.json
Since the serverless framework encourages the use of config.stage.json files and environment files, i had slight trouble getting environment files to work with vite, so i came up with the above function that reads the .json as well as .env files and loads the environment variables.

package.json file for vitest and serverless framework

The variable CONFIG_FILE is passed during the run time.

I hope you like this short article, thanks for reading :)

Abd038

Socials:

https://www.linkedin.com/in/abdul-mohammad-a567b2183/
https://twitter.com/iam_abd038
https://github.com/iam-abdul

💖 💪 🙅 🚩
abdddd
Abdul

Posted on May 16, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related