Testing
Unit testing with vitest
We are using vitest for unit testing in votura.
You can run the tests with the following command:
npm run test
Testing votura API
A convenient way to test the votura API during the development is to use Bruno. Bruno is a tool that allows you to create collections of API requests and test them. Bruno supports OpenAPI definitions and allows you to create tests for your API requests.
We are using Bruno only during the development, it is not enforced in the pipeline. To prove your code coverage you need to write vitest testcases (see below).
API tests with Bruno
Install Bruno
We recommend you to use the Bruno UI to edit your collections. You can download it from the Bruno website.
You can also edit the collections in you favorite text editor, but the UI makes it much easier to work with.
Test your API with Bruno
If you want to create a new collection, you can create a new one by generating it from the OpenAPI definition.
You can create simple asserts by using the Assert
function in the Bruno UI.
For example, to check if the response status code is 200.
But you can also create more complex tests by using the Tests
function in the Bruno UI.
For creating new asserts and tests we refer to the Bruno documentation.
You need to ensure that the backend and the database are running before you can test it with Bruno.
Why we are not forcing Bruno in the pipeline?
Bruno is a convenient tool for quick and handy testing of the API, but it has some limitations. Writing complex tests are possible, but not so easy as with vitest. For example, you can not import our zod schemas to validate the response data.
Another limitation that we can not measure the code coverage of the tests, so that is harder to find out if the code is covered by tests or not. So feel free to use Bruno for quick tests, but we recommend writing vitest testcases for more complex tests and to ensure the code coverage.
API tests with vitest
We are using supertest to test the votura API with vitest.
You can find the tests in the apps/backend/test
folder.
This test cases are run automatically in the pipeline and ensure that the API is working as expected.
To run these tests locally, ensure that the Docker daemon is running since the tests dynamically create multiple Docker containers for the database.
If you run npm run test
in the root of backend
workspace, it will run all tests in the apps/backend/test
folder.
Depending on your setup this might take a lot of resources and time, so you can also run a specific test file:
NODE_OPTIONS=--import=tsx npx vitest run --coverage ./path/to/file.test.ts
End-to-end tests with Playwright
We are using Playwright for end-to-end testing in votura.
You can find the tests in the packages/e2e
folder and they are run automatically in the pipeline.
Before you can run the tests locally you need to install the headless browser dependencies:
cd packages/e2e
npm run install-browsers
You also need to set the PEPPER
environment variable in the .env
file in the packages/e2e
, packages/db
, AND apps/backend
folder.
Now you can run the tests with the following command:
cd packages/e2e
npm run test