Bug: 1299786 Change-Id: Ifddd6b24407ff35c00287e28b971a84962065cf5 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3629864 Commit-Queue: Kateryna Prokopenko <kprokopenko@chromium.org> Reviewed-by: Eric Leese <leese@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org>
Unit tests
You can run the unit tests with npm run auto-unittest.
Unit tests are written using Mocha and Chai and run with Karma in a web browser.
Running a subset of unit tests
If you want to run a specific (set of) unit test, you can use it.only or describe.only for those tests that you want to run.
describe.only('The test suite that you want to run', () => {
it('A test that would run', () => {});
it('Another test that would run', () => {});
});
describe('The test suite that you want to run', () => {
it.only('A test that would run', () => {});
it('A test that would not run', () => {});
});
Obtaining code coverage
We can collect code coverage for the source code that is tested with unit tests.
You can run COVERAGE=1 npm run auto-unittest to obtain code coverage for the whole front_end folder.
However, there is some preprocessing overhead for collecting coverage.
You can use COVERAGE_FOLDERS to only preprocess specific folders for code coverage:
COVERAGE_FOLDERS='front_end/ui/components' npm run auto-unittest
COVERAGE_FOLDERS='front_end/{ui/components,core/common}' npm run auto-unittest
The code coverage output is written to /karma-coverage in the repository root.
You can open /karma-coverage/index.html in a browser to inspect coverage for individual files.
Inspecting detailed errors
By default, the Karma testing output is terse, to avoid console output cluttering.
However, if you want to obtain detailed reporting of a failure you are investigating, you can use --expanded-reporting:
npm run auto-unittest -- --expanded-reporting
Debugging with VSCode
To run tests under the debugger, open the "Run and Debug" sidebar, select "Run unit tests in VS Code debugger" from the dropdown, and click the start button or press F5.