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

feat(jest-diff, pretty-format): Add compareKeys option for sorting object keys #11992

Merged
merged 6 commits into from Oct 28, 2021

Conversation

D-Andreev
Copy link
Contributor

Summary

When comparing objects with jest-diff the keys are printed in alphabetical order by default. If the keys were not sorted alphabetically to begin with the diff is harder to read because the keys are not in their original positions.
This PR adds a compareKeys option to jest-diff and pretty-format which is a function for comparing object keys that's used when sorting.

Closes: 11938

Test plan

There are new unit tests in jest-diff and pretty-format.

@codecov-commenter
Copy link

Codecov Report

Merging #11992 (8cb1824) into main (f41e128) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11992      +/-   ##
==========================================
+ Coverage   68.74%   68.76%   +0.02%     
==========================================
  Files         323      323              
  Lines       16649    16657       +8     
  Branches     4808     4813       +5     
==========================================
+ Hits        11445    11454       +9     
+ Misses       5171     5170       -1     
  Partials       33       33              
Impacted Files Coverage Δ
packages/jest-diff/src/index.ts 88.73% <100.00%> (ø)
packages/jest-diff/src/normalizeDiffOptions.ts 100.00% <100.00%> (ø)
packages/pretty-format/src/collections.ts 100.00% <100.00%> (ø)
packages/pretty-format/src/index.ts 97.46% <100.00%> (+0.03%) ⬆️
packages/expect/src/utils.ts 96.37% <0.00%> (+0.51%) ⬆️

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 f41e128...8cb1824. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

thanks! just some type nits, the code lgtm 👍

packages/pretty-format/src/__tests__/prettyFormat.test.ts Outdated Show resolved Hide resolved
packages/pretty-format/src/collections.ts Outdated Show resolved Hide resolved
packages/pretty-format/src/types.ts Outdated Show resolved Hide resolved
packages/jest-diff/src/index.ts Outdated Show resolved Hide resolved
@D-Andreev
Copy link
Contributor Author

Thanks for the review @SimenB, comments are addressed.
Two of the checks are failing. Looking at the output they don't look like something related to the changes here, maybe they just need to be re-run, I don't have that option in Circle CI.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

looks good!

CHANGELOG.md Outdated Show resolved Hide resolved
packages/pretty-format/src/index.ts Outdated Show resolved Hide resolved
@SimenB SimenB merged commit 27b89ec into jestjs:main Oct 28, 2021
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: jest-diff should allow configuring sorting of object keys
4 participants