Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: account for sorting bug in node 10 #205

Merged
merged 2 commits into from Jan 3, 2020

Conversation

benmonro
Copy link
Member

@benmonro benmonro commented Jan 3, 2020

prior to node 11, Array.sort was unstable for arrays w/ length > 10.
https://twitter.com/mathias/status/1036626116654637057
for this reason, the tab() function needs to account for this in it's sorting.
for example under node 10 in this test:

'abcdefghijklmnopqrstuvwxyz'.split('').sort(() => 0).join('')
will give you 'nacdefghijklmbopqrstuvwxyz'

@codecov
Copy link

codecov bot commented Jan 3, 2020

Codecov Report

Merging #205 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #205      +/-   ##
==========================================
+ Coverage    97.1%   97.14%   +0.04%     
==========================================
  Files           1        1              
  Lines         138      140       +2     
  Branches       35       35              
==========================================
+ Hits          134      136       +2     
  Misses          4        4
Impacted Files Coverage Δ
src/index.js 97.14% <100%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4b5318...7acdf84. Read the comment docs.

@benmonro
Copy link
Member Author

benmonro commented Jan 3, 2020

@kentcdodds @Gpx found a pretty little stank nasty in node 10 and prior.

code cov is off by a branch but it's 100% if you count the fact that it's tested in each env on CI. ;)

update: cool looks like codecov accounts for that, neat.

src/index.js Outdated
@@ -12,6 +12,23 @@ function findTagInParents(element, tagName) {
return findTagInParents(element.parentNode, tagName);
}

let sortListByTabIndex;
let nodeVersion = +process.version.slice(1).split('.')[0];
if (nodeVersion < 11) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we can make this consistent regardless of node version? I'm not super thrilled about the added complexity here 😬

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about that but it would mean an additional map over the entire list. Felt like it would be punishing node 12 for the sins of node 10. Also didn't think it warranted adding a separate sort just because of this. As always open to other options I might be missing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be worried about perf at this stage... We're paying the price of complexity for an unnoticeable perf gain 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alrighty. pushed a version that just has a single sort @kentcdodds

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool 👍

@kentcdodds kentcdodds merged commit df282f9 into testing-library:master Jan 3, 2020
@Gpx
Copy link
Member

Gpx commented Jan 3, 2020

🎉 This PR is included in version 8.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Gpx Gpx added the released label Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants