whatsapp.hyperjump.tech

Testing

Testing for the project

About

This project uses

Running tests

To run the tests, you need to run the following command first from the root of the monorepo project:

docker-compose up

That will start the local PostgreSQL database that will be used by the tests.

Then run the tests with the following command from the root of the monorepo project:

pnpm run test

Coverage

To run the tests for all apps and packages with coverage, you can run the following command from the root of the monorepo project:

pnpm run coverage:combined

The coverage report location will be displayed in the output of the command.

You can also run the tests inside each app or package. For example, to run the tests inside the web app, you can run the following command from the apps/web directory:

pnpm run test

To run the tests with coverage inside the web app, you can run the following command from the apps/web directory:

pnpm run coverage

React Server Components

Unfortunately, react-testing-library does not support React Server Components (RSC) yet. Fortunately, someone already created a small helper to test RSC. You can find the helper in the @workspace/utils package, in the test-async-rsc.ts file.

Notes

  • In this project, you will see that we write TEST#<number> comments in the code to indicate the test case. This is very useful to keep track of the test cases and to know quickly which part of the code is being tested in the test cases.
  • We do something that is not very common here. We do not mock the prisma client in most of the tests. Instead, we use a test database. Each test will create a new schema in the test database. See packages/database/src/test-utils.ts for more information. Then the function that is being tested will use the test database through the dependency injection mechanism, i.e., async local storage to provide the database context. See the tests for more information.