Skip to content

Testing

Mark Bestavros edited this page Aug 1, 2018 · 7 revisions

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.

Required Extra Steps: 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 running 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.

  • Getting a node\r: No such file or directory error when running tests on Mac? You may need to change a file in one of the dependencies to Unix line endings. From the top-level flux directory, navigate to node_modules/run-script-os. Open the index.js file in vim using vim index.js. From there, enter the command :set ff=unix. Exit and save your changes (using :wq!). Then, navigate back to the parent directory and run the tests again. It should (hopefully) work.

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

Debugging UI Test While Writing It

To run just a single UI test when you run UI tests, add ".only" after the test keyword to begin the test. For example:

test.only('Clicking event buttons selects corresponding event', async t => {
    const clinicalEventSelector = Selector('.clinical-event-select');

    // Post-encounter is pre-selected
    await t
        .expect(await clinicalEventSelector.textContent)
        .eql('Post-encounter');
    ...

By doing this, when you run the ui tests, just this test will run.

To run just the ui tests you can run “yarn test-ui”.

https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#skipping-tests

Clone this wiki locally