Tests
Tests
All services and libraries have tests. There are 2 type of tests implemented:
- Unit tests
- End 2 End (e2e) tests
These tests are written using the jest framework (since this is used by nestjs).
The unit tests are located near the source in a test directory, and all the files have the extension .spec.ts
To run the test run the command yarn test.
The e2e tests are all located in the test directory in the root dir of an app, they have the extension .e2e-spec.ts.
To run the e2e tests run yarn test:e2e
The yarn test:e2e test runs the command jest --config ./test/jest-e2e.json.
This is important when you want to run the tests from your IDE, since the e2e tests require a config file.
When you run the tests from an IDE make sure is also uses this config file otherwise the tests won’t work.
Testcontainers
Most of the e2e tests make use of the testcontainers project. The testcontainers are used to start all dependencies of an application (i.e. postgres or NATS).
This way you can test the actual app without mocking all external dependencies.
Scripts
The package.json files for all apps contain multiple scripts to run tests:
- test: Run the unit tests
- test:watch: Run the unit test and watch for changes for hot reloading
- test:cov: Run the unit tests with code coverage
- test:debug: Run the tests, but wait for a debugger before starting
- test:e2e: Run the e2e tests
- test:e2e-cov: Run the e2e tests with code coverage
- test:full-cov: Run all the test (unit and e2e) and combine the code coverages (this is used by the build pipelines)
- test:cov-silent: Run the units tests with code coverage, but without output (only errors)
- test:e2e-cov-silent: Run the e2e tests with code coverage, but without output (only errors)
- test:full-cov-silent: Run all the test (unit and e2e) and combine the code coverages, but without output (only errors)