Skip to content

HTML report filter not working properly #1725

@RichardsonWTR

Description

@RichardsonWTR

Describe the bug
The filter on the coverage resets its state when I go to the previous page.

To Reproduce
Python 3.8.10
coverage.py v7.0.1 in my code, and the live example as linked below in the v7.4.0

  1. Go to the example page, as indicated here:
  2. See the number of lines, 10 lines (counting the "total").
  3. Type something in the filter on the top right end of the page, e.g., utils. The results will be filtered and there are now only 4 lines (counting the "total").
  4. Click in a file, e.g., cogapp/utils.py
  5. Go back to the previous page (click ALT + left)
  6. See that the text is still on the filter, on the top right of the page, but the results is not filtered.

Expected behavior
When I go back to the previous page, the results must be filtered.

Additional context

When the code below runs, the filter text is still empty.

    // Trigger change event on setup, to force filter on page refresh
    // (filter value may still be present).
    document.getElementById("filter").dispatchEvent(new Event("input"));

Location

Hotfix

Whithout thinking too much, this is a solution that I came up with: appending a new keyboard event after a timeout period. It's not the ideal, but it's working.

This is my script to see the coverage results:

coverage html  && \
    echo 'window.addEventListener("load",(function(){setTimeout((function(){const t=document.getElementById("filter");t&&t.dispatchEvent(new Event("input"))}),5)}));' >> htmlcov/coverage_html.js && \
    xdg-open 'http://localhost:8000' && \
    python -m http.server -d htmlcov

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghtml

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions