Skip to content

Testing

EUDIPLO is designed to be robust and easy to test both in development and CI environments. This guide outlines how to run, write, and automate tests for the project.


Running Tests Locally

To run all unit and integration tests locally:

pnpm run test

Or with watch mode:

pnpm run test:watch

This uses Jest under the hood, which is configured for NestJS.


Test Coverage

To check code coverage:

pnpm run test:cov

This generates a report in the /coverage folder. Open coverage/index.html in your browser to view it.


Test Structure

Tests are located next to their implementation files:

src/
  service/
    my.service.ts
    my.service.spec.ts  <-- Test file

Use .spec.ts naming to ensure Jest picks up the test files automatically.


Linting

Before pushing code, check linting rules and fix them:

pnpm run lint

GitHub Actions

Tests run automatically on every push to main or pull request via GitHub Actions.

You can find the workflow config in .github/workflows/ci.yml.


💡 Tips

  • Keep unit tests isolated; mock dependencies using tools like jest.mock() or NestJS's testing module.
  • For HTTP integration tests, use supertest.
  • For mocking external APIs (e.g., Vault or Keycloak), consider nock.

Happy testing! 🚀