Skip to content

Testing

GitHub Actions

The project uses GitHub Actions to run tests automatically on every push and pull request. The workflow is defined in .github/workflows/test-crdt.yml. It includes steps to:

  • Set up the environment
  • Install dependencies
  • Run tests for the service
  • Generate and upload code coverage reports in artifacts and upload it to Github Pages when the branch is develop

When the deploying GitHub Action is triggered, it will automatically run the tests and deploy only if the tests pass.

The published code coverage report can be accessed at:

CRDT Coverage report

Run tests locally

To run the tests locally, you can use the following commands:

First, start the backend server:

docker compose up --build

Then, run the tests for the service:

CRDT

# Go to the crdt_server directory
cd crdt_server/app

# Install the dependencies
npm install

The test will start the server (for coverage) and run the tests against it. Make sure to manually stop the server from the docker compose command before running the tests, as the tests will start the server again. (Keep the other service running, as the tests depend on postgres and neo4j to run)

# Set the needed environment variables for the tests
export CRDT_PORT=8003
export CRDT_URL="ws://127.0.0.1:8003"
export NEO4J_HOSTNAME="http://localhost:8000"
export POSTGRES_HOSTNAME="http://localhost:8001"
export JWT_SECRET_KEY="secret" # Must be the same as the one used for api-postgres
export CRDT_DEBOUNCE=1000
export CRDT_MAX_DEBOUNCE=10000

# Run the tests
npm run test
# Or if you want to run the tests with coverage
npm run test-coverage