Skip to content

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

Merged
SimenB merged 6 commits intojestjs:mainfrom
D-Andreev:d-andreev/11938-compare-keys-option
Oct 28, 2021
Merged

feat(jest-diff, pretty-format): Add compareKeys option for sorting object keys#11992
SimenB merged 6 commits intojestjs:mainfrom
D-Andreev:d-andreev/11938-compare-keys-option

Conversation

@D-Andreev
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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 👍

Comment thread packages/pretty-format/src/__tests__/prettyFormat.test.ts Outdated
Comment thread packages/pretty-format/src/collections.ts Outdated
Comment thread packages/pretty-format/src/types.ts Outdated
Comment thread packages/jest-diff/src/index.ts Outdated
@D-Andreev
Copy link
Copy Markdown
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
Copy Markdown
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!

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

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