API
Testing
Overview
In Ship testing settled through Jest framework and MongoDB memory server with possibility running them in CI/CD pipeline. MongoDB’s memory server allows connecting to the MongoDB server and running integration tests isolated.
Tests should be placed in the tests
directory specified for each resource from the resources
folder and have next naming format user.service.spec.ts
.
apps/api/src/resources/user/tests/user.service.spec.ts
Run tests and linter.
Run only tests.
Example
GitHub Actions
By default, tests run for each pull request to the main
branch through the run-tests.yml
workflow.
.github/workflows/run-tests.yml
To set up pull request rejection if tests failed visit Settings > Branches
tab in your repository. Then add the branch protection rule “Require status checks to pass before merging”.