This repository was archived by the owner on Mar 20, 2023. It is now read-only.
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Sorting by coverage % is sorting as a string, not numerically #8
Closed
Description
Describe the bug
Using localeCompare for sorting defaults to sorting each value as a string. You need to sort numerically here. See the MDN docs on how to use localeCompare
.
To Reproduce
Steps to reproduce the behavior:
- Open a coverage report where you have mixed coverage. 0%, 100%, and some in between
- Click on the % coverage header a few times to see how the sort changes
- Note how it will probably read 0%, 100%, then the others in order
Expected behavior
You expect 0%, then increasing coverage percents up to the 100% at the end of the list, or beginning depending on if you're ascending or descending
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: macOS
- Browser: Chrome
- Version: 78.0.3904.97
Gem Version
v0.4.0
Additional context
Simple fix. just change the localeCompare line to …
return reverse * (a.cells[col].textContent.trim().localeCompare(b.cells[col].textContent.trim(), undefined, {numeric: true}));
This is how I got the Numeric Sort screenshot above.