Skip to content

Testing

Dylan Phelan edited this page Oct 16, 2017 · 7 revisions

Testing:

Running tests

To run tests, go into the central project directory and run:

yarn test

This command will determine your machine's OS and run all possible tests. When in development, individuals can run front end tests with yarn test-ui and backend tests with yarn test-backend.

Extra Steps Required: Due to quirks in the libraries we're using, there are few things to do in order for all tests to pass:

  1. Run yarn start in another terminal before running yarn test. Some ui-tests will fail because it takes longer for the site instance to spin up than it takes for the tests to start.
  2. Ensure that all browsers' testing windows are open while the tests are running. TestCafe has been known to have some issues if those windows are minimized, possibly causing some tests to fail when they shouldn't.
  3. Zoom out ridiculously far out on the ui-test's browser windows once they open. There are currently some issues we have with the our fixed copy-button that cause some tests to fail if the

Other Known Issues:

  • Using Git Bash on Windows? It may look like the test aren't working on your machine. Hit enter a second time after running your yarn test command. The specifics of why this happens are still unknown, but this should help when running your tests.

Writing Tests

For docs on our testing libraries, see the Technologies Used section of our wiki.

Make sure unit testing is done with browser console open and resolve any warnings/errors that appear. In order for your code to be tested properly, and before it can be accepted in a pull request, the following must be done:

  1. Define backend tests for any functions your code defines or relies on. Back-end tests are found in projectDirectory/test/backend, are titled with the pattern <fileToTest>.test.js, and are organized in directories identically to the source files. That is, if you're testing a function found in projectDirectory/src/patient/Patient.jsx, you will define your test in a file found at projectDirectory/test/backend/patient/Patient.test.js. If there is no file or no corresponding folder, you should make one.
  2. Define front-end tests for any new ui-components you define, as well as any components you rely on in your new feature. Front-end tests are found in projectDirectory/test/ui and are titled with the pattern <viewToTest>.js. That is, if you're testing a ui-component displayed when using the view projectDirectory/src/view/SlimApp.jsx, you will define your test in a file found at projectDirectory/test/ui/SlimApp.js. If there is no file, you need to make one.
    • Do not add .test to the filename. This will make the backend test script try to run this file, which will fail and make it look like your tests don't work
Clone this wiki locally