From ccad35eaf432694e071638233cdbd16e77374a53 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Mon, 21 Jun 2021 15:29:02 +0100 Subject: [PATCH] Add test/unittests/README.md For those new to the repository and unit testing, we add a README that describes the most common tasks for unit testing. R=dsv@chromium.org Fixed: 1221492 Change-Id: Iae43609c7a02b09a8d5056fe280176a74bce904c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2975284 Commit-Queue: Tim van der Lippe Commit-Queue: Danil Somsikov Auto-Submit: Tim van der Lippe Reviewed-by: Danil Somsikov --- test/unittests/README.md | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/unittests/README.md diff --git a/test/unittests/README.md b/test/unittests/README.md new file mode 100644 index 0000000000..00fda3441e --- /dev/null +++ b/test/unittests/README.md @@ -0,0 +1,42 @@ +# Unit tests + +You can run the unit tests with `npm run auto-unittest`. +Unit tests are written using [Mocha](https://mochajs.org/) and [Chai](https://www.chaijs.com/) and run with [Karma](https://karma-runner.github.io/latest/index.html) 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. + +```ts +describe.only('The test suite that you want to run', () => { + it('A test that would run', () => {}); + it('Another test that would run', () => {}); +}); +``` + +```ts +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: + +```bash +COVERAGE_FOLDERS='front_end/ui/components' npm run auto-unittest +COVERAGE_FOLDERS='front_end/{ui/components,core/common}' npm run auto-unittest +``` + +## 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`: + +```bash +npm run auto-unittest -- --expanded-reporting +```