coveragepy
coveragepy copied to clipboard
HTML report filter not working properly
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
- Go to the example page, as indicated here:
- See the number of lines, 10 lines (counting the "total").
- 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"). - Click in a file, e.g.,
cogapp/utils.py
- Go back to the previous page (click ALT + left)
- 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"));
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
I so what you mean in Chrome. Firefox works as you expect. I'm sure there's something that can fix it well. Also, returning to the index page by clicking the ^ index
link on the file page brings you to the index page with the filter empty and nothing filtered. It should also keep the filter I think.
Well noted. In Firefox it works as expected. When I go to the previous page the results flash just like my hotfix solution, but it works.
And yes, I detected this bug in Chrome.
Besides, I agree that clicking on ^ index
should keep the filter.