Skip to content

Unit tests

Miguel Silva edited this page Jan 13, 2023 · 9 revisions

Unit tests are located in the src directory side by side with the module that they test (the test for some-module.js should be named some-module.test.js and be located in the same directory as some-module.js).

To run tests, run yarn test from the root directory. This starts a process that watches for changes in files and re-runs tests after a file is changed. To run tests once, use yarn test --watchAll=false.

As part of the IRWG’s (Independent Release Working Group’s) effort to improve testing confidence, Terra UI is also shifting to greatly invest in unit tests, and reduce the reliance on end-to-end UI tests. New or modified code is expected to have 80% code coverage and 80% branch coverage, or better.

See:

Unit tests are expected for new and modified code.

More info in:

Coverage

A coverage report for new code in a PR can be viewed in SonarCloud. Click the "x% Coverage" link in the SonarCloud PR comment or navigate to https://sonarcloud.io/component_measures?metric=new_coverage&selected=DataBiosphere_terra-ui&id=DataBiosphere_terra-ui&pullRequest=PR_NUMBER.

To generate a coverage report locally, run yarn test --coverage --watchAll=false. To view the report in HTML format, open coverage/lcov-report/index.html.

Clone this wiki locally