Skip to content
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
@silent-e

Description

@silent-e

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.

String sort
string sort

Numeric sort
numeric sort

To Reproduce
Steps to reproduce the behavior:

  1. Open a coverage report where you have mixed coverage. 0%, 100%, and some in between
  2. Click on the % coverage header a few times to see how the sort changes
  3. 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.

Metadata

Metadata

Labels

bugConfirmed bugs or reports that are very likely to be bugs.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions