Skip to content

Commit

Permalink
qunit: add support for precise coverage reporting
Browse files Browse the repository at this point in the history
You can now do something like this:

  $ pytest -k test_browser --js-cov-files='*/fsinfo.ts'

and get results like this:

  pkg/lib/cockpit/fsinfo.ts:33:49-33:63 json_merge
                                                         ▼ from here
      33         const updated = is_json_dict(current) ? { ...current } : { };
                                                                      ▲ to here

  pkg/lib/cockpit/fsinfo.ts:36:33-38:14 json_merge
                                         ▼ from here
      36             if (value === null) {
      37                 delete updated[key];
      38             } else {
                     ▲ to here

Since we also use the same approach for collecting data for integration
tests (Profiler.takePreciseCoverage), we could easily add support there
as well.
  • Loading branch information
allisonkarlitskaya committed Aug 27, 2024
1 parent 63e3dab commit 76e18fc
Show file tree
Hide file tree
Showing 6 changed files with 529 additions and 4 deletions.
16 changes: 16 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ run individual tests via `pytest -k`, like so:

pytest -k test-fsinfo.html

You can see JavaScript code coverage information for QUnit tests. For a
summary table:

pytest -k test_browser --js-cov

And for detailed output on uncovered sections in a specific file, something
like:

pytest -k test-fsinfo.html --js-cov-files='*/fsinfo.ts'

Coverage information is gathered into the pytest tmpdir, regardless of which
coverage-related commandline flags are given, so it's also possible to drill
down after the fact — without re-running tests — using something like:

test/common/js_coverage.py -m '*/fsinfo.ts' /tmp/pytest-of-*/pytest-current/js-coverage/*

There are also static code and syntax checks which you should run often:

test/static-code
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module = [

# test/common
'testlib',
'js_coverage',
'webdriver_bidi',
]

Expand Down Expand Up @@ -155,6 +156,7 @@ paths = [
]
ignore_names = [
"do_*",
"pytest_*",
"test[A-Z0-9]*",
]
ignore_decorators = [
Expand Down
Loading

0 comments on commit 76e18fc

Please sign in to comment.