Skip to main content

Testing

Medplum strongly believes in the importance of testing.

We use the following tools for testing:

Every pull request is analyzed by Sonarcloud and Coveralls for code coverage and other static analysis.

Before testing

When you are testing for the first time with a fresh database, you first need to seed and migrate the database. You can accomplish this by running the following command:

npx turbo run test:seed:parallel --filter=@medplum/server

This process can take a minute or two as it migrates the database and then creates many FHIR resources required for Medplum to operate correctly.

After the test passes and the database is migrated and seeded, you won't need to run it again unless the database schema changes or you destroy the volume attached to your postgres Docker container. Now you should be able to run the rest of the tests.

How to test

To run all tests for all packages, use the build script:

npm t

To run all tests for a single package, use npm t inside the package folder:

cd packages/app
npm t

To run tests for a single file, pass in the file name:

npm t -- src/App.test.tsx

To run a single test in a single file, pass the file name and the test name:

npm t -- src/App.test.tsx -t 'Click logo'

Any time you run npm t, you can optionally pass in --coverage to collect code coverage stats. They will be printed in the terminal:

npm t -- --coverage
npm t -- src/App.test.tsx --coverage
npm t -- src/App.test.tsx -t 'Click logo' --coverage