[go: nahoru, domu]

tree: 65b915c1933aff4393e6d836df1ca449feb9cf83 [path history] [tgz]
  1. fixtures/
  2. front_end/
  3. inspector_overlay/
  4. BUILD.gn
  5. debug-check.js
  6. karma.conf.js
  7. README.md
test/unittests/README.md

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.

Debugging with DevTools

To run tests under the DevTools debugger use DEBUG_TEST environment variable.

DEBUG_TEST=1 npm run auto-unittest

This will bring up Chrome with a Karma launcher page. Wait for “Debug” button to appear and click it. A new page will open, here you can open DevTools, set breakpoints in the tests and reload page to rerun tests.